| Class | Curl::Easy |
| In: |
.doc-tmp/curb_easy.c
ext/curb.rb |
| Parent: | Object |
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.
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.
Create a new Curl::Easy instance, optionally supplying the URL. The block form allows further configuration to be supplied before the instance is returned.
Clone this Curl::Easy instance, creating a new instance. This method duplicates the underlying CURL* handle.
Retrieve the time, in seconds, it took from the start until the connect to the remote host (or proxy) was completed.
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.
Set a cookiejar file to use for this Curl::Easy instance. This file will be used to persist cookies.
Note that you must set enable_cookies true to enable the cookie engine, or this option will be ignored.
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.
Retrieve the content-length of the download. This is the value read from the Content-Length: field.
Configure whether the libcurl cookie engine is enabled for this Curl::Easy instance.
Determine whether the libcurl cookie engine is enabled for this Curl::Easy instance.
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).
Configure whether this Curl instance will fetch remote file times, if available.
Determine whether this Curl instance will fetch remote file times, if available.
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.
Configure whether this Curl instance will follow Location: headers in HTTP responses. Redirects will only be followed to the extent specified by max_redirects.
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).
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.
Determine whether this Curl instance will verify the SSL peer certificate.
Retrieve the total size of all the headers received in the preceeding transfer.
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.
Obtain the HTTP authentication types that may be used for the following perform calls.
Set the HTTP authentication types that may be used for the following perform calls. This is a bitmap made by ORing together the Curl::CURLAUTH constants.
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.
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.
TODO Not yet implemented
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:
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.
TODO Not yet implemented
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.
Obtain the local port that will be used for the following perform calls.
This option is ignored if compiled against libcurl < 7.15.2.
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.
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.
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.
Obtain the maximum number of redirections to follow in the following perform calls.
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.
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.
Determine whether this Curl instance uses multipart/formdata content type for HTTP POST requests.
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).
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.
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.
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.
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.
Retrieve the errno variable from a connect failure (requires libcurl 7.12.2 or higher, otherwise 0 is always returned).
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 GET request method (i.e. this method is a synonym for http_get when using HTTP URLs).
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.
Obtain the proxy authentication types that may be used for the following perform calls.
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.
Obtain the proxy port that will be used for the following perform calls.
Set the proxy port that will be used for the following perform calls.
Obtain the proxy type that will be used for the following perform calls.
Set the proxy type that will be used for the following perform calls. This should be one of the Curl::CURLPROXY constants.
Obtain the HTTP Proxy URL that will be used by subsequent calls to perform.
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.
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"
Set the username/password string to use for proxy connection during subsequent calls to perform. The supplied string should have the form "username:password"
Retrieve the total number of redirections that were actually followed.
Requires libcurl 7.9.7 or higher, otherwise -1 is always returned.
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.
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.
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.
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? .
Determine whether this Curl instance will verify that the server cert is for the server it is known as.
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.
Determine whether this Curl instance will verify the SSL peer certificate.
Retrieve the result of the certification verification that was requested (by setting +ssl_verify_peer?+ to true).
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.
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).
Retrieve the total time in seconds for the previous transfer, including name resolving, TCP connect etc.
Retrieve the total time in seconds for the previous transfer, including name resolving, TCP connect etc.
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.
Configure whether this Curl instance may use any HTTP authentication method available when necessary.
Determine whether this Curl instance may use any HTTP authentication method available when necessary.
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.
Configure whether this Curl instance will use data from the user‘s .netrc file for FTP connections.
Determine whether this Curl instance will use data from the user‘s .netrc file for FTP connections.
Obtain the username/password string that will be used for subsequent calls to perform.
Set the username/password string to use for subsequent calls to perform. The supplied string should have the form "username:password"
Determine whether this Curl instance gives verbose output to STDERR during transfers.