Class: Patron::Session
- Inherits:
-
Object
- Object
- Patron::Session
- Defined in:
- lib/patron/session.rb,
ext/patron/session_ext.c
Overview
This class represents multiple request/response transactions with an HTTP server. This is the primary API for Patron.
Instance Attribute Summary collapse
-
#auth_type ⇒ Symbol
The authentication type for the request (
:basic
,:digest
or:token
). -
#automatic_content_encoding ⇒ Boolean
Support automatic Content-Encoding decompression and set liberal Accept-Encoding headers.
-
#base_url ⇒ String
The URL to prepend to all requests.
-
#buffer_size ⇒ Integer?
Set the buffer size for this request.
-
#cacert ⇒ String
Path to the CA file used for certificate verification, or
nil
if CURL default is used. -
#connect_timeout ⇒ Integer
HTTP connection timeout in seconds.
-
#default_response_charset ⇒ String?
Sets the name of the charset to assume for the response.
-
#download_byte_limit ⇒ Fixnum?
The amount of bytes downloaded.
-
#force_ipv4 ⇒ Boolean
Force curl to use IPv4.
-
#headers ⇒ Hash
Headers used in all requests.
-
#http_version ⇒ String
The supported values are "None", "HTTPv1_0", "HTTPv1_1", "HTTPv2_0", "HTTPv2_TLS", and "HTTPv2_PRIOR".
-
#ignore_content_length ⇒ Boolean
Whether Content-Range and Content-Length headers should be ignored.
-
#insecure ⇒ Boolean
Please consider twice before using this option..
-
#low_speed_limit ⇒ Integer?
The average transfer speed in bytes per second that the transfer should be below during
low_speed_time
seconds for libcurl to consider it to be too slow and abort. -
#low_speed_time ⇒ Integer?
The time in number seconds that the transfer speed should be below the
low_speed_limit
for the library to consider it too slow and abort. -
#max_redirects ⇒ Integer
Maximum number of redirects to follow Set to 0 to disable and -1 to follow all redirects.
-
#password ⇒ String?
Password for http authentication.
-
#proxy ⇒ String
Proxy URL in cURL format ('hostname:8080').
-
#proxy_type ⇒ Integer
Proxy type (default is HTTP).
-
#ssl_version ⇒ String
The supported values are nil, "SSLv2", "SSLv3", and "TLSv1".
-
#timeout ⇒ Integer
HTTP transaction timeout in seconds.
-
#username ⇒ String?
Username for http authentication.
WebDAV methods collapse
-
#copy(url, dest, headers = {}) ⇒ Patron::Response
Sends a WebDAV COPY request to the specified +url+.
Basic API methods collapse
-
#build_request(action, url, headers, options = {}) ⇒ Patron::Request
Builds a request object that can be used by ++handle_request++ Note that internally, ++handle_request++ uses instance variables of the Request object, and not it's public methods.
-
#request(action, url, headers, options = {}) ⇒ Patron::Response
Send an HTTP request to the specified
url
. -
#response_class ⇒ #new
Returns the class that will be used to build a Response from a Curl call.
Class Method Summary collapse
-
.escape(value) ⇒ Object
Escapes the provided string using libCURL URL escaping functions.
-
.unescape(value) ⇒ Object
Unescapes the provided string using libCURL URL escaping functions.
Instance Method Summary collapse
-
#add_cookie_file(file) ⇒ Object
Turn on cookie handling for this session, storing them in memory by default or in +file+ if specified.
-
#delete(url, headers = {}) ⇒ Patron::Response
Same as #get but performs a DELETE request.
-
#enable_debug(file = nil) ⇒ Object
Enable debug output to stderr or to specified
file
. -
#escape(value) ⇒ Object
(also: #urlencode)
Escapes the provided string using libCURL URL escaping functions.
-
#get(url, headers = {}) ⇒ Patron::Response
Retrieve the contents of the specified
url
optionally sending the specified headers. -
#get_file(url, filename, headers = {}) ⇒ Patron::Response
Retrieve the contents of the specified +url+ as with #get, but the content at the URL is downloaded directly into the specified file.
-
#handle_cookies(file_path = nil) ⇒ Object
Turn on cookie handling for this session, storing them in memory by default or in +file+ if specified.
-
#handle_request(request) ⇒ Patron::Response
Peform the actual HTTP request by calling libcurl.
-
#head(url, headers = {}) ⇒ Patron::Response
Same as #get but performs a HEAD request.
-
#initialize(args = {}) { ... } ⇒ Session
constructor
Create a new Session object for performing requests.
-
#interrupt ⇒ void
Interrupt any currently executing request.
-
#patch(url, data, headers = {}) ⇒ Patron::Response
Uploads the passed
data
to the specifiedurl
using an HTTP PATCH. -
#post(url, data, headers = {}) ⇒ Patron::Response
Uploads the passed
data
to the specifiedurl
using an HTTP POST. -
#post_file(url, filename, headers = {}) ⇒ Patron::Response
Uploads the contents of
file
to the specifiedurl
using an HTTP POST. -
#post_multipart(url, data, filename, headers = {}) ⇒ Patron::Response
Uploads the contents of
filename
to the specifiedurl
using an HTTP POST, in combination with given form fields passed indata
. -
#put(url, data, headers = {}) ⇒ Patron::Response
Uploads the passed
data
to the specifiedurl
using an HTTP PUT. -
#put_file(url, filename, headers = {}) ⇒ Patron::Response
Uploads the contents of
file
to the specifiedurl
using an HTTP PUT. -
#reset ⇒ Object
FIXME: figure out how this method should be used at all given Session is not multithreaded.
-
#set_debug_file(file) ⇒ Object
Enable debug output to stderr or to specified +file+.
-
#unescape(value) ⇒ Object
(also: #urldecode)
Unescapes the provided string using libCURL URL escaping functions.
Constructor Details
#initialize(args = {}) { ... } ⇒ Session
Create a new Session object for performing requests.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/patron/session.rb', line 108 def initialize(args = {}, &block) # Allows accessors to be set via constructor hash. Ex: {:base_url => 'www.home.com'} args.each do |attribute, value| send("#{attribute}=", value) end # Allows accessors to be set via block. if block_given? yield self end @headers ||= {} @headers['User-Agent'] ||= Patron.user_agent_string @timeout ||= 5 @connect_timeout ||= 1 @max_redirects ||= 5 @auth_type ||= :basic @force_ipv4 ||= false end |
Instance Attribute Details
#auth_type ⇒ Symbol
Returns the authentication type for the request (:basic
, :digest
or :token
).
49 50 51 |
# File 'lib/patron/session.rb', line 49 def auth_type @auth_type end |
#automatic_content_encoding ⇒ Boolean
Returns Support automatic Content-Encoding decompression and set liberal Accept-Encoding headers.
85 86 87 |
# File 'lib/patron/session.rb', line 85 def automatic_content_encoding @automatic_content_encoding end |
#base_url ⇒ String
Returns The URL to prepend to all requests.
27 28 29 |
# File 'lib/patron/session.rb', line 27 def base_url @base_url end |
#buffer_size ⇒ Integer?
Set the buffer size for this request. This option will only be set if buffer_size is non-nil
72 73 74 |
# File 'lib/patron/session.rb', line 72 def buffer_size @buffer_size end |
#cacert ⇒ String
Returns path to the CA file used for certificate verification, or nil
if CURL default is used.
64 65 66 |
# File 'lib/patron/session.rb', line 64 def cacert @cacert end |
#connect_timeout ⇒ Integer
Returns HTTP connection timeout in seconds. Defaults to 1 second.
16 17 18 |
# File 'lib/patron/session.rb', line 16 def connect_timeout @connect_timeout end |
#default_response_charset ⇒ String?
Sets the name of the charset to assume for the response. The argument should be a String that
is an acceptable argument for Encoding.find()
in Ruby. The variable will only be used if the
response does not specify a charset in it's Content-Type
header already, if it does that charset
will take precedence.
79 80 81 |
# File 'lib/patron/session.rb', line 79 def default_response_charset @default_response_charset end |
#download_byte_limit ⇒ Fixnum?
Returns the amount of bytes downloaded. If it is set to nil (default) no limit will be applied. Note that this only works on libCURL 7.34 and newer.
90 91 92 |
# File 'lib/patron/session.rb', line 90 def download_byte_limit @download_byte_limit end |
#force_ipv4 ⇒ Boolean
Returns Force curl to use IPv4.
82 83 84 |
# File 'lib/patron/session.rb', line 82 def force_ipv4 @force_ipv4 end |
#headers ⇒ Hash
Returns headers used in all requests.
45 46 47 |
# File 'lib/patron/session.rb', line 45 def headers @headers end |
#http_version ⇒ String
The supported values are "None", "HTTPv1_0", "HTTPv1_1", "HTTPv2_0", "HTTPv2_TLS", and "HTTPv2_PRIOR".
61 62 63 |
# File 'lib/patron/session.rb', line 61 def http_version @http_version end |
#ignore_content_length ⇒ Boolean
Returns whether Content-Range and Content-Length headers should be ignored.
67 68 69 |
# File 'lib/patron/session.rb', line 67 def ignore_content_length @ignore_content_length end |
#insecure ⇒ Boolean
Please consider twice before using this option..
53 54 55 |
# File 'lib/patron/session.rb', line 53 def insecure @insecure end |
#low_speed_limit ⇒ Integer?
Returns the average transfer speed in bytes per second that the transfer should be below
during low_speed_time
seconds for libcurl to consider it to be too slow and abort.
100 101 102 |
# File 'lib/patron/session.rb', line 100 def low_speed_limit @low_speed_limit end |
#low_speed_time ⇒ Integer?
Returns the time in number seconds that the transfer speed should be below the
low_speed_limit
for the library to consider it too slow and abort.
95 96 97 |
# File 'lib/patron/session.rb', line 95 def low_speed_time @low_speed_time end |
#max_redirects ⇒ Integer
Maximum number of redirects to follow Set to 0 to disable and -1 to follow all redirects. Defaults to 5.
24 25 26 |
# File 'lib/patron/session.rb', line 24 def max_redirects @max_redirects end |
#password ⇒ String?
Password for http authentication
35 36 37 |
# File 'lib/patron/session.rb', line 35 def password @password end |
#proxy ⇒ String
Returns Proxy URL in cURL format ('hostname:8080').
38 39 40 |
# File 'lib/patron/session.rb', line 38 def proxy @proxy end |
#proxy_type ⇒ Integer
Returns Proxy type (default is HTTP).
42 43 44 |
# File 'lib/patron/session.rb', line 42 def proxy_type @proxy_type end |
#ssl_version ⇒ String
The supported values are nil, "SSLv2", "SSLv3", and "TLSv1".
57 58 59 |
# File 'lib/patron/session.rb', line 57 def ssl_version @ssl_version end |
#timeout ⇒ Integer
Returns HTTP transaction timeout in seconds. Defaults to 5 seconds.
19 20 21 |
# File 'lib/patron/session.rb', line 19 def timeout @timeout end |
#username ⇒ String?
Username for http authentication
31 32 33 |
# File 'lib/patron/session.rb', line 31 def username @username end |
Class Method Details
.escape(value) ⇒ Object
Escapes the provided string using libCURL URL escaping functions.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'ext/patron/session_ext.c', line 237
static VALUE session_escape(VALUE self, VALUE value) {
VALUE string = StringValue(value);
char* escaped = NULL;
VALUE retval = Qnil;
struct patron_curl_state* state = curl_easy_init();
escaped = curl_easy_escape(state->handle,
RSTRING_PTR(string),
(int) RSTRING_LEN(string));
retval = rb_str_new2(escaped);
curl_easy_cleanup(state);
curl_free(escaped);
return retval;
}
|
.unescape(value) ⇒ Object
Unescapes the provided string using libCURL URL escaping functions.
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'ext/patron/session_ext.c', line 261
static VALUE session_unescape(VALUE self, VALUE value) {
VALUE string = StringValue(value);
char* unescaped = NULL;
VALUE retval = Qnil;
struct patron_curl_state* state = curl_easy_init();
unescaped = curl_easy_unescape(state->handle,
RSTRING_PTR(string),
(int) RSTRING_LEN(string),
NULL);
retval = rb_str_new2(unescaped);
curl_free(unescaped);
curl_easy_cleanup(state);
return retval;
}
|
Instance Method Details
#add_cookie_file(file) ⇒ Object
Turn on cookie handling for this session, storing them in memory by
default or in +file+ if specified. The file
must be readable and
writable. Calling multiple times will add more files.
FIXME: what does the empty string actually do here?
872 873 874 875 876 877 878 879 880 881 882 883 884 885 |
# File 'ext/patron/session_ext.c', line 872
static VALUE add_cookie_file(VALUE self, VALUE file) {
struct patron_curl_state *state = get_patron_curl_state(self);
CURL* curl = state->handle;
char* file_path = NULL;
// FIXME: http://websystemsengineering.blogspot.nl/2013/03/curloptcookiefile-vs-curloptcookiejar.html
file_path = RSTRING_PTR(file);
if (file_path != NULL && strlen(file_path) != 0) {
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, file_path);
}
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, file_path);
return self;
}
|
#build_request(action, url, headers, options = {}) ⇒ Patron::Request
Builds a request object that can be used by ++handle_request++ Note that internally, ++handle_request++ uses instance variables of the Request object, and not it's public methods.
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/patron/session.rb', line 348 def build_request(action, url, headers, = {}) # If the Expect header isn't set uploads are really slow headers['Expect'] ||= '' Request.new.tap do |req| req.action = action req.headers = self.headers.merge headers req.automatic_content_encoding = .fetch :automatic_content_encoding, self.automatic_content_encoding req.timeout = .fetch :timeout, self.timeout req.connect_timeout = .fetch :connect_timeout, self.connect_timeout req.low_speed_time = .fetch :low_speed_time, self.low_speed_time req.low_speed_limit = .fetch :low_speed_limit, self.low_speed_limit req.force_ipv4 = .fetch :force_ipv4, self.force_ipv4 req.max_redirects = .fetch :max_redirects, self.max_redirects req.username = .fetch :username, self.username req.password = .fetch :password, self.password req.proxy = .fetch :proxy, self.proxy req.proxy_type = .fetch :proxy_type, self.proxy_type req.auth_type = .fetch :auth_type, self.auth_type req.insecure = .fetch :insecure, self.insecure req.ssl_version = .fetch :ssl_version, self.ssl_version req.http_version = .fetch :http_version, self.http_version req.cacert = .fetch :cacert, self.cacert req.ignore_content_length = .fetch :ignore_content_length, self.ignore_content_length req.buffer_size = .fetch :buffer_size, self.buffer_size req.download_byte_limit = .fetch :download_byte_limit, self.download_byte_limit req.multipart = [:multipart] req.upload_data = [:data] req.file_name = [:file] base_url = self.base_url.to_s url = url.to_s raise ArgumentError, "Empty URL" if base_url.empty? && url.empty? uri = URI.parse(base_url.empty? ? url : File.join(base_url, url)) query = uri.query.to_s.split('&') query += [:query].is_a?(Hash) ? Util.build_query_pairs_from_hash([:query]) : [:query].to_s.split('&') uri.query = query.join('&') uri.query = nil if uri.query.empty? url = uri.to_s req.url = url end end |
#copy(url, dest, headers = {}) ⇒ Patron::Response
Sends a WebDAV COPY request to the specified +url+.
304 305 306 307 |
# File 'lib/patron/session.rb', line 304 def copy(url, dest, headers = {}) headers['Destination'] = dest request(:copy, url, headers) end |
#delete(url, headers = {}) ⇒ Patron::Response
Same as #get but performs a DELETE request.
Notice: this method doesn't accept any data
argument: if you need to send data with
a delete request (as might be needed for ElasticSearch), please, use the #request method.
214 215 216 |
# File 'lib/patron/session.rb', line 214 def delete(url, headers = {}) request(:delete, url, headers) end |
#enable_debug(file = nil) ⇒ Object
Change to an assignment of an IO object
Enable debug output to stderr or to specified file
.
162 163 164 165 |
# File 'lib/patron/session.rb', line 162 def enable_debug(file = nil) set_debug_file(file.to_s) self end |
#escape(value) ⇒ Object Also known as: urlencode
Escapes the provided string using libCURL URL escaping functions.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'ext/patron/session_ext.c', line 237
static VALUE session_escape(VALUE self, VALUE value) {
VALUE string = StringValue(value);
char* escaped = NULL;
VALUE retval = Qnil;
struct patron_curl_state* state = curl_easy_init();
escaped = curl_easy_escape(state->handle,
RSTRING_PTR(string),
(int) RSTRING_LEN(string));
retval = rb_str_new2(escaped);
curl_easy_cleanup(state);
curl_free(escaped);
return retval;
}
|
#get(url, headers = {}) ⇒ Patron::Response
Retrieve the contents of the specified url
optionally sending the
specified headers. If the +base_url+ varaible is set then it is prepended
to the +url+ parameter. Any custom headers are merged with the contents
of the +headers+ instance variable. The results are returned in a
Response object.
Notice: this method doesn't accept any data
argument: if you need to send a request body
with a GET request, when using ElasticSearch for example, please, use the #request method.
178 179 180 |
# File 'lib/patron/session.rb', line 178 def get(url, headers = {}) request(:get, url, headers) end |
#get_file(url, filename, headers = {}) ⇒ Patron::Response
Retrieve the contents of the specified +url+ as with #get, but the content at the URL is downloaded directly into the specified file. The file will be accessed by libCURL bypassing the Ruby runtime entirely.
Note that when using this option, the Response object will have ++nil++ as the body, and you will need to read your target file for access to the body string).
192 193 194 |
# File 'lib/patron/session.rb', line 192 def get_file(url, filename, headers = {}) request(:get, url, headers, :file => filename) end |
#handle_cookies(file_path = nil) ⇒ Object
the cookie jar and cookie file path options should be split
Turn on cookie handling for this session, storing them in memory by
default or in +file+ if specified. The file
must be readable and
writable. Calling multiple times will add more files.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/patron/session.rb', line 136 def (file_path = nil) if file_path path = Pathname(file_path). if !File.exists?(file_path) && !File.writable?(path.dirname) raise ArgumentError, "Can't create file #{path} (permission error)" elsif File.exists?(file_path) && !File.writable?(file_path) raise ArgumentError, "Can't read or write file #{path} (permission error)" end else path = nil end # Apparently calling this with an empty string sets the cookie file, # but calling it with a path to a writable file sets that file to be # the cookie jar (new cookies are written there) (path.to_s) self end |
#handle_request(request) ⇒ Patron::Response
Peform the actual HTTP request by calling libcurl. Each filed in the +request+ object will be used to set the appropriate option on the libcurl library. After the request completes, a Response object will be created and returned.
In the event of an error in the libcurl library, a Ruby exception will be created and raised. The exception will return the libcurl error code and error message.
822 823 824 825 |
# File 'ext/patron/session_ext.c', line 822
static VALUE session_handle_request(VALUE self, VALUE request) {
set_options_from_request(self, request);
return rb_ensure(&perform_request, self, &cleanup, self);
}
|
#head(url, headers = {}) ⇒ Patron::Response
Same as #get but performs a HEAD request.
202 203 204 |
# File 'lib/patron/session.rb', line 202 def head(url, headers = {}) request(:head, url, headers) end |
#interrupt ⇒ void
This method returns an undefined value.
Interrupt any currently executing request. This will cause the current request to error and raise an exception.
857 858 859 860 861 |
# File 'ext/patron/session_ext.c', line 857
static VALUE session_interrupt(VALUE self) {
struct patron_curl_state *state = get_patron_curl_state(self);
state->interrupt = INTERRUPT_ABORT;
return self;
}
|
#patch(url, data, headers = {}) ⇒ Patron::Response
inconsistency with "post" - Hash not accepted
Uploads the passed data
to the specified url
using an HTTP PATCH. Note that
unline ++post++, a Hash is not accepted as the ++data++ argument.
242 243 244 |
# File 'lib/patron/session.rb', line 242 def patch(url, data, headers = {}) request(:patch, url, headers, :data => data) end |
#post(url, data, headers = {}) ⇒ Patron::Response
Uploads the passed data
to the specified url
using an HTTP POST.
266 267 268 269 270 271 272 |
# File 'lib/patron/session.rb', line 266 def post(url, data, headers = {}) if data.is_a?(Hash) data = data.map {|k,v| urlencode(k.to_s) + '=' + urlencode(v.to_s) }.join('&') headers['Content-Type'] = 'application/x-www-form-urlencoded' end request(:post, url, headers, :data => data) end |
#post_file(url, filename, headers = {}) ⇒ Patron::Response
Uploads the contents of file
to the specified url
using an HTTP POST.
The file will be sent "as-is" without any multipart encoding.
281 282 283 |
# File 'lib/patron/session.rb', line 281 def post_file(url, filename, headers = {}) request(:post, url, headers, :file => filename) end |
#post_multipart(url, data, filename, headers = {}) ⇒ Patron::Response
Uploads the contents of filename
to the specified url
using an HTTP POST,
in combination with given form fields passed in data
.
293 294 295 |
# File 'lib/patron/session.rb', line 293 def post_multipart(url, data, filename, headers = {}) request(:post, url, headers, {:data => data, :file => filename, :multipart => true}) end |
#put(url, data, headers = {}) ⇒ Patron::Response
inconsistency with "post" - Hash not accepted
Uploads the passed data
to the specified url
using an HTTP PUT. Note that
unline ++post++, a Hash is not accepted as the ++data++ argument.
228 229 230 |
# File 'lib/patron/session.rb', line 228 def put(url, data, headers = {}) request(:put, url, headers, :data => data) end |
#put_file(url, filename, headers = {}) ⇒ Patron::Response
Uploads the contents of file
to the specified url
using an HTTP PUT. The file will be
sent "as-is" without any multipart encoding.
253 254 255 |
# File 'lib/patron/session.rb', line 253 def put_file(url, filename, headers = {}) request(:put, url, headers, :file => filename) end |
#request(action, url, headers, options = {}) ⇒ Patron::Response
Send an HTTP request to the specified url
.
319 320 321 322 |
# File 'lib/patron/session.rb', line 319 def request(action, url, headers, = {}) req = build_request(action, url, headers, ) handle_request(req) end |
#reset ⇒ Object
FIXME: figure out how this method should be used at all given Session is not multithreaded.
FIXME: also: what is the difference with interrupt()
and also relationship with cleanup()
?
Reset the underlying cURL session. This effectively closes all open
connections and disables debug output. There is no need to call this method
manually after performing a request, since cleanup is performed automatically
but the method can be used from another thread
to abort a request currently in progress.
838 839 840 841 842 843 844 845 846 847 848 849 850 |
# File 'ext/patron/session_ext.c', line 838
static VALUE session_reset(VALUE self) {
struct patron_curl_state *state;
Data_Get_Struct(self, struct patron_curl_state, state);
if (NULL != state->handle) {
cleanup(self);
curl_easy_cleanup(state->handle);
state->handle = NULL;
session_close_debug_file(state);
}
return self;
}
|
#response_class ⇒ #new
Returns the class that will be used to build a Response from a Curl call.
Primarily useful if you need a very lightweight Response object that does not have to perform all the parsing of various headers/status codes. The method must return a module that supports the same interface for +new+ as ++Patron::Response++
335 336 337 |
# File 'lib/patron/session.rb', line 335 def response_class ::Patron::Response end |
#set_debug_file(file) ⇒ Object
Enable debug output to stderr or to specified +file+.
893 894 895 896 897 898 899 900 901 902 903 904 905 906 |
# File 'ext/patron/session_ext.c', line 893
static VALUE set_debug_file(VALUE self, VALUE file) {
struct patron_curl_state *state = get_patron_curl_state(self);
char* file_path = RSTRING_PTR(file);
session_close_debug_file(state);
if(file_path != NULL && strlen(file_path) != 0) {
state->debug_file = open_file(file, "wb");
} else {
state->debug_file = stderr;
}
return self;
}
|
#unescape(value) ⇒ Object Also known as: urldecode
Unescapes the provided string using libCURL URL escaping functions.
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'ext/patron/session_ext.c', line 261
static VALUE session_unescape(VALUE self, VALUE value) {
VALUE string = StringValue(value);
char* unescaped = NULL;
VALUE retval = Qnil;
struct patron_curl_state* state = curl_easy_init();
unescaped = curl_easy_unescape(state->handle,
RSTRING_PTR(string),
(int) RSTRING_LEN(string),
NULL);
retval = rb_str_new2(unescaped);
curl_free(unescaped);
curl_easy_cleanup(state);
return retval;
}
|