Class: Curl::Easy
- Inherits:
-
Object
- Object
- Curl::Easy
- Defined in:
- lib/curl/easy.rb,
ext/curb_easy.c
Defined Under Namespace
Classes: Error
Class Method Summary collapse
-
.download(url, filename = url.split(/\?/).first.split(/\//).last, &blk) ⇒ Object
call-seq: Curl::Easy.download(url, filename = url.split(/?/).first.split(///).last) { |curl| … }.
-
.Curl::Easy.error(code) ⇒ Array, String
translate an internal libcurl error to ruby error class.
-
.http_delete(*args) {|c| ... } ⇒ Object
call-seq: Curl::Easy.http_delete(url) { |easy| … } => #<Curl::Easy…>.
-
.http_get(*args) {|c| ... } ⇒ Object
call-seq: Curl::Easy.http_get(url) { |easy| … } => #<Curl::Easy…>.
-
.http_head(*args) {|c| ... } ⇒ Object
call-seq: Curl::Easy.http_head(url) { |easy| … } => #<Curl::Easy…>.
-
.http_post(*args) {|c| ... } ⇒ Object
call-seq: Curl::Easy.http_post(url, “some=urlencoded%20form%20data&and=so%20on”) => true Curl::Easy.http_post(url, “some=urlencoded%20form%20data”, “and=so%20on”, …) => true Curl::Easy.http_post(url, “some=urlencoded%20form%20data”, Curl::PostField, “and=so%20on”, …) => true Curl::Easy.http_post(url, Curl::PostField, Curl::PostField …, Curl::PostField) => true.
-
.http_put(url, data) {|c| ... } ⇒ Object
call-seq: Curl::Easy.http_put(url, data) {|c| … }.
-
.perform(*args) {|c| ... } ⇒ Object
call-seq: Curl::Easy.perform(url) { |easy| … } => #<Curl::Easy…>.
Instance Method Summary collapse
- #app_connect_time ⇒ Object
-
#autoreferer=(autoreferer) ⇒ Object
easy = Curl::Easy.new easy.autoreferer=true.
-
#body_str ⇒ Object
(also: #body)
Return the response body from the previous call to
perform
. -
#cacert ⇒ String
Obtain the cacert file to use for this Curl::Easy instance.
-
#cacert=(string) ⇒ Object
Set a cacert bundle to use for this Curl::Easy instance.
-
#cert ⇒ String
Obtain the cert file to use for this Curl::Easy instance.
-
#cert=(string) ⇒ Object
Set a cert file to use for this Curl::Easy instance.
-
#cert_key ⇒ Object
Obtain the cert key file to use for this Curl::Easy instance.
-
#cert_key=(cert_key) ⇒ Object
Set a cert key to use for this Curl::Easy instance.
-
#certpassword=(string) ⇒ Object
Set a password used to open the specified cert.
-
#certtype ⇒ String
Obtain the cert type used for this Curl::Easy instance.
-
#certtype=(certtype) ⇒ Object
Set a cert type to use for this Curl::Easy instance.
-
#clone ⇒ Object
(also: #dup)
Clone this Curl::Easy instance, creating a new instance.
-
#close ⇒ nil
Close the Curl::Easy instance.
-
#response_code ⇒ Fixnum
Retrieve the last received HTTP or FTP code.
-
#connect_time ⇒ Float
Retrieve the time, in seconds, it took from the start until the connect to the remote host (or proxy) was completed.
-
#connect_timeout ⇒ Fixnum?
Obtain the maximum time in seconds that you allow the connection to the server to take.
-
#connect_timeout=(fixnum) ⇒ Fixnum?
Set the maximum time in seconds that you allow the connection to the server to take.
-
#connect_timeout_ms ⇒ Fixnum?
Obtain the maximum time in milliseconds that you allow the connection to the server to take.
-
#connect_timeout_ms=(fixnum) ⇒ Fixnum?
Set the maximum time in milliseconds that you allow the connection to the server to take.
-
#content_type ⇒ nil
Retrieve the content-type of the downloaded object.
-
#cookiefile ⇒ String
Obtain the cookiefile file for this Curl::Easy instance.
-
#cookiefile=(value) ⇒ Object
call-seq: easy.cookiefile = string => string.
-
#cookiejar ⇒ String
Obtain the cookiejar file to use for this Curl::Easy instance.
-
#cookiejar=(value) ⇒ Object
call-seq: easy.cookiejar = string => string.
-
#cookielist ⇒ Array
Retrieves the cookies curl knows in an array of strings.
-
#cookies ⇒ Object
Obtain the cookies for this Curl::Easy instance.
-
#cookies=(value) ⇒ Object
call-seq: easy.cookies = “name1=content1; name2=content2;” => string.
-
#delete ⇒ Object
call-seq: easy.http_delete.
-
#delete=(onoff) ⇒ Object
call-seq: easy = Curl::Easy.new(“url”) do|c| c.delete = true end easy.perform.
-
#dns_cache_timeout ⇒ Fixnum?
Obtain the dns cache timeout in seconds.
-
#dns_cache_timeout=(fixnum) ⇒ Fixnum?
Set the dns cache timeout in seconds.
-
#download_speed ⇒ Float
Retrieve the average download speed that curl measured for the preceeding complete download.
-
#downloaded_bytes ⇒ Float
Retrieve the total amount of bytes that were downloaded in the preceeding transfer.
-
#downloaded_content_length ⇒ Float
Retrieve the content-length of the download.
-
#enable_cookies=(boolean) ⇒ Boolean
Configure whether the libcurl cookie engine is enabled for this Curl::Easy instance.
-
#enable_cookies? ⇒ Boolean
Determine whether the libcurl cookie engine is enabled for this Curl::Easy instance.
-
#encoding ⇒ String
Get the set encoding types.
-
#encoding=(string) ⇒ String
Set the accepted encoding types, curl will handle all of the decompression.
-
#escape("some text") ⇒ Object
Convert the given input string to a URL encoded string and return the result.
-
#fetch_file_time=(boolean) ⇒ Boolean
Configure whether this Curl instance will fetch remote file times, if available.
-
#fetch_file_time? ⇒ Boolean
Determine whether this Curl instance will fetch remote file times, if available.
-
#file_time ⇒ Fixnum
Retrieve the remote time of the retrieved document (in number of seconds since 1 jan 1970 in the GMT/UTC time zone).
-
#follow_location=(onoff) ⇒ Object
call-seq: easy.follow_location = boolean => boolean.
-
#follow_location? ⇒ Boolean
Determine whether this Curl instance will follow Location: headers in HTTP responses.
- #ftp_commands ⇒ Array?
-
#ftp_commands=(ftp_commands) ⇒ Object
Explicitly sets the list of commands to execute on the FTP server when calling perform.
-
#ftp_entry_path ⇒ nil
Retrieve the path of the entry path.
-
#ftp_filemethod ⇒ Fixnum
Get the configuration for how libcurl will reach files on the server.
-
#ftp_filemethod=(value) ⇒ Fixnum?
Controls how libcurl reaches files on the server.
-
#ftp_response_timeout ⇒ Fixnum?
Obtain the maximum time that libcurl will wait for FTP command responses.
-
#ftp_response_timeout=(fixnum) ⇒ Fixnum?
Set a timeout period (in seconds) on the amount of time that the server is allowed to take in order to generate a response message for a command before the session is considered hung.
-
#get ⇒ Object
call-seq: easy.http_get => true.
-
#Fixnum ⇒ Object
Iniital access to libcurl curl_easy_getinfo, remember getinfo doesn’t return the same values as setopt.
-
#head=(onoff) ⇒ Object
call-seq: easy = Curl::Easy.new(“url”) do|c| c.head = true end easy.perform.
-
#header_in_body=(boolean) ⇒ Boolean
Configure whether this Curl instance will return HTTP headers combined with body data.
-
#header_in_body? ⇒ Boolean
Determine whether this Curl instance will return HTTP headers combined with body data.
-
#header_size ⇒ Fixnum
Retrieve the total size of all the headers received in the preceeding transfer.
-
#header_str ⇒ Object
(also: #head)
Return the response header from the previous call to
perform
. -
#headers ⇒ Hash, ...
Obtain the custom HTTP headers for following requests.
-
#headers=(headers) ⇒ Object
easy.headers = => “val” …, “Header” => “val” => val”, … easy.headers = [“Header: val” …, “Header: val”] => [“Header: val”, …].
-
#http(verb) ⇒ Object
Send an HTTP request with method set to verb, using the current options set for this Curl::Easy instance.
-
#http_auth_types ⇒ Fixnum?
Obtain the HTTP authentication types that may be used for the following
perform
calls. -
#http_auth_types=(*args) ⇒ Object
VALUE self, VALUE http_auth_types) {.
-
#http_connect_code ⇒ Fixnum
Retrieve the last received proxy response code to a CONNECT request.
-
#http_delete ⇒ Object
call-seq: easy.http_delete.
-
#http_get ⇒ Object
call-seq: easy.http_get => true.
-
#http_head ⇒ Object
call-seq: easy.http_head => true.
-
#http_post(*args) ⇒ Object
POST the specified formdata to the currently configured URL using the current options set for this Curl::Easy instance.
-
#http_put(data) ⇒ true
PUT the supplied data to the currently configured URL using the current options set for this Curl::Easy instance.
-
#ignore_content_length=(boolean) ⇒ Object
Configure whether this Curl::Easy instance should ignore the content length header.
-
#ignore_content_length? ⇒ Boolean
Determine whether this Curl::Easy instance ignores the content length header.
-
#initialize(*args) ⇒ Object
constructor
Initialize a new Curl::Easy instance, optionally supplying the URL.
- #inspect ⇒ "#<Curl::Easy http://google.com/>"
-
#interface ⇒ String
Obtain the interface name that is used as the outgoing network interface.
-
#interface=(value) ⇒ Object
call-seq: easy.interface = string => string.
-
#last_effective_url ⇒ nil
Retrieve the last effective URL used by this instance.
- #last_error ⇒ "Error details"?
- #last_result ⇒ 0
-
#local_port ⇒ Fixnum?
Obtain the local port that will be used for the following
perform
calls. -
#local_port=(fixnum) ⇒ Fixnum?
Set the local port that will be used for the following
perform
calls. -
#local_port_range ⇒ Fixnum?
Obtain the local port range that will be used for the following
perform
calls. -
#local_port_range=(fixnum) ⇒ Fixnum?
Set the local port range that will be used for the following
perform
calls. -
#low_speed_limit ⇒ Fixnum?
Obtain the minimum transfer speed over low_speedtime+ below which the transfer will be aborted.
-
#low_speed_limit=(fixnum) ⇒ Fixnum?
Set the transfer speed (in bytes per second) that the transfer should be below during
low_speed_time
seconds for the library to consider it too slow and abort. -
#low_speed_time ⇒ Fixnum?
Obtain the time that the transfer should be below
low_speed_limit
for the library to abort it. -
#low_speed_time=(fixnum) ⇒ Fixnum?
Set the time (in seconds) that the transfer should be below the
low_speed_limit
for the library to consider it too slow and abort. -
#max_recv_speed_large=(fixnum) ⇒ Fixnum?
Get the maximal receiving transfer speed (in bytes per second).
-
#max_recv_speed_large=(fixnum) ⇒ Fixnum?
Set the maximal receiving transfer speed (in bytes per second).
-
#max_redirects ⇒ Fixnum?
Obtain the maximum number of redirections to follow in the following
perform
calls. -
#max_redirects=(fixnum) ⇒ Fixnum?
Set the maximum number of redirections to follow in the following
perform
calls. -
#max_send_speed_large=(fixnum) ⇒ Fixnum?
Get the maximal sending transfer speed (in bytes per second).
-
#max_send_speed_large=(fixnum) ⇒ Fixnum?
Set the maximal sending transfer speed (in bytes per second).
- #multi ⇒ "#<Curl::Multi>"
- #multi= ⇒ "#<Curl::Multi>"
-
#multipart_form_post=(boolean) ⇒ Boolean
Configure whether this Curl instance uses multipart/formdata content type for HTTP POST requests.
-
#multipart_form_post? ⇒ Boolean
Determine whether this Curl instance uses multipart/formdata content type for HTTP POST requests.
-
#name_lookup_time ⇒ Float
Retrieve the time, in seconds, it took from the start until the name resolving was completed.
- #native_cert= ⇒ Object
-
#nosignal=(onoff) ⇒ Object
call-seq:.
-
#num_connects ⇒ Integer
Retrieve the number of new connections libcurl had to create to achieve the previous transfer (only the successful connects are counted).
-
#on_body {|body_data| ... } ⇒ Object
Assign or remove the
on_body
handler for this Curl::Easy instance. -
#on_complete {|easy| ... } ⇒ Object
Assign or remove the
on_complete
handler for this Curl::Easy instance. -
#on_debug {|type, data| ... } ⇒ Object
Assign or remove the
on_debug
handler for this Curl::Easy instance. -
#on_failure {|easy, code| ... } ⇒ Object
Assign or remove the
on_failure
handler for this Curl::Easy instance. -
#on_header {|header_data| ... } ⇒ Object
Assign or remove the
on_header
handler for this Curl::Easy instance. -
#on_missing {|easy, code| ... } ⇒ Object
Assign or remove the on_missing handler for this Curl::Easy instance.
-
#on_progress {|dl_total, dl_now, ul_total, ul_now| ... } ⇒ Object
Assign or remove the
on_progress
handler for this Curl::Easy instance. -
#on_redirect {|easy, code| ... } ⇒ Object
Assign or remove the on_redirect handler for this Curl::Easy instance.
-
#on_success {|easy| ... } ⇒ Object
Assign or remove the
on_success
handler for this Curl::Easy instance. -
#os_errno ⇒ Integer
Retrieve the errno variable from a connect failure (requires libcurl 7.12.2 or higher, otherwise 0 is always returned).
-
#password ⇒ String
Get the current password.
-
#password=(string) ⇒ String
Set the HTTP Authentication password.
-
#perform ⇒ Object
call-seq: easy.perform => true.
- #post ⇒ Object
-
#post_body ⇒ String?
Obtain the POST body used in this Curl::Easy instance.
-
#post_body=(post_body) ⇒ Object
Sets the POST body of this Curl::Easy instance.
-
#pre_transfer_time ⇒ Float
Retrieve the time, in seconds, it took from the start until the file transfer is just about to begin.
-
#primary_ip ⇒ nil
Retrieve the resolved IP of the most recent connection done with this curl handle.
-
#proxy_auth_types ⇒ Fixnum?
Obtain the proxy authentication types that may be used for the following
perform
calls. -
#proxy_auth_types=(fixnum) ⇒ Fixnum?
Set the proxy authentication types that may be used for the following
perform
calls. -
#proxy_headers ⇒ Hash, ...
Obtain the custom HTTP proxy_headers for following requests.
- #proxy_headers=(proxy_headers) ⇒ Object
-
#proxy_port ⇒ Fixnum?
Obtain the proxy port that will be used for the following
perform
calls. -
#proxy_port=(fixnum) ⇒ Fixnum?
Set the proxy port that will be used for the following
perform
calls. -
#proxy_tunnel=(boolean) ⇒ Boolean
Configure whether this Curl instance will use proxy tunneling.
-
#proxy_tunnel? ⇒ Boolean
Determine whether this Curl instance will use proxy tunneling.
-
#proxy_type ⇒ Fixnum?
Obtain the proxy type that will be used for the following
perform
calls. -
#proxy_type=(fixnum) ⇒ Fixnum?
Set the proxy type that will be used for the following
perform
calls. -
#proxy_url ⇒ String
Obtain the HTTP Proxy URL that will be used by subsequent calls to
perform
. -
#proxy_url=(url) ⇒ Object
call-seq: easy.proxy_url = string => string.
-
#proxypwd ⇒ String
Obtain the username/password string that will be used for proxy connection during subsequent calls to
perform
. -
#proxypwd=(value) ⇒ Object
call-seq: easy.proxypwd = string => string.
- #put ⇒ Object
-
#put_data=(data) ⇒ Object
Points this Curl::Easy instance to data to be uploaded via PUT.
-
#redirect_count ⇒ Integer
Retrieve the total number of redirections that were actually followed.
-
#redirect_time ⇒ Float
Retrieve the total time, in seconds, it took for all redirection steps include name lookup, connect, pretransfer and transfer before final transaction was started.
-
#redirect_url ⇒ nil
Retrieve the URL a redirect would take you to if you would enable CURLOPT_FOLLOWLOCATION.
-
#request_size ⇒ Fixnum
Retrieve the total size of the issued requests.
-
#reset ⇒ Hash
Reset the Curl::Easy instance, clears out all settings.
- #resolve ⇒ Array?
-
#resolve=(resolve) ⇒ Object
Set the resolve list to statically resolve hostnames to IP addresses, bypassing DNS for matching hostname/port combinations.
-
#resolve_mode ⇒ Object
Determines what type of IP address this Curl::Easy instance resolves DNS names to.
-
#resolve_mode=(symbol) ⇒ Object
Configures what type of IP address this Curl::Easy instance resolves DNS names to.
-
#response_code ⇒ Fixnum
Retrieve the last received HTTP or FTP code.
-
#set(opt, val) ⇒ Object
call-seq: easy.set :sym|Fixnum, value.
-
#Fixnum ⇒ Object
Initial access to libcurl curl_easy_setopt.
-
#ssl_verify_host ⇒ Numeric
Determine whether this Curl instance will verify that the server cert is for the server it is known as.
- #ssl_verify_host=(value) ⇒ Object
-
#ssl_verify_host? ⇒ Boolean
call-seq: easy.ssl_verify_host? => boolean.
-
#ssl_verify_host_integer=(ssl_verify_host) ⇒ Object
Configure whether this Curl instance will verify that the server cert is for the server it is known as.
-
#ssl_verify_peer=(boolean) ⇒ Boolean
Configure whether this Curl instance will verify the SSL peer certificate.
-
#ssl_verify_peer? ⇒ Boolean
Determine whether this Curl instance will verify the SSL peer certificate.
-
#ssl_verify_result ⇒ Integer
Retrieve the result of the certification verification that was requested (by setting
ssl_verify_peer?
totrue
). -
#ssl_version ⇒ Fixnum
Get the version of SSL/TLS that libcurl will attempt to use.
-
#ssl_version=(value) ⇒ Fixnum?
Sets the version of SSL/TLS that libcurl will attempt to use.
-
#start_transfer_time ⇒ Float
Retrieve the time, in seconds, it took from the start until the first byte is just about to be transferred.
-
#status ⇒ Object
call-seq: easy.status => String.
-
#sym2curl(opt) ⇒ Object
call-seq: easy.sym2curl :symbol => Fixnum.
-
#timeout ⇒ Numeric
Obtain the maximum time in seconds that you allow the libcurl transfer operation to take.
-
#timeout=(float) ⇒ Numeric
Set the maximum time in seconds that you allow the libcurl transfer operation to take.
-
#timeout_ms ⇒ Fixnum?
Obtain the maximum time in milliseconds that you allow the libcurl transfer operation to take.
-
#timeout_ms=(fixnum) ⇒ Fixnum?
Set the maximum time in milliseconds that you allow the libcurl transfer operation to take.
-
#total_time ⇒ Float
Retrieve the total time in seconds for the previous transfer, including name resolving, TCP connect etc.
-
#unescape("some%20text") ⇒ Object
Convert the given URL encoded input string to a “plain string” and return the result.
-
#unrestricted_auth=(boolean) ⇒ Boolean
Configure whether this Curl instance may use any HTTP authentication method available when necessary.
-
#unrestricted_auth? ⇒ Boolean
Determine whether this Curl instance may use any HTTP authentication method available when necessary.
-
#upload_speed ⇒ Float
Retrieve the average upload speed that curl measured for the preceeding complete upload.
-
#uploaded_bytes ⇒ Float
Retrieve the total amount of bytes that were uploaded in the preceeding transfer.
-
#uploaded_content_length ⇒ Float
Retrieve the content-length of the upload.
-
#url ⇒ String
Obtain the URL that will be used by subsequent calls to
perform
. - #url=(u) ⇒ Object
-
#use_netrc=(boolean) ⇒ Boolean
Configure whether this Curl instance will use data from the user’s .netrc file for FTP connections.
-
#use_netrc? ⇒ Boolean
Determine whether this Curl instance will use data from the user’s .netrc file for FTP connections.
-
#use_ssl ⇒ Fixnum
Get the desired level for using SSL on FTP connections.
-
#use_ssl=(value) ⇒ Fixnum?
Ensure libcurl uses SSL for FTP connections.
-
#useragent ⇒ "Ruby/Curb"
Obtain the user agent string used for this Curl::Easy instance.
-
#useragent=(useragent) ⇒ Object
Set the user agent string for this Curl::Easy instance.
-
#username ⇒ String
Get the current username.
-
#username=(string) ⇒ String
Set the HTTP Authentication username.
-
#userpwd ⇒ String
Obtain the username/password string that will be used for subsequent calls to
perform
. -
#userpwd=(value) ⇒ Object
call-seq: easy.userpwd = string => string.
-
#verbose=(boolean) ⇒ Boolean
Configure whether this Curl instance gives verbose output to STDERR during transfers.
-
#verbose? ⇒ Boolean
Determine whether this Curl instance gives verbose output to STDERR during transfers.
-
#version=(http_version) ⇒ Object
call-seq:.
Constructor Details
#Curl::Easy.new ⇒ #<Curl::Easy... #Curl::Easy.new(url = nil) ⇒ #<Curl::Easy... #Curl::Easy.new(url = nil) {|self| ... } ⇒ #<Curl::Easy...
Initialize a new Curl::Easy instance, optionally supplying the URL. The block form allows further configuration to be supplied before the instance is returned.
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'ext/curb_easy.c', line 336
static VALUE ruby_curl_easy_initialize(int argc, VALUE *argv, VALUE self) {
CURLcode ecode;
VALUE url, blk;
ruby_curl_easy *rbce;
rb_scan_args(argc, argv, "01&", &url, &blk);
Data_Get_Struct(self, ruby_curl_easy, rbce);
/* handler */
rbce->curl = curl_easy_init();
if (!rbce->curl) {
rb_raise(eCurlErrFailedInit, "Failed to initialize easy handle");
}
rbce->multi = Qnil;
rbce->opts = Qnil;
ruby_curl_easy_zero(rbce);
curl_easy_setopt(rbce->curl, CURLOPT_ERRORBUFFER, &rbce->err_buf);
rb_easy_set("url", url);
/* set the pointer to the curl handle */
ecode = curl_easy_setopt(rbce->curl, CURLOPT_PRIVATE, (void*)self);
if (ecode != CURLE_OK) {
raise_curl_easy_error_exception(ecode);
}
if (blk != Qnil) {
rb_funcall(blk, idCall, 1, self);
}
return self;
}
|
Class Method Details
.download(url, filename = url.split(/\?/).first.split(/\//).last, &blk) ⇒ Object
call-seq:
Curl::Easy.download(url, filename = url.split(/\?/).first.split(/\//).last) { |curl| ... }
Stream the specified url (via perform) and save the data directly to the supplied filename (defaults to the last component of the URL path, which will usually be the filename most simple urls).
If a block is supplied, it will be passed the curl instance prior to the perform call.
Note that the semantics of the on_body handler are subtly changed when using download, to account for the automatic routing of data to the specified file: The data string is passed to the handler before it is written to the file, allowing the handler to perform mutative operations where necessary. As usual, the transfer will be aborted if the on_body handler returns a size that differs from the data chunk size - in this case, the offending chunk will not be written to the file, the file will be closed, and a Curl::Err::AbortedByCallbackError will be raised.
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/curl/easy.rb', line 446 def download(url, filename = url.split(/\?/).first.split(/\//).last, &blk) curl = Curl::Easy.new(url, &blk) output = if filename.is_a? IO filename.binmode if filename.respond_to?(:binmode) filename else File.open(filename, 'wb') end begin old_on_body = curl.on_body do |data| result = old_on_body ? old_on_body.call(data) : data.length output << data if result == data.length result end curl.perform ensure output.close rescue IOError end return curl end |
.Curl::Easy.error(code) ⇒ Array, String
translate an internal libcurl error to ruby error class
3769 3770 3771 |
# File 'ext/curb_easy.c', line 3769
static VALUE ruby_curl_easy_error_message(VALUE klass, VALUE code) {
return rb_curl_easy_error(NUM2INT(code));
}
|
.http_delete(*args) {|c| ... } ⇒ Object
call-seq:
Curl::Easy.http_delete(url) { |easy| ... } => #<Curl::Easy...>
Convenience method that creates a new Curl::Easy instance with the specified URL and calls http_delete
, before returning the new instance.
If a block is supplied, the new instance will be yielded just prior to the http_delete
call.
421 422 423 424 425 426 |
# File 'lib/curl/easy.rb', line 421 def http_delete(*args) c = Curl::Easy.new(*args) yield c if block_given? c.http_delete c end |
.http_get(*args) {|c| ... } ⇒ Object
call-seq:
Curl::Easy.http_get(url) { |easy| ... } => #<Curl::Easy...>
Convenience method that creates a new Curl::Easy instance with the specified URL and calls http_get
, before returning the new instance.
If a block is supplied, the new instance will be yielded just prior to the http_get
call.
350 351 352 353 354 355 |
# File 'lib/curl/easy.rb', line 350 def http_get(*args) c = Curl::Easy.new(*args) yield c if block_given? c.http_get c end |
.http_head(*args) {|c| ... } ⇒ Object
call-seq:
Curl::Easy.http_head(url) { |easy| ... } => #<Curl::Easy...>
Convenience method that creates a new Curl::Easy instance with the specified URL and calls http_head
, before returning the new instance.
If a block is supplied, the new instance will be yielded just prior to the http_head
call.
367 368 369 370 371 372 |
# File 'lib/curl/easy.rb', line 367 def http_head(*args) c = Curl::Easy.new(*args) yield c if block_given? c.http_head c end |
.http_post(*args) {|c| ... } ⇒ Object
call-seq:
Curl::Easy.http_post(url, "some=urlencoded%20form%20data&and=so%20on") => true
Curl::Easy.http_post(url, "some=urlencoded%20form%20data", "and=so%20on", ...) => true
Curl::Easy.http_post(url, "some=urlencoded%20form%20data", Curl::PostField, "and=so%20on", ...) => true
Curl::Easy.http_post(url, Curl::PostField, Curl::PostField ..., Curl::PostField) => true
POST the specified formdata to the currently configured URL using the current options set for this Curl::Easy instance. This method always returns true, or raises an exception (defined under Curl::Err) on error.
If you wish to use multipart form encoding, you’ll need to supply a block in order to set multipart_form_post true. See #http_post for more information.
403 404 405 406 407 408 409 |
# File 'lib/curl/easy.rb', line 403 def http_post(*args) url = args.shift c = Curl::Easy.new url yield c if block_given? c.http_post(*args) c end |
.http_put(url, data) {|c| ... } ⇒ Object
call-seq:
Curl::Easy.http_put(url, data) {|c| ... }
see easy.http_put
380 381 382 383 384 385 |
# File 'lib/curl/easy.rb', line 380 def http_put(url, data) c = Curl::Easy.new url yield c if block_given? c.http_put data c end |
.perform(*args) {|c| ... } ⇒ Object
call-seq:
Curl::Easy.perform(url) { |easy| ... } => #<Curl::Easy...>
Convenience method that creates a new Curl::Easy instance with the specified URL and calls the general perform
method, before returning the new instance. For HTTP URLs, this is equivalent to calling http_get
.
If a block is supplied, the new instance will be yielded just prior to the http_get
call.
333 334 335 336 337 338 |
# File 'lib/curl/easy.rb', line 333 def perform(*args) c = Curl::Easy.new(*args) yield c if block_given? c.perform c end |
Instance Method Details
#app_connect_time ⇒ Object
2979 2980 2981 2982 2983 2984 2985 2986 2987 |
# File 'ext/curb_easy.c', line 2979
static VALUE ruby_curl_easy_app_connect_time_get(VALUE self) {
ruby_curl_easy *rbce;
double time;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_APPCONNECT_TIME, &time);
return rb_float_new(time);
}
|
#autoreferer=(autoreferer) ⇒ Object
easy = Curl::Easy.new easy.autoreferer=true
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 |
# File 'ext/curb_easy.c', line 1755
static VALUE ruby_curl_easy_autoreferer_set(VALUE self, VALUE autoreferer) {
ruby_curl_easy *rbce;
Data_Get_Struct(self, ruby_curl_easy, rbce);
if (Qtrue == autoreferer) {
curl_easy_setopt(rbce->curl, CURLOPT_AUTOREFERER, 1);
}
else {
curl_easy_setopt(rbce->curl, CURLOPT_AUTOREFERER, 0);
}
return autoreferer;
}
|
#body_str ⇒ Object Also known as: body
Return the response body from the previous call to perform
. This is populated by the default on_body
handler - if you supply your own body handler, this string will be empty.
2776 2777 2778 2779 2780 2781 2782 |
# File 'ext/curb_easy.c', line 2776
static VALUE ruby_curl_easy_body_str_get(VALUE self) {
/*
TODO: can we force_encoding on the return here if we see charset=utf-8 in the content-type header?
Content-Type: application/json; charset=utf-8
*/
CURB_OBJECT_HGETTER(ruby_curl_easy, body_data);
}
|
#cacert ⇒ String
Obtain the cacert file to use for this Curl::Easy instance.
717 718 719 |
# File 'ext/curb_easy.c', line 717 static VALUE ruby_curl_easy_cacert_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, cacert); } |
#cacert=(string) ⇒ Object
Set a cacert bundle to use for this Curl::Easy instance. This file will be used to validate SSL certificates.
707 708 709 |
# File 'ext/curb_easy.c', line 707
static VALUE ruby_curl_easy_cacert_set(VALUE self, VALUE cacert) {
CURB_OBJECT_HSETTER(ruby_curl_easy, cacert);
}
|
#cert ⇒ String
Obtain the cert file to use for this Curl::Easy instance.
673 674 675 |
# File 'ext/curb_easy.c', line 673 static VALUE ruby_curl_easy_cert_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, cert); } |
#cert=(string) ⇒ Object
Set a cert file to use for this Curl::Easy instance. This file will be used to validate SSL connections.
663 664 665 666 667 668 669 670 671 672 |
# File 'ext/curb_easy.c', line 663 def cert=(cert_file) pos = cert_file.rindex(':') if pos && pos > 1 self.native_cert= cert_file[0..pos-1] self.certpassword= cert_file[pos+1..-1] else self.native_cert= cert_file end self.cert end |
#cert_key ⇒ Object
Obtain the cert key file to use for this Curl::Easy instance.
695 696 697 |
# File 'ext/curb_easy.c', line 695 static VALUE ruby_curl_easy_cert_key_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, cert_key); } |
#cert_key=(cert_key) ⇒ Object
Set a cert key to use for this Curl::Easy instance. This file will be used to validate SSL certificates.
685 686 687 |
# File 'ext/curb_easy.c', line 685
static VALUE ruby_curl_easy_cert_key_set(VALUE self, VALUE cert_key) {
CURB_OBJECT_HSETTER(ruby_curl_easy, cert_key);
}
|
#certpassword=(string) ⇒ Object
Set a password used to open the specified cert
727 728 729 |
# File 'ext/curb_easy.c', line 727
static VALUE ruby_curl_easy_certpassword_set(VALUE self, VALUE certpassword) {
CURB_OBJECT_HSETTER(ruby_curl_easy, certpassword);
}
|
#certtype ⇒ String
Obtain the cert type used for this Curl::Easy instance
749 750 751 |
# File 'ext/curb_easy.c', line 749 static VALUE ruby_curl_easy_certtype_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, certtype); } |
#certtype=(certtype) ⇒ Object
Set a cert type to use for this Curl::Easy instance. Default is PEM
739 740 741 |
# File 'ext/curb_easy.c', line 739
static VALUE ruby_curl_easy_certtype_set(VALUE self, VALUE certtype) {
CURB_OBJECT_HSETTER(ruby_curl_easy, certtype);
}
|
#clone ⇒ Object #dup ⇒ Object Also known as: dup
Clone this Curl::Easy instance, creating a new instance. This method duplicates the underlying CURL* handle.
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'ext/curb_easy.c', line 381
static VALUE ruby_curl_easy_clone(VALUE self) {
ruby_curl_easy *rbce, *newrbce;
Data_Get_Struct(self, ruby_curl_easy, rbce);
newrbce = ALLOC(ruby_curl_easy);
memcpy(newrbce, rbce, sizeof(ruby_curl_easy));
newrbce->curl = curl_easy_duphandle(rbce->curl);
newrbce->curl_headers = NULL;
newrbce->curl_proxy_headers = NULL;
newrbce->curl_ftp_commands = NULL;
newrbce->curl_resolve = NULL;
curl_easy_setopt(rbce->curl, CURLOPT_ERRORBUFFER, &rbce->err_buf);
return Data_Wrap_Struct(cCurlEasy, curl_easy_mark, curl_easy_free, newrbce);
}
|
#close ⇒ nil
Close the Curl::Easy instance. Any open connections are closed The easy handle is reinitialized. If a previous multi handle was open it is set to nil and will be cleared after a GC.
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'ext/curb_easy.c', line 407
static VALUE ruby_curl_easy_close(VALUE self) {
CURLcode ecode;
ruby_curl_easy *rbce;
Data_Get_Struct(self, ruby_curl_easy, rbce);
if (rbce->callback_active) {
rb_raise(rb_eRuntimeError, "Cannot close an active curl handle within a callback");
}
ruby_curl_easy_free(rbce);
/* reinit the handle */
rbce->curl = curl_easy_init();
if (!rbce->curl) {
rb_raise(eCurlErrFailedInit, "Failed to initialize easy handle");
}
rbce->multi = Qnil;
ruby_curl_easy_zero(rbce);
/* give the new curl handle a reference back to the ruby object */
ecode = curl_easy_setopt(rbce->curl, CURLOPT_PRIVATE, (void*)self);
if (ecode != CURLE_OK) {
raise_curl_easy_error_exception(ecode);
}
return Qnil;
}
|
#response_code ⇒ Fixnum
Retrieve the last received HTTP or FTP code. This will be zero if no server response code has been received. Note that a proxy’s CONNECT response should be read with http_connect_code
and not this method.
2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 |
# File 'ext/curb_easy.c', line 2830
static VALUE ruby_curl_easy_response_code_get(VALUE self) {
ruby_curl_easy *rbce;
long code;
Data_Get_Struct(self, ruby_curl_easy, rbce);
#ifdef HAVE_CURLINFO_RESPONSE_CODE
curl_easy_getinfo(rbce->curl, CURLINFO_RESPONSE_CODE, &code);
#else
// old libcurl
curl_easy_getinfo(rbce->curl, CURLINFO_HTTP_CODE, &code);
#endif
return LONG2NUM(code);
}
|
#connect_time ⇒ Float
Retrieve the time, in seconds, it took from the start until the connect to the remote host (or proxy) was completed.
2958 2959 2960 2961 2962 2963 2964 2965 2966 |
# File 'ext/curb_easy.c', line 2958
static VALUE ruby_curl_easy_connect_time_get(VALUE self) {
ruby_curl_easy *rbce;
double time;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_CONNECT_TIME, &time);
return rb_float_new(time);
}
|
#connect_timeout ⇒ Fixnum?
Obtain the maximum time in seconds that you allow the connection to the server to take.
1310 1311 1312 |
# File 'ext/curb_easy.c', line 1310 static VALUE ruby_curl_easy_connect_timeout_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, connect_timeout, 0); } |
#connect_timeout=(fixnum) ⇒ Fixnum?
Set the maximum time in seconds that you allow the connection to the server to take. This only limits the connection phase, once it has connected, this option is of no more use.
Set to nil (or zero) to disable connection timeout (it will then only timeout on the system’s internal timeouts).
1299 1300 1301 |
# File 'ext/curb_easy.c', line 1299
static VALUE ruby_curl_easy_connect_timeout_set(VALUE self, VALUE connect_timeout) {
CURB_IMMED_SETTER(ruby_curl_easy, connect_timeout, 0);
}
|
#connect_timeout_ms ⇒ Fixnum?
Obtain the maximum time in milliseconds that you allow the connection to the server to take.
1336 1337 1338 |
# File 'ext/curb_easy.c', line 1336 static VALUE ruby_curl_easy_connect_timeout_ms_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, connect_timeout_ms, 0); } |
#connect_timeout_ms=(fixnum) ⇒ Fixnum?
Set the maximum time in milliseconds that you allow the connection to the server to take. This only limits the connection phase, once it has connected, this option is of no more use.
Set to nil (or zero) to disable connection timeout (it will then only timeout on the system’s internal timeouts).
1325 1326 1327 |
# File 'ext/curb_easy.c', line 1325
static VALUE ruby_curl_easy_connect_timeout_ms_set(VALUE self, VALUE connect_timeout_ms) {
CURB_IMMED_SETTER(ruby_curl_easy, connect_timeout_ms, 0);
}
|
#content_type ⇒ nil
Retrieve the content-type of the downloaded object. This is the value read from the Content-Type: field. If you get nil
, it means that the server didn’t send a valid Content-Type header or that the protocol used doesn’t support this.
3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 |
# File 'ext/curb_easy.c', line 3278
static VALUE ruby_curl_easy_content_type_get(VALUE self) {
ruby_curl_easy *rbce;
char* type;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_CONTENT_TYPE, &type);
if (type && type[0]) { // curl returns empty string if none
return rb_str_new2(type);
} else {
return Qnil;
}
}
|
#cookiefile ⇒ String
Obtain the cookiefile file for this Curl::Easy instance.
641 642 643 |
# File 'ext/curb_easy.c', line 641 static VALUE (VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, ); } |
#cookiefile=(value) ⇒ Object
call-seq:
easy. = string => string
Set a file that contains cookies to be sent in subsequent requests by this Curl::Easy instance.
Note that you must set enable_cookies true to enable the cookie engine, or this option will be ignored.
236 237 238 |
# File 'lib/curl/easy.rb', line 236 def (value) set :cookiefile, value end |
#cookiejar ⇒ String
Obtain the cookiejar file to use for this Curl::Easy instance.
651 652 653 |
# File 'ext/curb_easy.c', line 651 static VALUE (VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, ); } |
#cookiejar=(value) ⇒ Object
call-seq:
easy. = string => string
Set a cookiejar file to use for this Curl::Easy instance. Cookies from the response will be written into this file.
Note that you must set enable_cookies true to enable the cookie engine, or this option will be ignored.
250 251 252 |
# File 'lib/curl/easy.rb', line 250 def (value) set :cookiejar, value end |
#cookielist ⇒ Array
Retrieves the cookies curl knows in an array of strings. Returned strings are in Netscape cookiejar format or in Set-Cookie format.
See also option CURLINFO_COOKIELIST of curl_easy_getopt(3) to see how libcurl behaves.
(requires libcurl 7.14.1 or higher, otherwise -1 is always returned).
3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 |
# File 'ext/curb_easy.c', line 3376
static VALUE ruby_curl_easy_cookielist_get(VALUE self) {
#ifdef HAVE_CURLINFO_COOKIELIST
ruby_curl_easy *rbce;
struct curl_slist *cookies;
struct curl_slist *cookie;
VALUE rb_cookies;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_COOKIELIST, &cookies);
if (!cookies)
return Qnil;
rb_cookies = rb_ary_new();
for (cookie = cookies; cookie; cookie = cookie->next)
rb_ary_push(rb_cookies, rb_str_new2(cookie->data));
curl_slist_free_all(cookies);
return rb_cookies;
#else
rb_warn("Installed libcurl is too old to support cookielist");
return INT2FIX(-1);
#endif
}
|
#cookies ⇒ Object
Obtain the cookies for this Curl::Easy instance.
631 632 633 |
# File 'ext/curb_easy.c', line 631 static VALUE (VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, ); } |
#cookies=(value) ⇒ Object
call-seq:
easy. = "name1=content1; name2=content2;" => string
Set cookies to be sent by this Curl::Easy instance. The format of the string should be NAME=CONTENTS, where NAME is the cookie name and CONTENTS is what the cookie should contain. Set multiple cookies in one string like this: “name1=content1; name2=content2;” etc.
223 224 225 |
# File 'lib/curl/easy.rb', line 223 def (value) set :cookie, value end |
#delete ⇒ Object
call-seq:
easy.http_delete
DELETE the currently configured URL using the current options set for this Curl::Easy instance. This method always returns true, or raises an exception (defined under Curl::Err) on error.
318 319 320 |
# File 'lib/curl/easy.rb', line 318 def http_delete self.http :DELETE end |
#delete=(onoff) ⇒ Object
103 104 105 106 |
# File 'lib/curl/easy.rb', line 103 def delete=(onoff) set :customrequest, onoff ? 'DELETE' : nil onoff end |
#dns_cache_timeout ⇒ Fixnum?
Obtain the dns cache timeout in seconds.
1359 1360 1361 |
# File 'ext/curb_easy.c', line 1359 static VALUE ruby_curl_easy_dns_cache_timeout_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, dns_cache_timeout, -1); } |
#dns_cache_timeout=(fixnum) ⇒ Fixnum?
Set the dns cache timeout in seconds. Name resolves will be kept in memory for this number of seconds. Set to zero (0) to completely disable caching, or set to nil (or -1) to make the cached entries remain forever. By default, libcurl caches this info for 60 seconds.
1349 1350 1351 |
# File 'ext/curb_easy.c', line 1349
static VALUE ruby_curl_easy_dns_cache_timeout_set(VALUE self, VALUE dns_cache_timeout) {
CURB_IMMED_SETTER(ruby_curl_easy, dns_cache_timeout, -1);
}
|
#download_speed ⇒ Float
Retrieve the average download speed that curl measured for the preceeding complete download.
3166 3167 3168 3169 3170 3171 3172 3173 3174 |
# File 'ext/curb_easy.c', line 3166
static VALUE ruby_curl_easy_download_speed_get(VALUE self) {
ruby_curl_easy *rbce;
double bytes;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_SPEED_DOWNLOAD, &bytes);
return rb_float_new(bytes);
}
|
#downloaded_bytes ⇒ Float
Retrieve the total amount of bytes that were downloaded in the preceeding transfer.
3132 3133 3134 3135 3136 3137 3138 3139 3140 |
# File 'ext/curb_easy.c', line 3132
static VALUE ruby_curl_easy_downloaded_bytes_get(VALUE self) {
ruby_curl_easy *rbce;
double bytes;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_SIZE_DOWNLOAD, &bytes);
return rb_float_new(bytes);
}
|
#downloaded_content_length ⇒ Float
Retrieve the content-length of the download. This is the value read from the Content-Length: field.
3243 3244 3245 3246 3247 3248 3249 3250 3251 |
# File 'ext/curb_easy.c', line 3243
static VALUE ruby_curl_easy_downloaded_content_length_get(VALUE self) {
ruby_curl_easy *rbce;
double bytes;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &bytes);
return rb_float_new(bytes);
}
|
#enable_cookies=(boolean) ⇒ Boolean
Configure whether the libcurl cookie engine is enabled for this Curl::Easy instance.
1860 1861 1862 1863 |
# File 'ext/curb_easy.c', line 1860
static VALUE ruby_curl_easy_enable_cookies_set(VALUE self, VALUE enable_cookies)
{
CURB_BOOLEAN_SETTER(ruby_curl_easy, enable_cookies);
}
|
#enable_cookies? ⇒ Boolean
Determine whether the libcurl cookie engine is enabled for this Curl::Easy instance.
1872 1873 1874 |
# File 'ext/curb_easy.c', line 1872 static VALUE (VALUE self) { CURB_BOOLEAN_GETTER(ruby_curl_easy, ); } |
#encoding ⇒ String
Get the set encoding types
770 771 772 |
# File 'ext/curb_easy.c', line 770 static VALUE ruby_curl_easy_encoding_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, encoding); } |
#encoding=(string) ⇒ String
Set the accepted encoding types, curl will handle all of the decompression
760 761 762 |
# File 'ext/curb_easy.c', line 760
static VALUE ruby_curl_easy_encoding_set(VALUE self, VALUE encoding) {
CURB_OBJECT_HSETTER(ruby_curl_easy, encoding);
}
|
#escape("some text") ⇒ Object
Convert the given input string to a URL encoded string and return the result. All input characters that are not a-z, A-Z or 0-9 are converted to their “URL escaped” version (%NN where NN is a two-digit hexadecimal number).
3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 |
# File 'ext/curb_easy.c', line 3708
static VALUE ruby_curl_easy_escape(VALUE self, VALUE svalue) {
ruby_curl_easy *rbce;
char *result;
VALUE rresult;
VALUE str = svalue;
Data_Get_Struct(self, ruby_curl_easy, rbce);
/* NOTE: make sure the value is a string, if not call to_s */
if( rb_type(str) != T_STRING ) { str = rb_funcall(str,rb_intern("to_s"),0); }
#if (LIBCURL_VERSION_NUM >= 0x070f04)
result = (char*)curl_easy_escape(rbce->curl, StringValuePtr(str), (int)RSTRING_LEN(str));
#else
result = (char*)curl_escape(StringValuePtr(str), (int)RSTRING_LEN(str));
#endif
rresult = rb_str_new2(result);
curl_free(result);
return rresult;
}
|
#fetch_file_time=(boolean) ⇒ Boolean
Configure whether this Curl instance will fetch remote file times, if available.
1632 1633 1634 |
# File 'ext/curb_easy.c', line 1632
static VALUE ruby_curl_easy_fetch_file_time_set(VALUE self, VALUE fetch_file_time) {
CURB_BOOLEAN_SETTER(ruby_curl_easy, fetch_file_time);
}
|
#fetch_file_time? ⇒ Boolean
Determine whether this Curl instance will fetch remote file times, if available.
1643 1644 1645 |
# File 'ext/curb_easy.c', line 1643 static VALUE ruby_curl_easy_fetch_file_time_q(VALUE self) { CURB_BOOLEAN_GETTER(ruby_curl_easy, fetch_file_time); } |
#file_time ⇒ Fixnum
Retrieve the remote time of the retrieved document (in number of seconds since 1 jan 1970 in the GMT/UTC time zone). If you get -1, it can be because of many reasons (unknown, the server hides it or the server doesn’t support the command that tells document time etc) and the time of the document is unknown.
Note that you must tell the server to collect this information before the transfer is made, by setting fetch_file_time?
to true, or you will unconditionally get a -1 back.
This requires libcurl 7.5 or higher - otherwise -1 is unconditionally returned.
2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 |
# File 'ext/curb_easy.c', line 2902
static VALUE ruby_curl_easy_file_time_get(VALUE self) {
#ifdef HAVE_CURLINFO_FILETIME
ruby_curl_easy *rbce;
long time;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_FILETIME, &time);
return LONG2NUM(time);
#else
rb_warn("Installed libcurl is too old to support file_time");
return LONG2NUM(0);
#endif
}
|
#follow_location=(onoff) ⇒ Object
call-seq:
easy.follow_location = boolean => boolean
Configure whether this Curl instance will follow Location: headers in HTTP responses. Redirects will only be followed to the extent specified by max_redirects
.
273 274 275 |
# File 'lib/curl/easy.rb', line 273 def follow_location=(onoff) set :followlocation, onoff end |
#follow_location? ⇒ Boolean
Determine whether this Curl instance will follow Location: headers in HTTP responses.
1776 1777 1778 |
# File 'ext/curb_easy.c', line 1776 static VALUE ruby_curl_easy_follow_location_q(VALUE self) { CURB_BOOLEAN_GETTER(ruby_curl_easy, follow_location); } |
#ftp_commands ⇒ Array?
959 960 961 |
# File 'ext/curb_easy.c', line 959 static VALUE ruby_curl_easy_ftp_commands_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, ftp_commands); } |
#ftp_commands=(ftp_commands) ⇒ Object
Explicitly sets the list of commands to execute on the FTP server when calling perform
951 952 953 |
# File 'ext/curb_easy.c', line 951
static VALUE ruby_curl_easy_ftp_commands_set(VALUE self, VALUE ftp_commands) {
CURB_OBJECT_HSETTER(ruby_curl_easy, ftp_commands);
}
|
#ftp_entry_path ⇒ nil
Retrieve the path of the entry path. That is the initial path libcurl ended up in when logging on to the remote FTP server. This returns nil
if something is wrong.
(requires libcurl 7.15.4 or higher, otherwise nil
is always returned).
3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 |
# File 'ext/curb_easy.c', line 3418
static VALUE ruby_curl_easy_ftp_entry_path_get(VALUE self) {
#ifdef HAVE_CURLINFO_FTP_ENTRY_PATH
ruby_curl_easy *rbce;
char* path = NULL;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_FTP_ENTRY_PATH, &path);
if (path && path[0]) { // curl returns NULL or empty string if none
return rb_str_new2(path);
} else {
return Qnil;
}
#else
rb_warn("Installed libcurl is too old to support num_connects");
return Qnil;
#endif
}
|
#ftp_filemethod ⇒ Fixnum
Get the configuration for how libcurl will reach files on the server.
1599 1600 1601 |
# File 'ext/curb_easy.c', line 1599 static VALUE ruby_curl_easy_ftp_filemethod_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, ftp_filemethod, -1); } |
#ftp_filemethod=(value) ⇒ Fixnum?
Controls how libcurl reaches files on the server. Valid options are Curl::CURL_MULTICWD, Curl::CURL_NOCWD, and Curl::CURL_SINGLECWD (see libcurl docs for CURLOPT_FTP_METHOD).
1589 1590 1591 |
# File 'ext/curb_easy.c', line 1589
static VALUE ruby_curl_easy_ftp_filemethod_set(VALUE self, VALUE ftp_filemethod) {
CURB_IMMED_SETTER(ruby_curl_easy, ftp_filemethod, -1);
}
|
#ftp_response_timeout ⇒ Fixnum?
Obtain the maximum time that libcurl will wait for FTP command responses.
1386 1387 1388 |
# File 'ext/curb_easy.c', line 1386 static VALUE ruby_curl_easy_ftp_response_timeout_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, ftp_response_timeout, 0); } |
#ftp_response_timeout=(fixnum) ⇒ Fixnum?
Set a timeout period (in seconds) on the amount of time that the server is allowed to take in order to generate a response message for a command before the session is considered hung. While curl is waiting for a response, this value overrides timeout
. It is recommended that if used in conjunction with timeout
, you set ftp_response_timeout
to a value smaller than timeout
.
Ignored if libcurl version is < 7.10.8.
1376 1377 1378 |
# File 'ext/curb_easy.c', line 1376
static VALUE ruby_curl_easy_ftp_response_timeout_set(VALUE self, VALUE ftp_response_timeout) {
CURB_IMMED_SETTER(ruby_curl_easy, ftp_response_timeout, 0);
}
|
#get ⇒ Object
call-seq:
easy.http_get => true
GET the currently configured URL using the current options set for this Curl::Easy instance. This method always returns true, or raises an exception (defined under Curl::Err) on error.
305 306 307 308 |
# File 'lib/curl/easy.rb', line 305 def http_get set :httpget, true http :GET end |
#Fixnum ⇒ Object
Iniital access to libcurl curl_easy_getinfo, remember getinfo doesn’t return the same values as setopt
3671 3672 3673 |
# File 'ext/curb_easy.c', line 3671
static VALUE ruby_curl_easy_get_opt(VALUE self, VALUE opt) {
return Qnil;
}
|
#head=(onoff) ⇒ Object
261 262 263 |
# File 'lib/curl/easy.rb', line 261 def head=(onoff) set :nobody, onoff end |
#header_in_body=(boolean) ⇒ Boolean
Configure whether this Curl instance will return HTTP headers combined with body data. If this option is set true, both header and body data will go to body_str
(or the configured on_body
handler).
1712 1713 1714 |
# File 'ext/curb_easy.c', line 1712
static VALUE ruby_curl_easy_header_in_body_set(VALUE self, VALUE header_in_body) {
CURB_BOOLEAN_SETTER(ruby_curl_easy, header_in_body);
}
|
#header_in_body? ⇒ Boolean
Determine whether this Curl instance will return HTTP headers combined with body data.
1723 1724 1725 |
# File 'ext/curb_easy.c', line 1723 static VALUE ruby_curl_easy_header_in_body_q(VALUE self) { CURB_BOOLEAN_GETTER(ruby_curl_easy, header_in_body); } |
#header_size ⇒ Fixnum
Retrieve the total size of all the headers received in the preceeding transfer.
3183 3184 3185 3186 3187 3188 3189 3190 3191 |
# File 'ext/curb_easy.c', line 3183
static VALUE ruby_curl_easy_header_size_get(VALUE self) {
ruby_curl_easy *rbce;
long size;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_HEADER_SIZE, &size);
return LONG2NUM(size);
}
|
#header_str ⇒ Object Also known as: head
Return the response header from the previous call to perform
. This is populated by the default on_header
handler - if you supply your own header handler, this string will be empty.
2792 2793 2794 |
# File 'ext/curb_easy.c', line 2792 static VALUE ruby_curl_easy_header_str_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, header_data); } |
#headers ⇒ Hash, ...
Obtain the custom HTTP headers for following requests.
547 548 549 550 551 552 553 554 |
# File 'ext/curb_easy.c', line 547
static VALUE ruby_curl_easy_headers_get(VALUE self) {
ruby_curl_easy *rbce;
VALUE headers;
Data_Get_Struct(self, ruby_curl_easy, rbce);
headers = rb_easy_get("headers");//rb_hash_aref(rbce->opts, rb_intern("headers"));
if (headers == Qnil) { headers = rb_easy_set("headers", rb_hash_new()); }
return headers;
}
|
#headers=(headers) ⇒ Object
easy.headers = => “val” …, “Header” => “val” => val”, …
easy.headers = ["Header: val" ..., "Header: val"] => ["Header: val", ...]
Set custom HTTP headers for following requests. This can be used to add custom headers, or override standard headers used by libcurl. It defaults to a Hash.
For example to set a standard or custom header:
easy.headers["MyHeader"] = "myval"
To remove a standard header (this is useful when removing libcurls default ‘Expect: 100-Continue’ header when using HTTP form posts):
easy.headers["Expect"] = ''
Anything passed to libcurl as a header will be converted to a string during the perform step.
533 534 535 |
# File 'ext/curb_easy.c', line 533
static VALUE ruby_curl_easy_headers_set(VALUE self, VALUE headers) {
CURB_OBJECT_HSETTER(ruby_curl_easy, headers);
}
|
#http(verb) ⇒ Object
Send an HTTP request with method set to verb, using the current options set for this Curl::Easy instance. This method always returns true or raises an exception (defined under Curl::Err) on error.
2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 |
# File 'ext/curb_easy.c', line 2635
static VALUE ruby_curl_easy_perform_verb(VALUE self, VALUE verb) {
VALUE str_verb;
if (rb_type(verb) == T_STRING) {
return ruby_curl_easy_perform_verb_str(self, StringValueCStr(verb));
}
else if (rb_respond_to(verb,rb_intern("to_s"))) {
str_verb = rb_funcall(verb, rb_intern("to_s"), 0);
return ruby_curl_easy_perform_verb_str(self, StringValueCStr(str_verb));
}
else {
rb_raise(rb_eRuntimeError, "Invalid HTTP VERB, must response to 'to_s'");
}
}
|
#http_auth_types ⇒ Fixnum?
Obtain the HTTP authentication types that may be used for the following perform
calls.
1151 1152 1153 |
# File 'ext/curb_easy.c', line 1151 static VALUE ruby_curl_easy_http_auth_types_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, http_auth_types, 0); } |
#http_auth_types=(*args) ⇒ Object
VALUE self, VALUE http_auth_types) {
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 |
# File 'ext/curb_easy.c', line 1110
static VALUE ruby_curl_easy_http_auth_types_set(int argc, VALUE *argv, VALUE self) {//VALUE self, VALUE http_auth_types) {
ruby_curl_easy *rbce;
VALUE args_ary;
long i, len;
char* node = NULL;
long mask = 0;
rb_scan_args(argc, argv, "*", &args_ary);
Data_Get_Struct(self, ruby_curl_easy, rbce);
len = RARRAY_LEN(args_ary);
if (len == 1 && (rb_ary_entry(args_ary,0) == Qnil || TYPE(rb_ary_entry(args_ary,0)) == T_FIXNUM ||
TYPE(rb_ary_entry(args_ary,0)) == T_BIGNUM)) {
if (rb_ary_entry(args_ary,0) == Qnil) {
rbce->http_auth_types = 0;
}
else {
rbce->http_auth_types = NUM2LONG(rb_ary_entry(args_ary,0));
}
}
else {
// we could have multiple values, but they should be symbols
node = RSTRING_PTR(rb_funcall(rb_ary_entry(args_ary,0),rb_intern("to_s"),0));
mask = CURL_HTTPAUTH_STR_TO_NUM(node);
for( i = 1; i < len; ++i ) {
node = RSTRING_PTR(rb_funcall(rb_ary_entry(args_ary,i),rb_intern("to_s"),0));
mask |= CURL_HTTPAUTH_STR_TO_NUM(node);
}
rbce->http_auth_types = mask;
}
return LONG2NUM(rbce->http_auth_types);
}
|
#http_connect_code ⇒ Fixnum
Retrieve the last received proxy response code to a CONNECT request.
2875 2876 2877 2878 2879 2880 2881 2882 2883 |
# File 'ext/curb_easy.c', line 2875
static VALUE ruby_curl_easy_http_connect_code_get(VALUE self) {
ruby_curl_easy *rbce;
long code;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_HTTP_CONNECTCODE, &code);
return LONG2NUM(code);
}
|
#http_delete ⇒ Object
call-seq:
easy.http_delete
DELETE the currently configured URL using the current options set for this Curl::Easy instance. This method always returns true, or raises an exception (defined under Curl::Err) on error.
315 316 317 |
# File 'lib/curl/easy.rb', line 315 def http_delete self.http :DELETE end |
#http_get ⇒ Object
call-seq:
easy.http_get => true
GET the currently configured URL using the current options set for this Curl::Easy instance. This method always returns true, or raises an exception (defined under Curl::Err) on error.
301 302 303 304 |
# File 'lib/curl/easy.rb', line 301 def http_get set :httpget, true http :GET end |
#http_head ⇒ Object
call-seq:
easy.http_head => true
Request headers from the currently configured URL using the HEAD method and current options set for this Curl::Easy instance. This method always returns true, or raises an exception (defined under Curl::Err) on error.
286 287 288 289 290 291 |
# File 'lib/curl/easy.rb', line 286 def http_head set :nobody, true ret = self.perform set :nobody, false ret end |
#http_post("url = encoded%20form%20data;and=so%20on") ⇒ true #http_post("url = encoded%20form%20data", "and = so%20on", ...) ⇒ true #http_post("url = encoded%20form%20data", Curl: :PostField, "and = so%20on", ...) ⇒ true #http_post(Curl: :PostField, Curl: :PostField..., Curl: :PostField) ⇒ true
POST the specified formdata to the currently configured URL using the current options set for this Curl::Easy instance. This method always returns true, or raises an exception (defined under Curl::Err) on error.
The Content-type of the POST is determined by the current setting of multipart_form_post? , according to the following rules:
-
When false (the default): the form will be POSTed with a content-type of ‘application/x-www-form-urlencoded’, and any of the four calling forms may be used.
-
When true: the form will be POSTed with a content-type of ‘multipart/formdata’. Only the last calling form may be used, i.e. only PostField instances may be POSTed. In this mode, individual fields’ content-types are recognised, and file upload fields are supported.
2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 |
# File 'ext/curb_easy.c', line 2673
static VALUE ruby_curl_easy_perform_post(int argc, VALUE *argv, VALUE self) {
ruby_curl_easy *rbce;
CURL *curl;
int i;
VALUE args_ary;
rb_scan_args(argc, argv, "*", &args_ary);
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl = rbce->curl;
memset(rbce->err_buf, 0, sizeof(rbce->err_buf));
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, NULL);
if (rbce->multipart_form_post) {
VALUE ret;
struct curl_httppost *first = NULL, *last = NULL;
// Make the multipart form
for (i = 0; i < argc; i++) {
if (rb_obj_is_instance_of(argv[i], cCurlPostField)) {
append_to_form(argv[i], &first, &last);
} else if (rb_type(argv[i]) == T_ARRAY) {
// see: https://github.com/rvanlieshout/curb/commit/8bcdefddc0162484681ebd1a92d52a642666a445
long c = 0, argv_len = RARRAY_LEN(argv[i]);
for (; c < argv_len; ++c) {
if (rb_obj_is_instance_of(rb_ary_entry(argv[i],c), cCurlPostField)) {
append_to_form(rb_ary_entry(argv[i],c), &first, &last);
} else {
rb_raise(eCurlErrInvalidPostField, "You must use PostFields only with multipart form posts");
return Qnil;
}
}
} else {
rb_raise(eCurlErrInvalidPostField, "You must use PostFields only with multipart form posts");
return Qnil;
}
}
curl_easy_setopt(curl, CURLOPT_POST, 0);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, first);
ret = rb_funcall(self, rb_intern("perform"), 0);
curl_formfree(first);
return ret;
} else {
VALUE post_body = Qnil;
/* TODO: check for PostField.file and raise error before to_s fails */
if ((post_body = rb_funcall(args_ary, idJoin, 1, rbstrAmp)) == Qnil) {
rb_raise(eCurlErrError, "Failed to join arguments");
return Qnil;
} else {
/* if the function call above returns an empty string because no additional arguments were passed this makes sure
a previously set easy.post_body = "arg=foo&bar=bin" will be honored */
if( post_body != Qnil && rb_type(post_body) == T_STRING && RSTRING_LEN(post_body) > 0 ) {
ruby_curl_easy_post_body_set(self, post_body);
}
/* if post body is not defined, set it so we enable POST header, even though the request body is empty */
if( rb_easy_nil("postdata_buffer") ) {
ruby_curl_easy_post_body_set(self, post_body);
}
return rb_funcall(self, rb_intern("perform"), 0);
}
}
}
|
#http_put(data) ⇒ true
PUT the supplied data to the currently configured URL using the current options set for this Curl::Easy instance. This method always returns true, or raises an exception (defined under Curl::Err) on error.
2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 |
# File 'ext/curb_easy.c', line 2750
static VALUE ruby_curl_easy_perform_put(VALUE self, VALUE data) {
ruby_curl_easy *rbce;
CURL *curl;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl = rbce->curl;
memset(rbce->err_buf, 0, sizeof(rbce->err_buf));
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, NULL);
ruby_curl_easy_put_data_set(self, data);
return rb_funcall(self, rb_intern("perform"), 0);
}
|
#ignore_content_length=(boolean) ⇒ Object
Configure whether this Curl::Easy instance should ignore the content length header.
1883 1884 1885 1886 |
# File 'ext/curb_easy.c', line 1883
static VALUE ruby_curl_easy_ignore_content_length_set(VALUE self, VALUE ignore_content_length)
{
CURB_BOOLEAN_SETTER(ruby_curl_easy, ignore_content_length);
}
|
#ignore_content_length? ⇒ Boolean
Determine whether this Curl::Easy instance ignores the content length header.
1895 1896 1897 |
# File 'ext/curb_easy.c', line 1895 static VALUE ruby_curl_easy_ignore_content_length_q(VALUE self) { CURB_BOOLEAN_GETTER(ruby_curl_easy, ignore_content_length); } |
#inspect ⇒ "#<Curl::Easy http://google.com/>"
3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 |
# File 'ext/curb_easy.c', line 3679
static VALUE ruby_curl_easy_inspect(VALUE self) {
char buf[64];
ruby_curl_easy *rbce;
Data_Get_Struct(self, ruby_curl_easy, rbce);
/* if we don't have a url set... we'll crash... */
if( !rb_easy_nil("url") && rb_easy_type_check("url", T_STRING)) {
VALUE url = rb_easy_get("url");
size_t len = 13+((RSTRING_LEN(url) > 50) ? 50 : RSTRING_LEN(url));
/* "#<Net::HTTP http://www.google.com/:80 open=false>" */
memcpy(buf,"#<Curl::Easy ", 13);
memcpy(buf+13,StringValueCStr(url), (len - 13));
buf[len++] = '>';
return rb_str_new(buf,len);
}
return rb_str_new2("#<Curl::Easy>");
}
|
#interface ⇒ String
Obtain the interface name that is used as the outgoing network interface. The name can be an interface name, an IP address or a host name.
598 599 600 |
# File 'ext/curb_easy.c', line 598 static VALUE ruby_curl_easy_interface_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, interface_hm); } |
#interface=(value) ⇒ Object
call-seq:
easy.interface = string => string
Set the interface name to use as the outgoing network interface. The name can be an interface name, an IP address or a host name.
188 189 190 |
# File 'lib/curl/easy.rb', line 188 def interface=(value) set :interface, value end |
#last_effective_url ⇒ nil
Retrieve the last effective URL used by this instance. This is the URL used in the last perform
call, and may differ from the value of easy.url.
2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 |
# File 'ext/curb_easy.c', line 2807
static VALUE ruby_curl_easy_last_effective_url_get(VALUE self) {
ruby_curl_easy *rbce;
char* url;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_EFFECTIVE_URL, &url);
if (url && url[0]) { // curl returns empty string if none
return rb_str_new2(url);
} else {
return Qnil;
}
}
|
#last_error ⇒ "Error details"?
3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 |
# File 'ext/curb_easy.c', line 3472
static VALUE ruby_curl_easy_last_error(VALUE self) {
ruby_curl_easy *rbce;
Data_Get_Struct(self, ruby_curl_easy, rbce);
if (rbce->err_buf[0]) { // curl returns NULL or empty string if none
return rb_str_new2(rbce->err_buf);
} else {
return Qnil;
}
}
|
#last_result ⇒ 0
3462 3463 3464 3465 3466 |
# File 'ext/curb_easy.c', line 3462
static VALUE ruby_curl_easy_last_result(VALUE self) {
ruby_curl_easy *rbce;
Data_Get_Struct(self, ruby_curl_easy, rbce);
return LONG2NUM(rbce->last_result);
}
|
#local_port ⇒ Fixnum?
Obtain the local port that will be used for the following perform
calls.
This option is ignored if compiled against libcurl < 7.15.2.
1007 1008 1009 |
# File 'ext/curb_easy.c', line 1007 static VALUE ruby_curl_easy_local_port_get(VALUE self) { CURB_IMMED_PORT_GETTER(ruby_curl_easy, local_port); } |
#local_port=(fixnum) ⇒ Fixnum?
Set the local port that will be used for the following perform
calls.
Passing nil
will return to the default behaviour (no local port preference).
This option is ignored if compiled against libcurl < 7.15.2.
995 996 997 |
# File 'ext/curb_easy.c', line 995
static VALUE ruby_curl_easy_local_port_set(VALUE self, VALUE local_port) {
CURB_IMMED_PORT_SETTER(ruby_curl_easy, local_port, "port");
}
|
#local_port_range ⇒ Fixnum?
Obtain the local port range that will be used for the following perform
calls.
This option is ignored if compiled against libcurl < 7.15.2.
1038 1039 1040 |
# File 'ext/curb_easy.c', line 1038 static VALUE ruby_curl_easy_local_port_range_get(VALUE self) { CURB_IMMED_PORT_GETTER(ruby_curl_easy, local_port_range); } |
#local_port_range=(fixnum) ⇒ Fixnum?
Set the local port range that will be used for the following perform
calls. This is a number (between 0 and 65535) that determines how far libcurl may deviate from the supplied local_port
in order to find an available port.
If you set local_port
it’s also recommended that you set this, since it is fairly likely that your specified port will be unavailable.
This option is ignored if compiled against libcurl < 7.15.2.
1025 1026 1027 |
# File 'ext/curb_easy.c', line 1025
static VALUE ruby_curl_easy_local_port_range_set(VALUE self, VALUE local_port_range) {
CURB_IMMED_PORT_SETTER(ruby_curl_easy, local_port_range, "port range");
}
|
#low_speed_limit ⇒ Fixnum?
Obtain the minimum transfer speed over low_speedtime+ below which the transfer will be aborted.
1409 1410 1411 |
# File 'ext/curb_easy.c', line 1409 static VALUE ruby_curl_easy_low_speed_limit_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, low_speed_limit, 0); } |
#low_speed_limit=(fixnum) ⇒ Fixnum?
Set the transfer speed (in bytes per second) that the transfer should be below during low_speed_time
seconds for the library to consider it too slow and abort.
1398 1399 1400 |
# File 'ext/curb_easy.c', line 1398
static VALUE ruby_curl_easy_low_speed_limit_set(VALUE self, VALUE low_speed_limit) {
CURB_IMMED_SETTER(ruby_curl_easy, low_speed_limit, 0);
}
|
#low_speed_time ⇒ Fixnum?
Obtain the time that the transfer should be below low_speed_limit
for the library to abort it.
1431 1432 1433 |
# File 'ext/curb_easy.c', line 1431 static VALUE ruby_curl_easy_low_speed_time_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, low_speed_time, 0); } |
#low_speed_time=(fixnum) ⇒ Fixnum?
Set the time (in seconds) that the transfer should be below the low_speed_limit
for the library to consider it too slow and abort.
1420 1421 1422 |
# File 'ext/curb_easy.c', line 1420
static VALUE ruby_curl_easy_low_speed_time_set(VALUE self, VALUE low_speed_time) {
CURB_IMMED_SETTER(ruby_curl_easy, low_speed_time, 0);
}
|
#max_recv_speed_large=(fixnum) ⇒ Fixnum?
Get the maximal receiving transfer speed (in bytes per second)
1471 1472 1473 |
# File 'ext/curb_easy.c', line 1471 static VALUE ruby_curl_easy_max_recv_speed_large_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, max_recv_speed_large, 0); } |
#max_recv_speed_large=(fixnum) ⇒ Fixnum?
Set the maximal receiving transfer speed (in bytes per second)
1461 1462 1463 |
# File 'ext/curb_easy.c', line 1461
static VALUE ruby_curl_easy_max_recv_speed_large_set(VALUE self, VALUE max_recv_speed_large) {
CURB_IMMED_SETTER(ruby_curl_easy, max_recv_speed_large, 0);
}
|
#max_redirects ⇒ Fixnum?
Obtain the maximum number of redirections to follow in the following perform
calls.
1200 1201 1202 |
# File 'ext/curb_easy.c', line 1200 static VALUE ruby_curl_easy_max_redirects_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, max_redirs, -1); } |
#max_redirects=(fixnum) ⇒ Fixnum?
Set the maximum number of redirections to follow in the following perform
calls. Set to nil or -1 allow an infinite number (the default). Setting this option only makes sense if follow_location
is also set true.
With libcurl >= 7.15.1, setting this to 0 will cause libcurl to refuse any redirect.
1189 1190 1191 |
# File 'ext/curb_easy.c', line 1189
static VALUE ruby_curl_easy_max_redirects_set(VALUE self, VALUE max_redirs) {
CURB_IMMED_SETTER(ruby_curl_easy, max_redirs, -1);
}
|
#max_send_speed_large=(fixnum) ⇒ Fixnum?
Get the maximal sending transfer speed (in bytes per second)
1451 1452 1453 |
# File 'ext/curb_easy.c', line 1451 static VALUE ruby_curl_easy_max_send_speed_large_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, max_send_speed_large, 0); } |
#max_send_speed_large=(fixnum) ⇒ Fixnum?
Set the maximal sending transfer speed (in bytes per second)
1441 1442 1443 |
# File 'ext/curb_easy.c', line 1441
static VALUE ruby_curl_easy_max_send_speed_large_set(VALUE self, VALUE max_send_speed_large) {
CURB_IMMED_SETTER(ruby_curl_easy, max_send_speed_large, 0);
}
|
#multi ⇒ "#<Curl::Multi>"
3441 3442 3443 3444 3445 |
# File 'ext/curb_easy.c', line 3441
static VALUE ruby_curl_easy_multi_get(VALUE self) {
ruby_curl_easy *rbce;
Data_Get_Struct(self, ruby_curl_easy, rbce);
return rbce->multi;
}
|
#multi= ⇒ "#<Curl::Multi>"
3451 3452 3453 3454 3455 3456 |
# File 'ext/curb_easy.c', line 3451
static VALUE ruby_curl_easy_multi_set(VALUE self, VALUE multi) {
ruby_curl_easy *rbce;
Data_Get_Struct(self, ruby_curl_easy, rbce);
rbce->multi = multi;
return rbce->multi;
}
|
#multipart_form_post=(boolean) ⇒ Boolean
Configure whether this Curl instance uses multipart/formdata content type for HTTP POST requests. If this is false (the default), then the application/x-www-form-urlencoded content type is used for the form data.
If this is set true, you must pass one or more PostField instances to the http_post method - no support for posting multipart forms from a string is provided.
1837 1838 1839 1840 |
# File 'ext/curb_easy.c', line 1837
static VALUE ruby_curl_easy_multipart_form_post_set(VALUE self, VALUE multipart_form_post)
{
CURB_BOOLEAN_SETTER(ruby_curl_easy, multipart_form_post);
}
|
#multipart_form_post? ⇒ Boolean
Determine whether this Curl instance uses multipart/formdata content type for HTTP POST requests.
1849 1850 1851 |
# File 'ext/curb_easy.c', line 1849 static VALUE ruby_curl_easy_multipart_form_post_q(VALUE self) { CURB_BOOLEAN_GETTER(ruby_curl_easy, multipart_form_post); } |
#name_lookup_time ⇒ Float
Retrieve the time, in seconds, it took from the start until the name resolving was completed.
2941 2942 2943 2944 2945 2946 2947 2948 2949 |
# File 'ext/curb_easy.c', line 2941
static VALUE ruby_curl_easy_name_lookup_time_get(VALUE self) {
ruby_curl_easy *rbce;
double time;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_NAMELOOKUP_TIME, &time);
return rb_float_new(time);
}
|
#native_cert= ⇒ Object
475 |
# File 'lib/curl/easy.rb', line 475 alias_method :native_cert=, :cert= |
#nosignal=(onoff) ⇒ Object
call-seq:
easy = Curl::Easy.new easy.nosignal = true
92 93 94 |
# File 'lib/curl/easy.rb', line 92 def nosignal=(onoff) set :nosignal, !!onoff end |
#num_connects ⇒ Integer
Retrieve the number of new connections libcurl had to create to achieve the previous transfer (only the successful connects are counted). Combined with redirect_count
you are able to know how many times libcurl successfully reused existing connection(s) or not.
See the Connection Options of curl_easy_setopt(3) to see how libcurl tries to make persistent connections to save time.
(requires libcurl 7.12.3 or higher, otherwise -1 is always returned).
3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 |
# File 'ext/curb_easy.c', line 3349
static VALUE ruby_curl_easy_num_connects_get(VALUE self) {
#ifdef HAVE_CURLINFO_NUM_CONNECTS
ruby_curl_easy *rbce;
long result;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_NUM_CONNECTS, &result);
return LONG2NUM(result);
#else
rb_warn("Installed libcurl is too old to support num_connects");
return LONG2NUM(-1);
#endif
}
|
#on_body {|body_data| ... } ⇒ Object
Assign or remove the on_body
handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.
The on_body
handler is called for each chunk of response body passed back by libcurl during perform
. It should perform any processing necessary, and return the actual number of bytes handled. Normally, this will equal the length of the data string, and CURL will continue processing. If the returned length does not equal the input length, CURL will abort the processing with a Curl::Err::AbortedByCallbackError.
1979 1980 1981 |
# File 'ext/curb_easy.c', line 1979
static VALUE ruby_curl_easy_on_body_set(int argc, VALUE *argv, VALUE self) {
CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, body_proc);
}
|
#on_complete {|easy| ... } ⇒ Object
Assign or remove the on_complete
handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.
The on_complete
handler is called when the request is finished.
2053 2054 2055 |
# File 'ext/curb_easy.c', line 2053
static VALUE ruby_curl_easy_on_complete_set(int argc, VALUE *argv, VALUE self) {
CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, complete_proc);
}
|
#on_debug {|type, data| ... } ⇒ Object
Assign or remove the on_debug
handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.
The on_debug
handler, if configured, will receive detailed information from libcurl during the perform call. This can be useful for debugging. Setting a debug handler overrides libcurl’s internal handler, disabling any output from verbose
, if set.
The type argument will match one of the Curl::Easy::CURLINFO_XXXX constants, and specifies the kind of information contained in the data. The data is passed as a String.
2111 2112 2113 |
# File 'ext/curb_easy.c', line 2111
static VALUE ruby_curl_easy_on_debug_set(int argc, VALUE *argv, VALUE self) {
CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, debug_proc);
}
|
#on_failure {|easy, code| ... } ⇒ Object
Assign or remove the on_failure
handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.
The on_failure
handler is called when the request is finished with a status of 50x
2009 2010 2011 |
# File 'ext/curb_easy.c', line 2009
static VALUE ruby_curl_easy_on_failure_set(int argc, VALUE *argv, VALUE self) {
CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, failure_proc);
}
|
#on_header {|header_data| ... } ⇒ Object
Assign or remove the on_header
handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.
The on_header
handler is called for each chunk of response header passed back by libcurl during perform
. The semantics are the same as for the block supplied to on_body
.
2069 2070 2071 |
# File 'ext/curb_easy.c', line 2069
static VALUE ruby_curl_easy_on_header_set(int argc, VALUE *argv, VALUE self) {
CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, header_proc);
}
|
#on_missing {|easy, code| ... } ⇒ Object
Assign or remove the on_missing handler for this Curl::Easy instance.
To remove a previously-supplied handler, call this method with no attached
block.
The +on_missing+ handler is called when request is finished with a
status of 40x
2024 2025 2026 |
# File 'ext/curb_easy.c', line 2024
static VALUE ruby_curl_easy_on_missing_set(int argc, VALUE *argv, VALUE self) {
CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, missing_proc);
}
|
#on_progress {|dl_total, dl_now, ul_total, ul_now| ... } ⇒ Object
Assign or remove the on_progress
handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.
The on_progress
handler is called regularly by libcurl (approximately once per second) during transfers to allow the application to receive progress information. There is no guarantee that the reported progress will change between calls.
The result of the block call determines whether libcurl continues the transfer. Returning a non-true value (i.e. nil or false) will cause the transfer to abort, throwing a Curl::Err::AbortedByCallbackError.
2090 2091 2092 |
# File 'ext/curb_easy.c', line 2090
static VALUE ruby_curl_easy_on_progress_set(int argc, VALUE *argv, VALUE self) {
CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, progress_proc);
}
|
#on_redirect {|easy, code| ... } ⇒ Object
Assign or remove the on_redirect handler for this Curl::Easy instance.
To remove a previously-supplied handler, call this method with no attached
block.
The +on_redirect+ handler is called when request is finished with a
status of 30x
2039 2040 2041 |
# File 'ext/curb_easy.c', line 2039
static VALUE ruby_curl_easy_on_redirect_set(int argc, VALUE *argv, VALUE self) {
CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, redirect_proc);
}
|
#on_success {|easy| ... } ⇒ Object
Assign or remove the on_success
handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.
The on_success
handler is called when the request is finished with a status of 20x
1994 1995 1996 |
# File 'ext/curb_easy.c', line 1994
static VALUE ruby_curl_easy_on_success_set(int argc, VALUE *argv, VALUE self) {
CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, success_proc);
}
|
#os_errno ⇒ Integer
Retrieve the errno variable from a connect failure (requires libcurl 7.12.2 or higher, otherwise 0 is always returned).
3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 |
# File 'ext/curb_easy.c', line 3320
static VALUE ruby_curl_easy_os_errno_get(VALUE self) {
#ifdef HAVE_CURLINFO_OS_ERRNO
ruby_curl_easy *rbce;
long result;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_OS_ERRNO, &result);
return LONG2NUM(result);
#else
rb_warn("Installed libcurl is too old to support os_errno");
return LONG2NUM(0);
#endif
}
|
#password ⇒ String
Get the current password
1523 1524 1525 1526 1527 1528 1529 |
# File 'ext/curb_easy.c', line 1523 static VALUE ruby_curl_easy_password_get(VALUE self) { #if HAVE_CURLOPT_PASSWORD CURB_OBJECT_HGETTER(ruby_curl_easy, password); #else return Qnil; #endif } |
#password=(string) ⇒ String
Set the HTTP Authentication password.
1509 1510 1511 1512 1513 1514 1515 |
# File 'ext/curb_easy.c', line 1509
static VALUE ruby_curl_easy_password_set(VALUE self, VALUE password) {
#if HAVE_CURLOPT_PASSWORD
CURB_OBJECT_HSETTER(ruby_curl_easy, password);
#else
return Qnil;
#endif
}
|
#perform ⇒ Object
call-seq:
easy.perform => true
Transfer the currently configured URL using the options set for this Curl::Easy instance. If this is an HTTP URL, it will be transferred via the configured HTTP Verb.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/curl/easy.rb', line 66 def perform self.multi = Curl::Multi.new if self.multi.nil? self.multi.add self ret = self.multi.perform self.multi.remove self if Curl::Multi.autoclose self.multi.close self.multi = nil end if self.last_result != 0 && self.on_failure.nil? (err_class, err_summary) = Curl::Easy.error(self.last_result) err_detail = self.last_error raise err_class.new([err_summary, err_detail].compact.join(": ")) end ret end |
#post ⇒ Object
5 |
# File 'lib/curl/easy.rb', line 5 alias post http_post |
#post_body ⇒ String?
Obtain the POST body used in this Curl::Easy instance.
855 856 857 |
# File 'ext/curb_easy.c', line 855 static VALUE ruby_curl_easy_post_body_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, postdata_buffer); } |
#post_body=(post_body) ⇒ Object
Sets the POST body of this Curl::Easy instance. This is expected to be URL encoded; no additional processing or encoding is done on the string. The content-type header will be set to application/x-www-form-urlencoded.
This is handy if you want to perform a POST against a Curl::Multi instance.
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 |
# File 'ext/curb_easy.c', line 805
static VALUE ruby_curl_easy_post_body_set(VALUE self, VALUE post_body) {
ruby_curl_easy *rbce;
CURL *curl;
char *data;
long len;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl = rbce->curl;
if ( post_body == Qnil ) {
rb_easy_del("postdata_buffer");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
} else {
if (rb_type(post_body) == T_STRING) {
data = StringValuePtr(post_body);
len = RSTRING_LEN(post_body);
}
else if (rb_respond_to(post_body, rb_intern("to_s"))) {
VALUE str_body = rb_funcall(post_body, rb_intern("to_s"), 0);
data = StringValuePtr(str_body);
len = RSTRING_LEN(post_body);
}
else {
rb_raise(rb_eRuntimeError, "post data must respond_to .to_s");
}
// Store the string, since it has to hang around for the duration of the
// request. See CURLOPT_POSTFIELDS in the libcurl docs.
//rbce->postdata_buffer = post_body;
rb_easy_set("postdata_buffer", post_body);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, len);
return post_body;
}
return Qnil;
}
|
#pre_transfer_time ⇒ Float
Retrieve the time, in seconds, it took from the start until the file transfer is just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.
3000 3001 3002 3003 3004 3005 3006 3007 3008 |
# File 'ext/curb_easy.c', line 3000
static VALUE ruby_curl_easy_pre_transfer_time_get(VALUE self) {
ruby_curl_easy *rbce;
double time;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_PRETRANSFER_TIME, &time);
return rb_float_new(time);
}
|
#primary_ip ⇒ nil
Retrieve the resolved IP of the most recent connection
done with this curl handle. This string may be IPv6 if
that's enabled. This feature requires curl 7.19.x and above
2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 |
# File 'ext/curb_easy.c', line 2854
static VALUE ruby_curl_easy_primary_ip_get(VALUE self) {
ruby_curl_easy *rbce;
char* ip;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_PRIMARY_IP, &ip);
if (ip && ip[0]) { // curl returns empty string if none
return rb_str_new2(ip);
} else {
return Qnil;
}
}
|
#proxy_auth_types ⇒ Fixnum?
Obtain the proxy authentication types that may be used for the following perform
calls.
1174 1175 1176 |
# File 'ext/curb_easy.c', line 1174 static VALUE ruby_curl_easy_proxy_auth_types_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, proxy_auth_types, 0); } |
#proxy_auth_types=(fixnum) ⇒ Fixnum?
Set the proxy authentication types that may be used for the following perform
calls. This is a bitmap made by ORing together the Curl::CURLAUTH constants.
1163 1164 1165 |
# File 'ext/curb_easy.c', line 1163
static VALUE ruby_curl_easy_proxy_auth_types_set(VALUE self, VALUE proxy_auth_types) {
CURB_IMMED_SETTER(ruby_curl_easy, proxy_auth_types, 0);
}
|
#proxy_headers ⇒ Hash, ...
Obtain the custom HTTP proxy_headers for following requests.
582 583 584 585 586 587 588 589 |
# File 'ext/curb_easy.c', line 582
static VALUE ruby_curl_easy_proxy_headers_get(VALUE self) {
ruby_curl_easy *rbce;
VALUE proxy_headers;
Data_Get_Struct(self, ruby_curl_easy, rbce);
proxy_headers = rb_easy_get("proxy_headers");//rb_hash_aref(rbce->opts, rb_intern("proxy_headers"));
if (proxy_headers == Qnil) { proxy_headers = rb_easy_set("proxy_headers", rb_hash_new()); }
return proxy_headers;
}
|
#proxy_headers=(proxy_headers) ⇒ Object
537 538 539 |
# File 'ext/curb_easy.c', line 537
static VALUE ruby_curl_easy_proxy_headers_set(VALUE self, VALUE proxy_headers) {
CURB_OBJECT_HSETTER(ruby_curl_easy, proxy_headers);
}
|
#proxy_port ⇒ Fixnum?
Obtain the proxy port that will be used for the following perform
calls.
1058 1059 1060 |
# File 'ext/curb_easy.c', line 1058 static VALUE ruby_curl_easy_proxy_port_get(VALUE self) { CURB_IMMED_PORT_GETTER(ruby_curl_easy, proxy_port); } |
#proxy_port=(fixnum) ⇒ Fixnum?
Set the proxy port that will be used for the following perform
calls.
1048 1049 1050 |
# File 'ext/curb_easy.c', line 1048
static VALUE ruby_curl_easy_proxy_port_set(VALUE self, VALUE proxy_port) {
CURB_IMMED_PORT_SETTER(ruby_curl_easy, proxy_port, "port");
}
|
#proxy_tunnel=(boolean) ⇒ Boolean
Configure whether this Curl instance will use proxy tunneling.
1611 1612 1613 |
# File 'ext/curb_easy.c', line 1611
static VALUE ruby_curl_easy_proxy_tunnel_set(VALUE self, VALUE proxy_tunnel) {
CURB_BOOLEAN_SETTER(ruby_curl_easy, proxy_tunnel);
}
|
#proxy_tunnel? ⇒ Boolean
Determine whether this Curl instance will use proxy tunneling.
1621 1622 1623 |
# File 'ext/curb_easy.c', line 1621 static VALUE ruby_curl_easy_proxy_tunnel_q(VALUE self) { CURB_BOOLEAN_GETTER(ruby_curl_easy, proxy_tunnel); } |
#proxy_type ⇒ Fixnum?
Obtain the proxy type that will be used for the following perform
calls.
1079 1080 1081 |
# File 'ext/curb_easy.c', line 1079 static VALUE ruby_curl_easy_proxy_type_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, proxy_type, -1); } |
#proxy_type=(fixnum) ⇒ Fixnum?
Set the proxy type that will be used for the following perform
calls. This should be one of the Curl::CURLPROXY constants.
1069 1070 1071 |
# File 'ext/curb_easy.c', line 1069
static VALUE ruby_curl_easy_proxy_type_set(VALUE self, VALUE proxy_type) {
CURB_IMMED_SETTER(ruby_curl_easy, proxy_type, -1);
}
|
#proxy_url ⇒ String
Obtain the HTTP Proxy URL that will be used by subsequent calls to perform
.
507 508 509 |
# File 'ext/curb_easy.c', line 507 static VALUE ruby_curl_easy_proxy_url_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, proxy_url); } |
#proxy_url=(url) ⇒ Object
call-seq:
easy.proxy_url = string => string
Set the URL of the HTTP proxy to use for subsequent calls to perform
. The URL should specify the the host name or dotted IP address. To specify port number in this string, append :[port] to the end of the host name. The proxy string may be prefixed with [protocol]:// since any such prefix will be ignored. The proxy’s port number may optionally be specified with the separate option proxy_port .
When you tell the library to use an HTTP proxy, libcurl will transparently convert operations to HTTP even if you specify an FTP URL etc. This may have an impact on what other features of the library you can use, such as FTP specifics that don’t work unless you tunnel through the HTTP proxy. Such tunneling is activated with proxy_tunnel = true.
libcurl respects the environment variables http_proxy, ftp_proxy, all_proxy etc, if any of those is set. The proxy_url option does however override any possibly set environment variables.
Starting with libcurl 7.14.1, the proxy host string given in environment variables can be specified the exact same way as the proxy can be set with proxy_url, including protocol prefix (http://) and embedded user + password.
157 158 159 |
# File 'lib/curl/easy.rb', line 157 def proxy_url=(url) set :proxy, url end |
#proxypwd ⇒ String
Obtain the username/password string that will be used for proxy connection during subsequent calls to perform
. The supplied string should have the form “username:password”
621 622 623 |
# File 'ext/curb_easy.c', line 621 static VALUE ruby_curl_easy_proxypwd_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, proxypwd); } |
#proxypwd=(value) ⇒ Object
call-seq:
easy.proxypwd = string => string
Set the username/password string to use for proxy connection during subsequent calls to perform
. The supplied string should have the form “username:password”
211 212 213 |
# File 'lib/curl/easy.rb', line 211 def proxypwd=(value) set :proxyuserpwd, value end |
#put ⇒ Object
6 |
# File 'lib/curl/easy.rb', line 6 alias put http_put |
#put_data=(data) ⇒ Object
Points this Curl::Easy instance to data to be uploaded via PUT. This sets the request to a PUT type request - useful if you want to PUT via a multi handle.
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 |
# File 'ext/curb_easy.c', line 867
static VALUE ruby_curl_easy_put_data_set(VALUE self, VALUE data) {
ruby_curl_easy *rbce;
CURL *curl;
VALUE upload;
VALUE headers;
Data_Get_Struct(self, ruby_curl_easy, rbce);
upload = ruby_curl_upload_new(cCurlUpload);
ruby_curl_upload_stream_set(upload,data);
curl = rbce->curl;
rb_easy_set("upload", upload); /* keep the upload object alive as long as
the easy handle is active or until the upload
is complete or terminated... */
curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, (curl_read_callback)read_data_handler);
#if HAVE_CURLOPT_SEEKFUNCTION
curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, (curl_seek_callback)seek_data_handler);
#endif
curl_easy_setopt(curl, CURLOPT_READDATA, rbce);
#if HAVE_CURLOPT_SEEKDATA
curl_easy_setopt(curl, CURLOPT_SEEKDATA, rbce);
#endif
/*
* we need to set specific headers for the PUT to work... so
* convert the internal headers structure to a HASH if one is set
*/
if (!rb_easy_nil("headers")) {
if (rb_easy_type_check("headers", T_ARRAY) || rb_easy_type_check("headers", T_STRING)) {
rb_raise(rb_eRuntimeError, "Must set headers as a HASH to modify the headers in an PUT request");
}
}
// exit fast if the payload is empty
if (NIL_P(data)) { return data; }
headers = rb_easy_get("headers");
if( headers == Qnil ) {
headers = rb_hash_new();
}
if (rb_respond_to(data, rb_intern("read"))) {
VALUE stat = rb_funcall(data, rb_intern("stat"), 0);
if( stat && rb_hash_aref(headers, rb_str_new2("Content-Length")) == Qnil) {
VALUE size;
if( rb_hash_aref(headers, rb_str_new2("Expect")) == Qnil ) {
rb_hash_aset(headers, rb_str_new2("Expect"), rb_str_new2(""));
}
size = rb_funcall(stat, rb_intern("size"), 0);
curl_easy_setopt(curl, CURLOPT_INFILESIZE, NUM2LONG(size));
}
else if( rb_hash_aref(headers, rb_str_new2("Content-Length")) == Qnil && rb_hash_aref(headers, rb_str_new2("Transfer-Encoding")) == Qnil ) {
rb_hash_aset(headers, rb_str_new2("Transfer-Encoding"), rb_str_new2("chunked"));
}
else if( rb_hash_aref(headers, rb_str_new2("Content-Length")) ) {
VALUE size = rb_funcall(rb_hash_aref(headers, rb_str_new2("Content-Length")), rb_intern("to_i"), 0);
curl_easy_setopt(curl, CURLOPT_INFILESIZE, NUM2LONG(size));
}
}
else if (rb_respond_to(data, rb_intern("to_s"))) {
curl_easy_setopt(curl, CURLOPT_INFILESIZE, RSTRING_LEN(data));
if( rb_hash_aref(headers, rb_str_new2("Expect")) == Qnil ) {
rb_hash_aset(headers, rb_str_new2("Expect"), rb_str_new2(""));
}
}
else {
rb_raise(rb_eRuntimeError, "PUT data must respond to read or to_s");
}
rb_easy_set("headers",headers);
// if we made it this far, all should be well.
return data;
}
|
#redirect_count ⇒ Integer
Retrieve the total number of redirections that were actually followed.
Requires libcurl 7.9.7 or higher, otherwise -1 is always returned.
3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 |
# File 'ext/curb_easy.c', line 3062
static VALUE ruby_curl_easy_redirect_count_get(VALUE self) {
#ifdef HAVE_CURLINFO_REDIRECT_COUNT
ruby_curl_easy *rbce;
long count;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_REDIRECT_COUNT, &count);
return LONG2NUM(count);
#else
rb_warn("Installed libcurl is too old to support redirect_count");
return LONG2NUM(-1);
#endif
}
|
#redirect_time ⇒ Float
Retrieve the total time, in seconds, it took for all redirection steps include name lookup, connect, pretransfer and transfer before final transaction was started. redirect_time
contains the complete execution time for multiple redirections.
Requires libcurl 7.9.7 or higher, otherwise -1 is always returned.
3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 |
# File 'ext/curb_easy.c', line 3039
static VALUE ruby_curl_easy_redirect_time_get(VALUE self) {
#ifdef HAVE_CURLINFO_REDIRECT_TIME
ruby_curl_easy *rbce;
double time;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_REDIRECT_TIME, &time);
return rb_float_new(time);
#else
rb_warn("Installed libcurl is too old to support redirect_time");
return rb_float_new(-1);
#endif
}
|
#redirect_url ⇒ nil
Retrieve the URL a redirect would take you to if you would enable CURLOPT_FOLLOWLOCATION.
Requires libcurl 7.18.2 or higher, otherwise -1 is always returned.
3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 |
# File 'ext/curb_easy.c', line 3087
static VALUE ruby_curl_easy_redirect_url_get(VALUE self) {
#ifdef HAVE_CURLINFO_REDIRECT_URL
ruby_curl_easy *rbce;
char* url;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_REDIRECT_URL, &url);
if (url && url[0]) { // curl returns empty string if none
return rb_str_new2(url);
} else {
return Qnil;
}
#else
rb_warn("Installed libcurl is too old to support redirect_url");
return LONG2NUM(-1);
#endif
}
|
#request_size ⇒ Fixnum
Retrieve the total size of the issued requests. This is so far only for HTTP requests. Note that this may be more than one request if follow_location?
is true.
3201 3202 3203 3204 3205 3206 3207 3208 3209 |
# File 'ext/curb_easy.c', line 3201
static VALUE ruby_curl_easy_request_size_get(VALUE self) {
ruby_curl_easy *rbce;
long size;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_REQUEST_SIZE, &size);
return LONG2NUM(size);
}
|
#reset ⇒ Hash
Reset the Curl::Easy instance, clears out all settings.
from curl.haxx.se/libcurl/c/curl_easy_reset.html Re-initializes all options previously set on a specified CURL handle to the default values. This puts back the handle to the same state as it was in when it was just created with curl_easy_init(3). It does not change the following information kept in the handle: live connections, the Session ID cache, the DNS cache, the cookies and shares.
The return value contains all settings stored.
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
# File 'ext/curb_easy.c', line 450
static VALUE ruby_curl_easy_reset(VALUE self) {
CURLcode ecode;
ruby_curl_easy *rbce;
VALUE opts_dup;
Data_Get_Struct(self, ruby_curl_easy, rbce);
if (rbce->callback_active) {
rb_raise(rb_eRuntimeError, "Cannot close an active curl handle within a callback");
}
opts_dup = rb_funcall(rbce->opts, rb_intern("dup"), 0);
curl_easy_reset(rbce->curl);
ruby_curl_easy_zero(rbce);
curl_easy_setopt(rbce->curl, CURLOPT_ERRORBUFFER, &rbce->err_buf);
/* reset clobbers the private setting, so reset it to self */
ecode = curl_easy_setopt(rbce->curl, CURLOPT_PRIVATE, (void*)self);
if (ecode != CURLE_OK) {
raise_curl_easy_error_exception(ecode);
}
/* Free everything up */
if (rbce->curl_headers) {
curl_slist_free_all(rbce->curl_headers);
rbce->curl_headers = NULL;
}
/* Free everything up */
if (rbce->curl_proxy_headers) {
curl_slist_free_all(rbce->curl_proxy_headers);
rbce->curl_proxy_headers = NULL;
}
return opts_dup;
}
|
#resolve ⇒ Array?
978 979 980 |
# File 'ext/curb_easy.c', line 978 static VALUE ruby_curl_easy_resolve_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, resolve); } |
#resolve=(resolve) ⇒ Object
Set the resolve list to statically resolve hostnames to IP addresses, bypassing DNS for matching hostname/port combinations.
970 971 972 |
# File 'ext/curb_easy.c', line 970
static VALUE ruby_curl_easy_resolve_set(VALUE self, VALUE resolve) {
CURB_OBJECT_HSETTER(ruby_curl_easy, resolve);
}
|
#resolve_mode ⇒ Object
Determines what type of IP address this Curl::Easy instance resolves DNS names to.
1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 |
# File 'ext/curb_easy.c', line 1906
static VALUE ruby_curl_easy_resolve_mode(VALUE self) {
ruby_curl_easy *rbce;
unsigned short rm;
Data_Get_Struct(self, ruby_curl_easy, rbce);
rm = rbce->resolve_mode;
switch(rm) {
case CURL_IPRESOLVE_V4:
return rb_easy_sym("ipv4");
case CURL_IPRESOLVE_V6:
return rb_easy_sym("ipv6");
default:
return rb_easy_sym("auto");
}
}
|
#resolve_mode=(symbol) ⇒ Object
Configures what type of IP address this Curl::Easy instance resolves DNS names to. Valid options are:
- :auto
-
resolves DNS names to all IP versions your system allows
- :ipv4
-
resolves DNS names to IPv4 only
- :ipv6
-
resolves DNS names to IPv6 only
1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 |
# File 'ext/curb_easy.c', line 1934
static VALUE ruby_curl_easy_resolve_mode_set(VALUE self, VALUE resolve_mode) {
if (TYPE(resolve_mode) != T_SYMBOL) {
rb_raise(rb_eTypeError, "Must pass a symbol");
return Qnil;
} else {
ruby_curl_easy *rbce;
ID resolve_mode_id;
Data_Get_Struct(self, ruby_curl_easy, rbce);
resolve_mode_id = rb_to_id(resolve_mode);
if (resolve_mode_id == rb_intern("auto")) {
rbce->resolve_mode = CURL_IPRESOLVE_WHATEVER;
return resolve_mode;
} else if (resolve_mode_id == rb_intern("ipv4")) {
rbce->resolve_mode = CURL_IPRESOLVE_V4;
return resolve_mode;
} else if (resolve_mode_id == rb_intern("ipv6")) {
rbce->resolve_mode = CURL_IPRESOLVE_V6;
return resolve_mode;
} else {
rb_raise(rb_eArgError, "Must set to one of :auto, :ipv4, :ipv6");
return Qnil;
}
}
}
|
#response_code ⇒ Fixnum
Retrieve the last received HTTP or FTP code. This will be zero if no server response code has been received. Note that a proxy’s CONNECT response should be read with http_connect_code
and not this method.
2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 |
# File 'ext/curb_easy.c', line 2830
static VALUE ruby_curl_easy_response_code_get(VALUE self) {
ruby_curl_easy *rbce;
long code;
Data_Get_Struct(self, ruby_curl_easy, rbce);
#ifdef HAVE_CURLINFO_RESPONSE_CODE
curl_easy_getinfo(rbce->curl, CURLINFO_RESPONSE_CODE, &code);
#else
// old libcurl
curl_easy_getinfo(rbce->curl, CURLINFO_HTTP_CODE, &code);
#endif
return LONG2NUM(code);
}
|
#set(opt, val) ⇒ Object
call-seq:
easy.set :sym|Fixnum, value
set options on the curl easy handle see curl.haxx.se/libcurl/c/curl_easy_setopt.html
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/curl/easy.rb', line 34 def set(opt,val) if opt.is_a?(Symbol) option = sym2curl(opt) else option = opt.to_i end begin setopt(option, val) rescue TypeError raise TypeError, "Curb doesn't support setting #{opt} [##{option}] option" end end |
#Fixnum ⇒ Object
Initial access to libcurl curl_easy_setopt
3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 |
# File 'ext/curb_easy.c', line 3489
static VALUE ruby_curl_easy_set_opt(VALUE self, VALUE opt, VALUE val) {
ruby_curl_easy *rbce;
long option = NUM2LONG(opt);
rb_io_t *open_f_ptr;
Data_Get_Struct(self, ruby_curl_easy, rbce);
switch (option) {
/* BEHAVIOR OPTIONS */
case CURLOPT_VERBOSE: {
VALUE verbose = val;
CURB_BOOLEAN_SETTER(ruby_curl_easy, verbose);
} break;
case CURLOPT_FOLLOWLOCATION: {
VALUE follow_location = val;
CURB_BOOLEAN_SETTER(ruby_curl_easy, follow_location);
} break;
/* TODO: CALLBACK OPTIONS */
/* TODO: ERROR OPTIONS */
/* NETWORK OPTIONS */
case CURLOPT_URL: {
VALUE url = val;
CURB_OBJECT_HSETTER(ruby_curl_easy, url);
} break;
case CURLOPT_CUSTOMREQUEST:
curl_easy_setopt(rbce->curl, CURLOPT_CUSTOMREQUEST, NIL_P(val) ? NULL : StringValueCStr(val));
break;
case CURLOPT_HTTP_VERSION:
curl_easy_setopt(rbce->curl, CURLOPT_HTTP_VERSION, NUM2LONG(val));
break;
case CURLOPT_PROXY: {
VALUE proxy_url = val;
CURB_OBJECT_HSETTER(ruby_curl_easy, proxy_url);
} break;
case CURLOPT_INTERFACE: {
VALUE interface_hm = val;
CURB_OBJECT_HSETTER(ruby_curl_easy, interface_hm);
} break;
case CURLOPT_HEADER:
case CURLOPT_NOPROGRESS:
case CURLOPT_NOSIGNAL:
#if HAVE_CURLOPT_PATH_AS_IS
case CURLOPT_PATH_AS_IS:
#endif
#if HAVE_CURLOPT_PIPEWAIT
case CURLOPT_PIPEWAIT:
#endif
case CURLOPT_HTTPGET:
case CURLOPT_NOBODY: {
int type = rb_type(val);
VALUE value;
if (type == T_TRUE) {
value = rb_int_new(1);
} else if (type == T_FALSE) {
value = rb_int_new(0);
} else {
value = rb_funcall(val, rb_intern("to_i"), 0);
}
curl_easy_setopt(rbce->curl, option, NUM2LONG(value));
} break;
case CURLOPT_POST: {
curl_easy_setopt(rbce->curl, CURLOPT_POST, rb_type(val) == T_TRUE);
} break;
case CURLOPT_MAXCONNECTS: {
curl_easy_setopt(rbce->curl, CURLOPT_MAXCONNECTS, NUM2LONG(val));
} break;
case CURLOPT_POSTFIELDS: {
curl_easy_setopt(rbce->curl, CURLOPT_POSTFIELDS, NIL_P(val) ? NULL : StringValueCStr(val));
} break;
case CURLOPT_USERPWD: {
VALUE userpwd = val;
CURB_OBJECT_HSETTER(ruby_curl_easy, userpwd);
} break;
case CURLOPT_PROXYUSERPWD: {
VALUE proxypwd = val;
CURB_OBJECT_HSETTER(ruby_curl_easy, proxypwd);
} break;
case CURLOPT_COOKIE: {
VALUE cookies = val;
CURB_OBJECT_HSETTER(ruby_curl_easy, cookies);
} break;
case CURLOPT_COOKIEFILE: {
VALUE cookiefile = val;
CURB_OBJECT_HSETTER(ruby_curl_easy, cookiefile);
} break;
case CURLOPT_COOKIEJAR: {
VALUE cookiejar = val;
CURB_OBJECT_HSETTER(ruby_curl_easy, cookiejar);
} break;
case CURLOPT_TCP_NODELAY: {
curl_easy_setopt(rbce->curl, CURLOPT_TCP_NODELAY, NUM2LONG(val));
} break;
case CURLOPT_RANGE: {
curl_easy_setopt(rbce->curl, CURLOPT_RANGE, StringValueCStr(val));
} break;
case CURLOPT_RESUME_FROM: {
curl_easy_setopt(rbce->curl, CURLOPT_RESUME_FROM, NUM2LONG(val));
} break;
case CURLOPT_FAILONERROR: {
curl_easy_setopt(rbce->curl, CURLOPT_FAILONERROR, NUM2LONG(val));
} break;
case CURLOPT_SSL_CIPHER_LIST: {
curl_easy_setopt(rbce->curl, CURLOPT_SSL_CIPHER_LIST, StringValueCStr(val));
} break;
case CURLOPT_FORBID_REUSE: {
curl_easy_setopt(rbce->curl, CURLOPT_FORBID_REUSE, NUM2LONG(val));
} break;
#if HAVE_CURLOPT_GSSAPI_DELEGATION
case CURLOPT_GSSAPI_DELEGATION: {
curl_easy_setopt(rbce->curl, CURLOPT_GSSAPI_DELEGATION, NUM2LONG(val));
} break;
#endif
#if HAVE_CURLOPT_UNIX_SOCKET_PATH
case CURLOPT_UNIX_SOCKET_PATH: {
curl_easy_setopt(rbce->curl, CURLOPT_UNIX_SOCKET_PATH, StringValueCStr(val));
} break;
#endif
#if HAVE_CURLOPT_MAX_SEND_SPEED_LARGE
case CURLOPT_MAX_SEND_SPEED_LARGE: {
curl_easy_setopt(rbce->curl, CURLOPT_MAX_SEND_SPEED_LARGE, (curl_off_t) NUM2LL(val));
} break;
#endif
#if HAVE_CURLOPT_MAX_RECV_SPEED_LARGE
case CURLOPT_MAX_RECV_SPEED_LARGE: {
curl_easy_setopt(rbce->curl, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) NUM2LL(val));
} break;
#endif
#if HAVE_CURLOPT_MAXFILESIZE
case CURLOPT_MAXFILESIZE:
curl_easy_setopt(rbce->curl, CURLOPT_MAXFILESIZE, NUM2LONG(val));
break;
#endif
#if HAVE_CURLOPT_TCP_KEEPALIVE
case CURLOPT_TCP_KEEPALIVE:
curl_easy_setopt(rbce->curl, CURLOPT_TCP_KEEPALIVE, NUM2LONG(val));
break;
case CURLOPT_TCP_KEEPIDLE:
curl_easy_setopt(rbce->curl, CURLOPT_TCP_KEEPIDLE, NUM2LONG(val));
break;
case CURLOPT_TCP_KEEPINTVL:
curl_easy_setopt(rbce->curl, CURLOPT_TCP_KEEPINTVL, NUM2LONG(val));
break;
#endif
#if HAVE_CURLOPT_HAPROXYPROTOCOL
case CURLOPT_HAPROXYPROTOCOL:
curl_easy_setopt(rbce->curl, CURLOPT_HAPROXYPROTOCOL, NUM2LONG(val));
break;
#endif
case CURLOPT_STDERR:
// libcurl requires raw FILE pointer and this should be IO object in Ruby.
// Tempfile or StringIO won't work.
Check_Type(val, T_FILE);
GetOpenFile(val, open_f_ptr);
curl_easy_setopt(rbce->curl, CURLOPT_STDERR, rb_io_stdio_file(open_f_ptr));
break;
case CURLOPT_PROTOCOLS:
case CURLOPT_REDIR_PROTOCOLS:
curl_easy_setopt(rbce->curl, option, NUM2LONG(val));
break;
#if HAVE_CURLOPT_SSL_SESSIONID_CACHE
case CURLOPT_SSL_SESSIONID_CACHE:
curl_easy_setopt(rbce->curl, CURLOPT_SSL_SESSIONID_CACHE, NUM2LONG(val));
break;
#endif
#if HAVE_CURLOPT_PROXY_SSL_VERIFYHOST
case CURLOPT_PROXY_SSL_VERIFYHOST:
curl_easy_setopt(rbce->curl, CURLOPT_PROXY_SSL_VERIFYHOST, NUM2LONG(val));
break;
#endif
default:
rb_raise(rb_eTypeError, "Curb unsupported option");
}
return val;
}
|
#ssl_verify_host ⇒ Numeric
Determine whether this Curl instance will verify that the server cert is for the server it is known as.
1700 1701 1702 |
# File 'ext/curb_easy.c', line 1700 static VALUE ruby_curl_easy_ssl_verify_host_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, ssl_verify_host, 0); } |
#ssl_verify_host=(value) ⇒ Object
161 162 163 164 165 |
# File 'lib/curl/easy.rb', line 161 def ssl_verify_host=(value) value = 1 if value.class == TrueClass value = 0 if value.class == FalseClass self.ssl_verify_host_integer=value end |
#ssl_verify_host? ⇒ Boolean
call-seq:
easy.ssl_verify_host? => boolean
Deprecated: call easy.ssl_verify_host instead can be one of [0,1,2]
Determine whether this Curl instance will verify that the server cert is for the server it is known as.
177 178 179 |
# File 'lib/curl/easy.rb', line 177 def ssl_verify_host? ssl_verify_host.nil? ? false : (ssl_verify_host > 0) end |
#ssl_verify_host_integer=(ssl_verify_host) ⇒ Object
Configure whether this Curl instance will verify that the server cert is for the server it is known as. When true (the default) the server certificate must indicate that the server is the server to which you meant to connect, or the connection fails. When false, the connection will succeed regardless of the names in the certificate.
this option controls is of the identity that the server claims. The server could be lying. To control lying, see ssl_verify_peer? .
1689 1690 1691 |
# File 'ext/curb_easy.c', line 1689
static VALUE ruby_curl_easy_ssl_verify_host_set(VALUE self, VALUE ssl_verify_host) {
CURB_IMMED_SETTER(ruby_curl_easy, ssl_verify_host, 0);
}
|
#ssl_verify_peer=(boolean) ⇒ Boolean
Configure whether this Curl instance will verify the SSL peer certificate. When true (the default), and the verification fails to prove that the certificate is authentic, the connection fails. When false, the connection succeeds regardless.
Authenticating the certificate is not by itself very useful. You typically want to ensure that the server, as authentically identified by its certificate, is the server you mean to be talking to. The ssl_verify_host? options controls that.
1661 1662 1663 |
# File 'ext/curb_easy.c', line 1661
static VALUE ruby_curl_easy_ssl_verify_peer_set(VALUE self, VALUE ssl_verify_peer) {
CURB_BOOLEAN_SETTER(ruby_curl_easy, ssl_verify_peer);
}
|
#ssl_verify_peer? ⇒ Boolean
Determine whether this Curl instance will verify the SSL peer certificate.
1672 1673 1674 |
# File 'ext/curb_easy.c', line 1672 static VALUE ruby_curl_easy_ssl_verify_peer_q(VALUE self) { CURB_BOOLEAN_GETTER(ruby_curl_easy, ssl_verify_peer); } |
#ssl_verify_result ⇒ Integer
Retrieve the result of the certification verification that was requested (by setting ssl_verify_peer?
to true
).
3218 3219 3220 3221 3222 3223 3224 3225 3226 |
# File 'ext/curb_easy.c', line 3218
static VALUE ruby_curl_easy_ssl_verify_result_get(VALUE self) {
ruby_curl_easy *rbce;
long result;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_SSL_VERIFYRESULT, &result);
return LONG2NUM(result);
}
|
#ssl_version ⇒ Fixnum
Get the version of SSL/TLS that libcurl will attempt to use.
1557 1558 1559 |
# File 'ext/curb_easy.c', line 1557 static VALUE ruby_curl_easy_ssl_version_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, ssl_version, -1); } |
#ssl_version=(value) ⇒ Fixnum?
Sets the version of SSL/TLS that libcurl will attempt to use. Valid options are:
Curl::CURL_SSLVERSION_DEFAULT
Curl::CURL_SSLVERSION_TLSv1 (TLS 1.x)
Curl::CURL_SSLVERSION_SSLv2
Curl::CURL_SSLVERSION_SSLv3
Curl::CURL_SSLVERSION_TLSv1_0
Curl::CURL_SSLVERSION_TLSv1_1
Curl::CURL_SSLVERSION_TLSv1_2
Curl::CURL_SSLVERSION_TLSv1_3
1547 1548 1549 |
# File 'ext/curb_easy.c', line 1547
static VALUE ruby_curl_easy_ssl_version_set(VALUE self, VALUE ssl_version) {
CURB_IMMED_SETTER(ruby_curl_easy, ssl_version, -1);
}
|
#start_transfer_time ⇒ Float
Retrieve the time, in seconds, it took from the start until the first byte is just about to be transferred. This includes the pre_transfer_time
and also the time the server needs to calculate the result.
3018 3019 3020 3021 3022 3023 3024 3025 3026 |
# File 'ext/curb_easy.c', line 3018
static VALUE ruby_curl_easy_start_transfer_time_get(VALUE self) {
ruby_curl_easy *rbce;
double time;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_STARTTRANSFER_TIME, &time);
return rb_float_new(time);
}
|
#status ⇒ Object
call-seq:
easy.status => String
22 23 24 25 26 |
# File 'lib/curl/easy.rb', line 22 def status # Matches the last HTTP Status - following the HTTP protocol specification 'Status-Line = HTTP-Version SP Status-Code SP (Opt:)Reason-Phrase CRLF' statuses = self.header_str.to_s.scan(/HTTP\/\d(\.\d)?\s(\d+\s.*)\r\n/).map {|match| match[1] } statuses.last.strip if statuses.length > 0 end |
#sym2curl(opt) ⇒ Object
call-seq:
easy.sym2curl :symbol => Fixnum
translates ruby symbols to libcurl
54 55 56 |
# File 'lib/curl/easy.rb', line 54 def sym2curl(opt) Curl.const_get("CURLOPT_#{opt.to_s.upcase}") end |
#timeout ⇒ Numeric
Obtain the maximum time in seconds that you allow the libcurl transfer operation to take.
Uses timeout_ms internally instead of timeout.
1244 1245 1246 1247 1248 |
# File 'ext/curb_easy.c', line 1244
static VALUE ruby_curl_easy_timeout_get(VALUE self) {
ruby_curl_easy *rbce;
Data_Get_Struct(self, ruby_curl_easy, rbce);
return DBL2NUM(rbce->timeout_ms / 1000.0);
}
|
#timeout=(float) ⇒ Numeric
Set the maximum time in seconds that you allow the libcurl transfer operation to take. Normally, name lookups can take a considerable time and limiting operations to less than a few minutes risk aborting perfectly normal operations.
Set to nil (or zero) to disable timeout (it will then only timeout on the system’s internal timeouts).
Uses timeout_ms internally instead of timeout because it allows for better precision and libcurl will use the last set value when both timeout and timeout_ms are set.
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 |
# File 'ext/curb_easy.c', line 1221
static VALUE ruby_curl_easy_timeout_set(VALUE self, VALUE timeout_s) {
ruby_curl_easy *rbce;
Data_Get_Struct(self, ruby_curl_easy, rbce);
if (Qnil == timeout_s || NUM2DBL(timeout_s) <= 0.0) {
rbce->timeout_ms = 0;
} else {
rbce->timeout_ms = (unsigned long)(NUM2DBL(timeout_s) * 1000);
}
return DBL2NUM(rbce->timeout_ms / 1000.0);
}
|
#timeout_ms ⇒ Fixnum?
Obtain the maximum time in milliseconds that you allow the libcurl transfer operation to take.
1282 1283 1284 1285 1286 |
# File 'ext/curb_easy.c', line 1282
static VALUE ruby_curl_easy_timeout_ms_get(VALUE self) {
ruby_curl_easy *rbce;
Data_Get_Struct(self, ruby_curl_easy, rbce);
return LONG2NUM(rbce->timeout_ms);
}
|
#timeout_ms=(fixnum) ⇒ Fixnum?
Set the maximum time in milliseconds that you allow the libcurl transfer operation to take. Normally, name lookups can take a considerable time and limiting operations to less than a few minutes risk aborting perfectly normal operations.
Set to nil (or zero) to disable timeout (it will then only timeout on the system’s internal timeouts).
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 |
# File 'ext/curb_easy.c', line 1262
static VALUE ruby_curl_easy_timeout_ms_set(VALUE self, VALUE timeout_ms) {
ruby_curl_easy *rbce;
Data_Get_Struct(self, ruby_curl_easy, rbce);
if (Qnil == timeout_ms || NUM2DBL(timeout_ms) <= 0.0) {
rbce->timeout_ms = 0;
} else {
rbce->timeout_ms = NUM2ULONG(timeout_ms);
}
return ULONG2NUM(rbce->timeout_ms);
}
|
#total_time ⇒ Float
Retrieve the total time in seconds for the previous transfer, including name resolving, TCP connect etc.
2924 2925 2926 2927 2928 2929 2930 2931 2932 |
# File 'ext/curb_easy.c', line 2924
static VALUE ruby_curl_easy_total_time_get(VALUE self) {
ruby_curl_easy *rbce;
double time;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_TOTAL_TIME, &time);
return rb_float_new(time);
}
|
#unescape("some%20text") ⇒ Object
Convert the given URL encoded input string to a “plain string” and return the result. All input characters that are URL encoded (%XX where XX is a two-digit hexadecimal number) are converted to their binary versions.
3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 |
# File 'ext/curb_easy.c', line 3739
static VALUE ruby_curl_easy_unescape(VALUE self, VALUE str) {
ruby_curl_easy *rbce;
int rlen;
char *result;
VALUE rresult;
Data_Get_Struct(self, ruby_curl_easy, rbce);
#if (LIBCURL_VERSION_NUM >= 0x070f04)
result = (char*)curl_easy_unescape(rbce->curl, StringValuePtr(str), (int)RSTRING_LEN(str), &rlen);
#else
result = (char*)curl_unescape(StringValuePtr(str), (int)RSTRING_LEN(str));
rlen = strlen(result);
#endif
rresult = rb_str_new(result, rlen);
curl_free(result);
return rresult;
}
|
#unrestricted_auth=(boolean) ⇒ Boolean
Configure whether this Curl instance may use any HTTP authentication method available when necessary.
1787 1788 1789 |
# File 'ext/curb_easy.c', line 1787
static VALUE ruby_curl_easy_unrestricted_auth_set(VALUE self, VALUE unrestricted_auth) {
CURB_BOOLEAN_SETTER(ruby_curl_easy, unrestricted_auth);
}
|
#unrestricted_auth? ⇒ Boolean
Determine whether this Curl instance may use any HTTP authentication method available when necessary.
1798 1799 1800 |
# File 'ext/curb_easy.c', line 1798 static VALUE ruby_curl_easy_unrestricted_auth_q(VALUE self) { CURB_BOOLEAN_GETTER(ruby_curl_easy, unrestricted_auth); } |
#upload_speed ⇒ Float
Retrieve the average upload speed that curl measured for the preceeding complete upload.
3149 3150 3151 3152 3153 3154 3155 3156 3157 |
# File 'ext/curb_easy.c', line 3149
static VALUE ruby_curl_easy_upload_speed_get(VALUE self) {
ruby_curl_easy *rbce;
double bytes;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_SPEED_UPLOAD, &bytes);
return rb_float_new(bytes);
}
|
#uploaded_bytes ⇒ Float
Retrieve the total amount of bytes that were uploaded in the preceeding transfer.
3115 3116 3117 3118 3119 3120 3121 3122 3123 |
# File 'ext/curb_easy.c', line 3115
static VALUE ruby_curl_easy_uploaded_bytes_get(VALUE self) {
ruby_curl_easy *rbce;
double bytes;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_SIZE_UPLOAD, &bytes);
return rb_float_new(bytes);
}
|
#uploaded_content_length ⇒ Float
Retrieve the content-length of the upload.
3259 3260 3261 3262 3263 3264 3265 3266 3267 |
# File 'ext/curb_easy.c', line 3259
static VALUE ruby_curl_easy_uploaded_content_length_get(VALUE self) {
ruby_curl_easy *rbce;
double bytes;
Data_Get_Struct(self, ruby_curl_easy, rbce);
curl_easy_getinfo(rbce->curl, CURLINFO_CONTENT_LENGTH_UPLOAD, &bytes);
return rb_float_new(bytes);
}
|
#url ⇒ String
Obtain the URL that will be used by subsequent calls to perform
.
497 498 499 |
# File 'ext/curb_easy.c', line 497 static VALUE ruby_curl_easy_url_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, url); } |
#url=(u) ⇒ Object
call-seq:
easy.url = "http://some.url/" => "http://some.url/"
Set the URL for subsequent calls to perform
. It is acceptable (and even recommended) to reuse Curl::Easy instances by reassigning the URL between calls to perform
.
128 129 130 |
# File 'lib/curl/easy.rb', line 128 def url=(u) set :url, u end |
#use_netrc=(boolean) ⇒ Boolean
Configure whether this Curl instance will use data from the user’s .netrc file for FTP connections.
1734 1735 1736 |
# File 'ext/curb_easy.c', line 1734
static VALUE ruby_curl_easy_use_netrc_set(VALUE self, VALUE use_netrc) {
CURB_BOOLEAN_SETTER(ruby_curl_easy, use_netrc);
}
|
#use_netrc? ⇒ Boolean
Determine whether this Curl instance will use data from the user’s .netrc file for FTP connections.
1745 1746 1747 |
# File 'ext/curb_easy.c', line 1745 static VALUE ruby_curl_easy_use_netrc_q(VALUE self) { CURB_BOOLEAN_GETTER(ruby_curl_easy, use_netrc); } |
#use_ssl ⇒ Fixnum
Get the desired level for using SSL on FTP connections.
1578 1579 1580 |
# File 'ext/curb_easy.c', line 1578 static VALUE ruby_curl_easy_use_ssl_get(VALUE self) { CURB_IMMED_GETTER(ruby_curl_easy, use_ssl, -1); } |
#use_ssl=(value) ⇒ Fixnum?
Ensure libcurl uses SSL for FTP connections. Valid options are Curl::CURL_USESSL_NONE, Curl::CURL_USESSL_TRY, Curl::CURL_USESSL_CONTROL, and Curl::CURL_USESSL_ALL.
1568 1569 1570 |
# File 'ext/curb_easy.c', line 1568
static VALUE ruby_curl_easy_use_ssl_set(VALUE self, VALUE use_ssl) {
CURB_IMMED_SETTER(ruby_curl_easy, use_ssl, -1);
}
|
#useragent ⇒ "Ruby/Curb"
Obtain the user agent string used for this Curl::Easy instance
791 792 793 |
# File 'ext/curb_easy.c', line 791 static VALUE ruby_curl_easy_useragent_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, useragent); } |
#useragent=(useragent) ⇒ Object
Set the user agent string for this Curl::Easy instance
781 782 783 |
# File 'ext/curb_easy.c', line 781
static VALUE ruby_curl_easy_useragent_set(VALUE self, VALUE useragent) {
CURB_OBJECT_HSETTER(ruby_curl_easy, useragent);
}
|
#username ⇒ String
Get the current username
1495 1496 1497 1498 1499 1500 1501 |
# File 'ext/curb_easy.c', line 1495 static VALUE ruby_curl_easy_username_get(VALUE self) { #if HAVE_CURLOPT_USERNAME CURB_OBJECT_HGETTER(ruby_curl_easy, username); #else return Qnil; #endif } |
#username=(string) ⇒ String
Set the HTTP Authentication username.
1481 1482 1483 1484 1485 1486 1487 |
# File 'ext/curb_easy.c', line 1481
static VALUE ruby_curl_easy_username_set(VALUE self, VALUE username) {
#if HAVE_CURLOPT_USERNAME
CURB_OBJECT_HSETTER(ruby_curl_easy, username);
#else
return Qnil;
#endif
}
|
#userpwd ⇒ String
Obtain the username/password string that will be used for subsequent calls to perform
.
609 610 611 |
# File 'ext/curb_easy.c', line 609 static VALUE ruby_curl_easy_userpwd_get(VALUE self) { CURB_OBJECT_HGETTER(ruby_curl_easy, userpwd); } |
#userpwd=(value) ⇒ Object
call-seq:
easy.userpwd = string => string
Set the username/password string to use for subsequent calls to perform
. The supplied string should have the form “username:password”
199 200 201 |
# File 'lib/curl/easy.rb', line 199 def userpwd=(value) set :userpwd, value end |
#verbose=(boolean) ⇒ Boolean
Configure whether this Curl instance gives verbose output to STDERR during transfers. Ignored if this instance has an on_debug handler.
1809 1810 1811 |
# File 'ext/curb_easy.c', line 1809
static VALUE ruby_curl_easy_verbose_set(VALUE self, VALUE verbose) {
CURB_BOOLEAN_SETTER(ruby_curl_easy, verbose);
}
|
#verbose? ⇒ Boolean
Determine whether this Curl instance gives verbose output to STDERR during transfers.
1820 1821 1822 |
# File 'ext/curb_easy.c', line 1820 static VALUE ruby_curl_easy_verbose_q(VALUE self) { CURB_BOOLEAN_GETTER(ruby_curl_easy, verbose); } |
#version=(http_version) ⇒ Object
116 117 118 |
# File 'lib/curl/easy.rb', line 116 def version=(http_version) set :http_version, http_version end |