lib/ethon/easy/options.rb in ethon-0.5.10 vs lib/ethon/easy/options.rb in ethon-0.5.11

- old
+ new

@@ -29,19 +29,18 @@ # @return [ void ] def accept_encoding=(value) Curl.set_option(:accept_encoding, value_for(value, :string), handle) end - # Pass a string to a zero terminated - # string naming a file holding one or more certificates to verify - # the peer with. This makes sense only when used in combination with - # the CURLOPT_SSL_VERIFYPEER option. If CURLOPT_SSL_VERIFYPEER is - # zero, CURLOPT_CAINFO need not even indicate an accessible file. - # This option is by default set to the system path where libcurl's - # cacert bundle is assumed to be stored, as established at build time. - # When built against NSS, this is the directory that the NSS certificate - # database resides in. + # Pass a string to a zero-terminated string naming a file holding one + # or more certificates with which to verify the peer. This makes sense + # only when used in combination with the CURLOPT_SSL_VERIFYPEER option. + # If CURLOPT_SSL_VERIFYPEER is zero, CURLOPT_CAINFO need not even + # indicate an accessible file. This option is by default set to the + # system path where libcurl's cacert bundle is assumed to be stored, + # as established at build time. When built against NSS, this is the + # directory that the NSS certificate database resides in. # # @example Set cainfo option. # easy.cainfo = "/path/to/file" # # @param [ String ] value The value to set. @@ -49,14 +48,14 @@ # @return [ void ] def cainfo=(value) Curl.set_option(:cainfo, value_for(value, :string), handle) end - # Pass a string to a zero terminated string naming a directory holding - # multiple CA certificates to verify the peer with. If libcurl is built - # against OpenSSL, the certificate directory must be prepared using the - # openssl c_rehash utility. This makes sense only when used in + # Pass a string to a zero-terminated string naming a directory holding + # multiple CA certificates with which to verify the peer. If libcurl is + # built against OpenSSL, the certificate directory must be prepared using + # the openssl c_rehash utility. This makes sense only when used in # combination with the CURLOPT_SSL_VERIFYPEER option. If # CURLOPT_SSL_VERIFYPEER is zero, CURLOPT_CAPATH need not even indicate # an accessible path. The CURLOPT_CAPATH function apparently does not # work in Windows due to some limitation in openssl. This option is # OpenSSL-specific and does nothing if libcurl is built to use GnuTLS. @@ -76,11 +75,11 @@ # Pass a long. It should contain 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 zero to switch to the default built-in connection timeout # \- 300 seconds. See also the CURLOPT_TIMEOUT option. - # In unix-like systems, this might cause signals to be used unless + # In Unix-like systems, this might cause signals to be used unless # CURLOPT_NOSIGNAL is set. # # @example Set connecttimeout option. # easy.connecttimeout = 1 # @@ -105,10 +104,55 @@ # @return [ void ] def connecttimeout_ms=(value) Curl.set_option(:connecttimeout_ms, value_for(value, :int), handle) end + # Sets the cookie value + # + # If you want to read/write the cookie from a file, + # see cookiefile= and cookiejar= + # + # @example Set the cookie option + # easy.cookie = "cookie-value" + # + # @param [ String ] value The cookie value + # + # @return [ void ] + def cookie=(value) + Curl.set_option(:cookie, value_for(value, :string), handle) + end + + # Sets the cookie jar file + # The file will only be used to write the cookie value + # If you want to read the cookie from a file, see cookiefile= + # + # If the file does not exist, it will try to create it + # + # @example Set cookiejar option + # easy.cookiejar = "/path/to/file" + # + # @param [ String ] file The path to the file + # + # @return [ void ] + def cookiejar=(file) + Curl.set_option(:cookiejar, value_for(file, :string), handle) + end + + # Sets the cookie file + # The file will only be used to read the cookie value + # If you want to set the cookie in a file, see cookiejar= + # + # @example Set cookiefile option + # easy.cookiefile = "/path/to/file" + # + # @param [ String ] file The path to the file + # + # @return [ void ] + def cookiefile=(file) + Curl.set_option(:cookiefile, value_for(file, :string), handle) + end + # Pass a string as parameter, which should be the full data to post in # a HTTP POST operation. It behaves as the CURLOPT_POSTFIELDS option, # but the original data are copied by the library, allowing the # application to overwrite the original data after setting this option. # Because data are copied, care must be taken when using this option in @@ -128,11 +172,11 @@ # @return [ void ] def copypostfields=(value) Curl.set_option(:copypostfields, value_for(value, :string), handle) end - # Pass a pointer to a zero terminated string as parameter. It can be + # Pass a pointer to a zero-terminated string as parameter. It can be # used to specify the request instead of GET or HEAD when performing # HTTP based requests, instead of LIST and NLST when performing FTP # directory listings and instead of LIST and RETR when issuing POP3 # based commands. This is particularly useful, for example, for # performing a HTTP DELETE request or a POP3 DELE command. @@ -141,11 +185,11 @@ # When you change the request method by setting CURLOPT_CUSTOMREQUEST # to something, you don't actually change how libcurl behaves or acts # in regards to the particular request method, it will only change the # actual string sent in the request. # For example: - # With the HTTP protocol when you tell libcurl to do a HEAD request, + # With the HTTP protocol, when you tell libcurl to do a HEAD request, # but then specify a GET though a custom request libcurl will still act # as if it sent a HEAD. To switch to a proper HEAD use CURLOPT_NOBODY, # to switch to a proper POST use CURLOPT_POST or CURLOPT_POSTFIELDS and # to switch to a proper GET use CURLOPT_HTTPGET. # With the POP3 protocol when you tell libcurl to use a custom request @@ -170,11 +214,11 @@ # @return [ void ] def customrequest=(value) Curl.set_option(:customrequest, value_for(value, :string), handle) end - # Pass a long, this sets the timeout in seconds. Name resolves will be + # Pass a long, this sets the timeout in seconds. Name resolutions will be # kept in memory for this number of seconds. Set to zero to completely # disable caching, or set to -1 to make the cached entries remain # forever. By default, libcurl caches this info for 60 seconds. # The name resolve functions of various libc implementations don't # re-read name server information unless explicitly told so (for @@ -476,10 +520,21 @@ # @return [ void ] def postfieldsize=(value) Curl.set_option(:postfieldsize, value_for(value, :int), handle) end + # + # @example Set protocols option. + # easy.protocols = :http + # + # @param [ Symbol ] value The value or array of values to set. + # + # @return [ void ] + def postredir=(value) + Curl.set_option(:postredir, value_for(value, :enum, :postredir), handle) + end + # Pass a long that holds a bitmask of CURLPROTO_* defines. If used, this # bitmask limits what protocols libcurl may use in the transfer. This # allows you to have a libcurl built to support a wide range of protocols # but still limit specific transfers to only be allowed to use a subset # of them. By default libcurl will accept all protocols it supports. See @@ -863,10 +918,25 @@ # @return [ void ] def timeout_ms=(value) Curl.set_option(:timeout_ms, value_for(value, :int), handle) end + # A parameter set to 1 tells the library it can continue to send + # authentication (user+password) when following locations, even + # when hostname changed. This option is meaningful only when setting + # CURLOPT_FOLLOWLOCATION. + # + # @example Set unrestricted auth. + # easy.unrestricted_auth = true + # + # @param [ Boolean ] value The value to set. + # + # @return [ void ] + def unrestricted_auth=(value) + Curl.set_option(:unrestricted_auth, value_for(value, :bool), handle) + end + # A parameter set to 1 tells the library to prepare for an upload. The # CURLOPT_READDATA and CURLOPT_INFILESIZE or CURLOPT_INFILESIZE_LARGE # options are also interesting for uploads. If the protocol is HTTP, # uploading means using the PUT request unless you tell libcurl # otherwise. @@ -1138,9 +1208,15 @@ raise Errors::InvalidValue.new(option, value) end elsif type == :enum && (option == :protocols || option == :redir_protocols) Array(value).map do |v| Curl::Protocols.to_h.fetch(v) do + raise Errors::InvalidValue.new(option, v) + end + end.inject(:+) + elsif type == :enum && option == :postredir + Array(value).map do |v| + Curl::Postredir.to_h.fetch(v) do raise Errors::InvalidValue.new(option, v) end end.inject(:+) elsif type == :enum && option == :proxytype Curl::Proxy.to_h.fetch(value) do