class Curl::Easy

Public Class Methods

defer_multi_close(multi, easy, owner: Thread.current) click to toggle source
# File lib/curl/easy.rb, line 35
def defer_multi_close(multi, easy, owner: Thread.current)
  deferred_multi_close_mutex.synchronize do
    @deferred_multi_closes ||= []
    return if @deferred_multi_closes.any? { |entry| entry[:multi].equal?(multi) }

    multi.instance_variable_set(:@deferred_close, true)
    @deferred_multi_closes << { multi: multi, easy: easy, owner: owner }
  end
end
deferred_multi_close_mutex() click to toggle source
# File lib/curl/easy.rb, line 5
def deferred_multi_close_mutex
  @deferred_multi_close_mutex ||= Mutex.new
end
deferred_multi_closes() click to toggle source
# File lib/curl/easy.rb, line 9
def deferred_multi_closes
  deferred_multi_close_mutex.synchronize do
    (@deferred_multi_closes ||= []).dup
  end
end
Curl::Easy.download(url, filename = url.split(/\?/).first.split(/\//).last) { |curl| ... } click to toggle source

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.

# File lib/curl/easy.rb, line 661
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) → [ErrCode, String] click to toggle source

translate an internal libcurl error to ruby error class

static VALUE ruby_curl_easy_error_message(VALUE klass, VALUE code) {
  return rb_curl_easy_error(NUM2INT(code));
}
flush_deferred_multi_closes(all_threads: false) click to toggle source
# File lib/curl/easy.rb, line 45
def flush_deferred_multi_closes(all_threads: false)
  pending = deferred_multi_close_mutex.synchronize do
    @deferred_multi_closes ||= []

    if all_threads
      @deferred_multi_closes.shift(@deferred_multi_closes.length)
    else
      owner = Thread.current
      remaining = []
      current = []

      @deferred_multi_closes.each do |entry|
        if entry[:owner].equal?(owner)
          current << entry
        else
          remaining << entry
        end
      end

      @deferred_multi_closes = remaining
      current
    end
  end

  pending.each do |entry|
    multi = entry[:multi]
    easy = entry[:easy]

    unless release_deferred_multi_close(multi, easy)
      defer_multi_close(multi, easy, owner: entry[:owner])
    end
  end
end
Curl::Easy.http_delete(url) { |easy| ... } → #<Curl::Easy...> click to toggle source

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.

# File lib/curl/easy.rb, line 636
def http_delete(*args)
  c = Curl::Easy.new(*args)
  yield c if block_given?
  c.http_delete
  c
end
Curl::Easy.http_get(url) { |easy| ... } → #<Curl::Easy...> click to toggle source

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.

# File lib/curl/easy.rb, line 542
def http_get(*args)
  c = Curl::Easy.new(*args)
  yield c if block_given?
  c.http_get
  c
end
Curl::Easy.http_head(url) { |easy| ... } → #<Curl::Easy...> click to toggle source

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.

# File lib/curl/easy.rb, line 559
def http_head(*args)
  c = Curl::Easy.new(*args)
  yield c if block_given?
  c.http_head
  c
end
Curl::Easy.http_patch(url, data) {|c| ... } click to toggle source
Curl::Easy.http_patch(url, "some=urlencoded%20form%20data&and=so%20on") → true
Curl::Easy.http_patch(url, "some=urlencoded%20form%20data", "and=so%20on", ...) → true
Curl::Easy.http_patch(url, "some=urlencoded%20form%20data", Curl::PostField, "and=so%20on", ...) → true
Curl::Easy.http_patch(url, Curl::PostField, Curl::PostField ..., Curl::PostField) → true

see easy.http_patch

# File lib/curl/easy.rb, line 594
def http_patch(*args)
  url = args.shift
  c = Curl::Easy.new(url)
  yield c if block_given?
  c.http_patch(*args)
  c
end
Curl::Easy.http_post(url, "some=urlencoded%20form%20data&and=so%20on") → true click to toggle source
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.

# File lib/curl/easy.rb, line 618
def http_post(*args)
  url = args.shift
  c = Curl::Easy.new url
  yield c if block_given?
  c.http_post(*args)
  c
end
Curl::Easy.http_put(url, data) {|c| ... } click to toggle source
Curl::Easy.http_put(url, "some=urlencoded%20form%20data&and=so%20on") → true
Curl::Easy.http_put(url, "some=urlencoded%20form%20data", "and=so%20on", ...) → true
Curl::Easy.http_put(url, "some=urlencoded%20form%20data", Curl::PostField, "and=so%20on", ...) → true
Curl::Easy.http_put(url, Curl::PostField, Curl::PostField ..., Curl::PostField) → true

see easy.http_put

# File lib/curl/easy.rb, line 576
def http_put(*args)
  url = args.shift
  c = Curl::Easy.new(url)
  yield c if block_given?
  c.http_put(*args)
  c
end
Curl::Easy.new → #<Curl::Easy...> click to toggle source
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.

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);

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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);
  rbce->self = self;

  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*)rbce);
  if (ecode != CURLE_OK) {
    raise_curl_easy_error_exception(ecode);
  }

  if (blk != Qnil) {
    rb_funcall(blk, idCall, 1, self);
  }

  return self;
}
Curl::Easy.perform(url) { |easy| ... } → #<Curl::Easy...> click to toggle source

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.

# File lib/curl/easy.rb, line 525
def perform(*args)
  c = Curl::Easy.new(*args)
  yield c if block_given?
  c.perform
  c
end
release_deferred_multi_close(multi, easy) click to toggle source
# File lib/curl/easy.rb, line 15
def release_deferred_multi_close(multi, easy)
  if easy && multi.requests[easy.object_id]
    begin
      multi.remove(easy)
    rescue StandardError
      # Deferred cleanup only applies to implicit single-easy multis, so
      # clear any stale Ruby bookkeeping and continue closing the handle.
      multi.instance_variable_set(:@requests, {})
    end
  else
    multi.instance_variable_set(:@requests, {})
  end

  multi.instance_variable_set(:@deferred_close, false)
  multi._close
  true
rescue StandardError
  false
end

Public Instance Methods

_curb_native_close()
Alias for: close
multi=multi → "#<Curl::Multi>"
Alias for: multi=
app_connect_time() click to toggle source
static VALUE ruby_curl_easy_app_connect_time_get(VALUE self) {
  ruby_curl_easy *rbce;
  double time;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_APPCONNECT_TIME, &time);

  return rb_float_new(time);
}
autoreferer=(p1) click to toggle source

easy = Curl::Easy.new easy.autoreferer=true

static VALUE ruby_curl_easy_autoreferer_set(VALUE self, VALUE autoreferer) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);

  if (Qtrue == autoreferer) {
    curl_easy_setopt(rbce->curl, CURLOPT_AUTOREFERER, 1);
  }
  else {
    curl_easy_setopt(rbce->curl, CURLOPT_AUTOREFERER, 0);
  }

  return autoreferer;
}
body()
Alias for: body_str
body_str → "response body" click to toggle source

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.

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);
}
Also aliased as: body
cacert → string click to toggle source

Obtain the cacert file to use for this Curl::Easy instance.

static VALUE ruby_curl_easy_cacert_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, cacert);
}
cacert = string → "" click to toggle source

Set a cacert bundle to use for this Curl::Easy instance. This file will be used to validate SSL certificates.

static VALUE ruby_curl_easy_cacert_set(VALUE self, VALUE cacert) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, cacert);
}
cert → string click to toggle source

Obtain the cert file to use for this Curl::Easy instance.

static VALUE ruby_curl_easy_cert_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, cert);
}
cert = string → "" click to toggle source

Set a cert file to use for this Curl::Easy instance. This file will be used to validate SSL connections.

static VALUE ruby_curl_easy_cert_set(VALUE self, VALUE cert) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, cert);
}
cert_key → "cert_key.file" click to toggle source

Obtain the cert key file to use for this Curl::Easy instance.

static VALUE ruby_curl_easy_cert_key_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, cert_key);
}
cert_key = "cert_key.file" → "" click to toggle source

Set a cert key to use for this Curl::Easy instance. This file will be used to validate SSL certificates.

static VALUE ruby_curl_easy_cert_key_set(VALUE self, VALUE cert_key) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, cert_key);
}
certpassword = string → "" click to toggle source

Set a password used to open the specified cert

static VALUE ruby_curl_easy_certpassword_set(VALUE self, VALUE certpassword) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, certpassword);
}
certtype → string click to toggle source

Obtain the cert type used for this Curl::Easy instance

static VALUE ruby_curl_easy_certtype_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, certtype);
}
certtype = "PEM|DER" → "" click to toggle source

Set a cert type to use for this Curl::Easy instance. Default is PEM

static VALUE ruby_curl_easy_certtype_set(VALUE self, VALUE certtype) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, certtype);
}
clone → <easy clone> click to toggle source

Clone this Curl::Easy instance, creating a new instance. This method duplicates the underlying CURL* handle.

static VALUE ruby_curl_easy_clone(VALUE self) {
  ruby_curl_easy *rbce, *newrbce;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);

  newrbce = ALLOC(ruby_curl_easy);
  if (!newrbce) {
    rb_raise(rb_eNoMemError, "Failed to allocate memory for Curl::Easy clone");
  }
  /* shallow copy */
  memcpy(newrbce, rbce, sizeof(ruby_curl_easy));

  /* now deep copy */
  newrbce->curl = curl_easy_duphandle(rbce->curl);
  newrbce->curl_headers = (rbce->curl_headers) ? duplicate_curl_slist(rbce->curl_headers) : NULL;
  newrbce->curl_proxy_headers = (rbce->curl_proxy_headers) ? duplicate_curl_slist(rbce->curl_proxy_headers) : NULL;
  newrbce->curl_ftp_commands = (rbce->curl_ftp_commands) ? duplicate_curl_slist(rbce->curl_ftp_commands) : NULL;
  newrbce->curl_resolve = (rbce->curl_resolve) ? duplicate_curl_slist(rbce->curl_resolve) : NULL;

  /* A cloned easy should not retain ownership reference to the original multi. */
  newrbce->multi = Qnil;
  newrbce->callback_error = Qnil;

  if (rbce->opts != Qnil) {
    newrbce->opts = rb_funcall(rbce->opts, rb_intern("dup"), 0);
  }

  /* Set the error buffer on the new curl handle using the new err_buf */
  curl_easy_setopt(newrbce->curl, CURLOPT_ERRORBUFFER, newrbce->err_buf);

  VALUE clone = TypedData_Wrap_Struct(cCurlEasy, &ruby_curl_easy_data_type, newrbce);
  newrbce->self = clone;
  curl_easy_setopt(newrbce->curl, CURLOPT_PRIVATE, (void*)newrbce);

  return clone;
}
Also aliased as: dup
close → nil click to toggle source

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.

static VALUE ruby_curl_easy_close(VALUE self) {
  CURLcode ecode;
  ruby_curl_easy *rbce;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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);
  rbce->self = self;

  /* give the new curl handle a reference back to the ruby object */
  ecode = curl_easy_setopt(rbce->curl, CURLOPT_PRIVATE, (void*)rbce);
  if (ecode != CURLE_OK) {
    raise_curl_easy_error_exception(ecode);
  }

  return Qnil;
}
Also aliased as: _curb_native_close
code()

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.

Alias for: response_code
connect_time → float click to toggle source

Retrieve the time, in seconds, it took from the start until the connect to the remote host (or proxy) was completed.

static VALUE ruby_curl_easy_connect_time_get(VALUE self) {
  ruby_curl_easy *rbce;
  double time;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_CONNECT_TIME, &time);

  return rb_float_new(time);
}
connect_timeout → fixnum or nil click to toggle source

Obtain the maximum time in seconds that you allow the connection to the server to take.

static VALUE ruby_curl_easy_connect_timeout_get(VALUE self) {
  CURB_IMMED_GETTER(ruby_curl_easy, connect_timeout, 0);
}
connect_timeout = fixnum or nil → fixnum or nil click to toggle source

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).

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 or nil click to toggle source

Obtain the maximum time in milliseconds that you allow the connection to the server to take.

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 or nil → fixnum or nil click to toggle source

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).

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 → "content/type" or nil click to toggle source

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.

static VALUE ruby_curl_easy_content_type_get(VALUE self) {
  ruby_curl_easy *rbce;
  char* type;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 click to toggle source

Obtain the cookiefile path for this Curl::Easy instance (used to load cookies when the cookie engine is enabled).

static VALUE ruby_curl_easy_cookiefile_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, cookiefile);
}
cookiefile = string → string click to toggle source

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.

Note: assigning nil has no effect; pass a path string to use a cookie file.

# File lib/curl/easy.rb, line 404
def cookiefile=(value)
  set :cookiefile, value
end
cookiejar → string click to toggle source

Obtain the cookiejar path for this Curl::Easy instance (used to persist cookies when the cookie engine is enabled).

static VALUE ruby_curl_easy_cookiejar_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, cookiejar);
}
cookiejar = string → string click to toggle source

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.

Note: assigning nil has no effect; pass a path string to persist cookies to a file.

# File lib/curl/easy.rb, line 420
def cookiejar=(value)
  set :cookiejar, value
end
cookielist → cookielist click to toggle source

Retrieves the cookies curl knows in an array of strings. Returned strings are in Netscape cookiejar format or in Set-Cookie format. Since 7.43.0 cookies in the Set-Cookie format without a domain name are not exported.

To modify the cookie engine (add/replace/remove), use +easy.cookielist= string+ or +easy.set(:cookielist, string)+ with one of the following accepted inputs:

  • A Set-Cookie style header string: “Set-Cookie: name=value; Domain=example.com; Path=/; Expires=…”

  • One or more lines in Netscape cookie file format (tab-separated fields)

  • Special commands: “ALL” (clear all), “SESS” (remove session cookies), “FLUSH” (write to jar), “RELOAD” (reload from file)

@see curl.se/libcurl/c/CURLINFO_COOKIELIST.html option CURLINFO_COOKIELIST of

<code>curl_easy_getopt(3)</code> to see how libcurl behaves.

@note requires libcurl 7.14.1 or higher, otherwise -1 is always returned @return [Array<String>, nil, -1] array of strings, or nil if there are no cookies, or -1 if the libcurl version is too old

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;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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
}
cookielist = string → string click to toggle source

Modify cookies in libcurl’s internal cookie engine (CURLOPT_COOKIELIST). Accepts a Set-Cookie style string, one or more lines in Netscape cookie file format, or one of the special commands: “ALL” (clear), “SESS” (remove session cookies), “FLUSH” (write to jar), “RELOAD” (reload from file).

Examples:

easy.cookielist = "Set-Cookie: session=42; Domain=example.com; Path=/;"
easy.cookielist = [
  ['.example.com', 'TRUE', '/', 'FALSE', 0, 'c1', 'v1'].join("\t"),
  ['.example.com', 'TRUE', '/', 'FALSE', 0, 'c2', 'v2'].join("\t"),
  ''
].join("\n")
easy.cookielist = 'ALL'   # clear all cookies in the engine
# File lib/curl/easy.rb, line 442
def cookielist=(value)
  set :cookielist, value
end
cookies → "name1=content1; name2=content2;" click to toggle source

Obtain the manually set Cookie header string for this Curl::Easy instance.

Notes:

  • This corresponds to libcurl’s CURLOPT_COOKIE and only affects the outgoing Cookie request header. It does NOT modify the internal libcurl cookie engine that stores cookies received via Set-Cookie.

  • To inspect or modify cookies stored in the cookie engine, use easy.cookielist (getter) and easy.cookielist= or +easy.set(:cookielist, …)+ (setter).

  • To clear a previously set manual Cookie header, assign an empty string. Assigning nil currently has no effect.

static VALUE ruby_curl_easy_cookies_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, cookies);
}
cookies = "name1=content1; name2=content2;" → string click to toggle source

Set the manual Cookie request header for 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;”.

Notes:

  • This only affects the outgoing Cookie header (libcurl CURLOPT_COOKIE) and does NOT alter the internal libcurl cookie engine (which stores cookies from Set-Cookie).

  • To change cookies stored in the engine, use {#cookielist} / {#cookielist=} or {#set} with :cookielist.

  • To clear a previously set manual Cookie header, assign an empty string (”). Assigning nil has no effect in current curb versions.

# File lib/curl/easy.rb, line 389
def cookies=(value)
  set :cookie, value
end
http_delete
Alias for: http_delete
easy = Curl::Easy.new("url") do|c| click to toggle source
delete = true
end
perform
# File lib/curl/easy.rb, line 240
def delete=(onoff)
  set :customrequest, onoff ? 'DELETE' : nil
  onoff
end
dns_cache_timeout → fixnum or nil click to toggle source

Obtain the dns cache timeout in seconds.

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 or nil → fixnum or nil click to toggle source

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.

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 click to toggle source

Retrieve the average download speed that curl measured for the preceeding complete download.

static VALUE ruby_curl_easy_download_speed_get(VALUE self) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);

#ifdef HAVE_CURLINFO_SPEED_DOWNLOAD_T
  curl_off_t bytes;
  curl_easy_getinfo(rbce->curl, CURLINFO_SPEED_DOWNLOAD_T, &bytes);
  return LL2NUM(bytes);
#else
  double bytes;
  curl_easy_getinfo(rbce->curl, CURLINFO_SPEED_DOWNLOAD, &bytes);
  return rb_float_new(bytes);
#endif
}
downloaded_bytes → float click to toggle source

Retrieve the total amount of bytes that were downloaded in the preceeding transfer.

static VALUE ruby_curl_easy_downloaded_bytes_get(VALUE self) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);

#ifdef HAVE_CURLINFO_SIZE_DOWNLOAD_T
  curl_off_t bytes;
  curl_easy_getinfo(rbce->curl, CURLINFO_SIZE_DOWNLOAD_T, &bytes);
  return LL2NUM(bytes);
#else
  double bytes;
  curl_easy_getinfo(rbce->curl, CURLINFO_SIZE_DOWNLOAD, &bytes);
  return rb_float_new(bytes);
#endif
}
downloaded_content_length → float click to toggle source

Retrieve the content-length of the download. This is the value read from the Content-Length: field.

static VALUE ruby_curl_easy_downloaded_content_length_get(VALUE self) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);

#ifdef HAVE_CURLINFO_CONTENT_LENGTH_DOWNLOAD_T
  curl_off_t bytes;
  curl_easy_getinfo(rbce->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &bytes);
  return LL2NUM(bytes);
#else
  double bytes;
  curl_easy_getinfo(rbce->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &bytes);
  return rb_float_new(bytes);
#endif
}
dup → <easy clone>

Clone this Curl::Easy instance, creating a new instance. This method duplicates the underlying CURL* handle.

Alias for: clone
enable_cookies = boolean → boolean click to toggle source

Configure whether the libcurl cookie engine is enabled for this Curl::Easy instance. When enabled, cookies received via Set-Cookie are stored by libcurl and automatically sent on subsequent matching requests. Use easy.cookiefile to load cookies and easy.cookiejar to persist them.

This setting is independent from the manual Cookie header set via easy.cookies. The manual header is additive and can be cleared by assigning an empty string.

static VALUE ruby_curl_easy_enable_cookies_set(VALUE self, VALUE enable_cookies)
{
  CURB_BOOLEAN_SETTER(ruby_curl_easy, enable_cookies);
}
enable_cookies? → boolean click to toggle source

Determine whether the libcurl cookie engine is enabled for this Curl::Easy instance.

static VALUE ruby_curl_easy_enable_cookies_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, enable_cookies);
}
encoding → string click to toggle source

Get the set encoding types

static VALUE ruby_curl_easy_encoding_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, encoding);
}
encoding = string → string click to toggle source

Set the accepted encoding types, curl will handle all of the decompression

static VALUE ruby_curl_easy_encoding_set(VALUE self, VALUE encoding) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, encoding);
}
escape("some text") → "some%20text" click to toggle source

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).

static VALUE ruby_curl_easy_escape(VALUE self, VALUE svalue) {
  ruby_curl_easy *rbce;
  char *result;
  VALUE rresult;
  VALUE str = svalue;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 click to toggle source

Configure whether this Curl instance will fetch remote file times, if available.

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 click to toggle source

Determine whether this Curl instance will fetch remote file times, if available.

static VALUE ruby_curl_easy_fetch_file_time_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, fetch_file_time);
}
file_time → fixnum click to toggle source

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.

static VALUE ruby_curl_easy_file_time_get(VALUE self) {
#ifdef HAVE_CURLINFO_FILETIME
  ruby_curl_easy *rbce;
  long time;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 = boolean → boolean click to toggle source

Configure whether this Curl instance will follow Location: headers in HTTP responses. Redirects will only be followed to the extent specified by max_redirects.

# File lib/curl/easy.rb, line 465
def follow_location=(onoff)
  set :followlocation, onoff
end
follow_location? → boolean click to toggle source

Determine whether this Curl instance will follow Location: headers in HTTP responses.

static VALUE ruby_curl_easy_follow_location_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, follow_location);
}
ftp_commands → array or nil click to toggle source
static VALUE ruby_curl_easy_ftp_commands_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, ftp_commands);
}
ftp_commands = ["CWD /", "MKD directory"] → ["CWD /", ...] click to toggle source

Explicitly sets the list of commands to execute on the FTP server when calling perform.

NOTE:

  • This maps to libcurl CURLOPT_QUOTE; it sends commands on the control connection.

  • Do not include data-transfer commands like LIST/NLST/RETR/STOR here. libcurl does not parse PASV/EPSV replies from QUOTE commands and will not establish the required data connection. For directory listings, set CURLOPT_DIRLISTONLY (via ‘easy.set(:dirlistonly, true)`) and request an FTP directory URL (e.g. “host/path/”) so libcurl manages PASV/EPSV and the data connection for you.

static VALUE ruby_curl_easy_ftp_commands_set(VALUE self, VALUE ftp_commands) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, ftp_commands);
}
ftp_entry_path → "C:\ftp\root\" or nil click to toggle source

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).

static VALUE ruby_curl_easy_ftp_entry_path_get(VALUE self) {
#ifdef HAVE_CURLINFO_FTP_ENTRY_PATH
  ruby_curl_easy *rbce;
  char* path = NULL;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 ftp_entry_path");
  return Qnil;
#endif
}
ftp_filemethod → fixnum click to toggle source

Get the configuration for how libcurl will reach files on the server.

static VALUE ruby_curl_easy_ftp_filemethod_get(VALUE self) {
  CURB_IMMED_GETTER(ruby_curl_easy, ftp_filemethod, -1);
}
ftp_filemethod = value → fixnum or nil click to toggle source

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).

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 or nil click to toggle source

Obtain the maximum time that libcurl will wait for FTP command responses.

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 or nil → fixnum or nil click to toggle source

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.

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()
Alias for: http_get
getinfo(opt) → nil click to toggle source

Iniital access to libcurl curl_easy_getinfo, remember getinfo doesn’t return the same values as setopt

@note This method is not implemented yet. @param [Fixnum] code Constant CURLINFO_* from libcurl @return [nil]

static VALUE ruby_curl_easy_get_opt(VALUE self, VALUE opt) {
  return Qnil;
}
head()
Alias for: header_str
easy = Curl::Easy.new("url") do|c| click to toggle source
head = true
end
perform
# File lib/curl/easy.rb, line 453
def head=(onoff)
  set :nobody, onoff
end
header_in_body = boolean → boolean click to toggle source

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).

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 click to toggle source

Determine whether this Curl instance will return HTTP headers combined with body data.

static VALUE ruby_curl_easy_header_in_body_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, header_in_body);
}
header_size → fixnum click to toggle source

Retrieve the total size of all the headers received in the preceeding transfer.

static VALUE ruby_curl_easy_header_size_get(VALUE self) {
  ruby_curl_easy *rbce;
  long size;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_HEADER_SIZE, &size);

  return LONG2NUM(size);
}
header_str → "response header" click to toggle source

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.

static VALUE ruby_curl_easy_header_str_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, header_data);
}
Also aliased as: head
headers → Hash, Array or Str click to toggle source

Obtain the custom HTTP headers for following requests.

static VALUE ruby_curl_easy_headers_get(VALUE self) {
  ruby_curl_easy *rbce;
  VALUE headers;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 = "Header: val" → "Header: val" click to toggle source
headers = {"Header" => "val" ..., "Header" => "val"} → {"Header: val", ...}
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.

static VALUE ruby_curl_easy_headers_set(VALUE self, VALUE headers) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, headers);
}
http(verb) click to toggle source

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.

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 or nil click to toggle source

Obtain the HTTP authentication types that may be used for the following perform calls.

static VALUE ruby_curl_easy_http_auth_types_get(VALUE self) {
  CURB_IMMED_GETTER(ruby_curl_easy, http_auth_types, 0);
}
http_auth_types = fixnum or nil → fixnum or nil click to toggle source
http_auth_types = [:basic,:digest,:digest_ie,:gssnegotiate, :ntlm, :any, :anysafe]

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.

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);
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 click to toggle source

Retrieve the last received proxy response code to a CONNECT request.

static VALUE ruby_curl_easy_http_connect_code_get(VALUE self) {
  ruby_curl_easy *rbce;
  long code;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_HTTP_CONNECTCODE, &code);

  return LONG2NUM(code);
}
http_delete click to toggle source

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.

# File lib/curl/easy.rb, line 507
def http_delete
  self.http :DELETE
end
Also aliased as: delete
http_get → true click to toggle source

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.

# File lib/curl/easy.rb, line 493
def http_get
  set :httpget, true
  http :GET
end
Also aliased as: get
http_head → true click to toggle source

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.

# File lib/curl/easy.rb, line 478
def http_head
  set :nobody, true
  ret = self.perform
  set :nobody, false
  ret
end
http_patch("url=encoded%20form%20data;and=so%20on") → true click to toggle source
http_patch("url=encoded%20form%20data", "and=so%20on", ...) → true
http_patch("url=encoded%20form%20data", Curl::PostField, "and=so%20on", ...) → true
http_patch(Curl::PostField, Curl::PostField ..., Curl::PostField) → true

PATCH 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.

When multipart_form_post is true the multipart logic is used; otherwise, the arguments are joined into a raw PATCH body.

static VALUE ruby_curl_easy_perform_patch(int argc, VALUE *argv, VALUE self) {
  ruby_curl_easy *rbce;
  CURL *curl;
  int i;
  VALUE args_ary;

  rb_scan_args(argc, argv, "*", &args_ary);
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl = rbce->curl;

  /* Clear the error buffer */
  memset(rbce->err_buf, 0, CURL_ERROR_SIZE);

  /* Set the custom HTTP method to PATCH */
  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PATCH");

  if (rbce->multipart_form_post) {
    VALUE ret;
    struct curl_httppost *first = NULL, *last = NULL;

    /* Build the multipart form (same logic as for POST) */
    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) {
        long j, argv_len = RARRAY_LEN(argv[i]);
        for (j = 0; j < argv_len; ++j) {
          if (rb_obj_is_instance_of(rb_ary_entry(argv[i], j), cCurlPostField)) {
            append_to_form(rb_ary_entry(argv[i], j), &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;
      }
    }
    /* Disable the POST flag */
    curl_easy_setopt(curl, CURLOPT_POST, 0);
    /* Use the built multipart form as the request body */
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, first);
    struct easy_form_perform_args perform_args = { curl, first };
    ret = rb_ensure(call_easy_perform, self, ensure_free_form_post, (VALUE)&perform_args);
    return ret;
  } else {
    /* Join arguments into a raw PATCH body */
    VALUE patch_body = rb_funcall(args_ary, idJoin, 1, rbstrAmp);
    if (patch_body == Qnil) {
      rb_raise(eCurlErrError, "Failed to join arguments");
      return Qnil;
    } else {
      if (rb_type(patch_body) == T_STRING && RSTRING_LEN(patch_body) > 0) {
        ruby_curl_easy_post_body_set(self, patch_body);
      }
      /* If postdata_buffer is still nil, set it so that the PATCH header is enabled */
      if (rb_easy_nil("postdata_buffer")) {
        ruby_curl_easy_post_body_set(self, patch_body);
      }
      return rb_funcall(self, rb_intern("perform"), 0);
    }
  }
}
http_post("url=encoded%20form%20data;and=so%20on") → true click to toggle source
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.

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);

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl = rbce->curl;

  memset(rbce->err_buf, 0, CURL_ERROR_SIZE);

  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);
    struct easy_form_perform_args perform_args = { curl, first };
    ret = rb_ensure(call_easy_perform, self, ensure_free_form_post, (VALUE)&perform_args);

    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);
    }
  }
}
Also aliased as: post
http_put(data) → true click to toggle source

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.

static VALUE ruby_curl_easy_perform_put(int argc, VALUE *argv, VALUE self) {
  ruby_curl_easy *rbce;
  CURL *curl;
  VALUE args_ary;
  int i;

  rb_scan_args(argc, argv, "*", &args_ary);
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl = rbce->curl;

  memset(rbce->err_buf, 0, CURL_ERROR_SIZE);
  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");

  /* New: if no arguments were provided, treat as an empty PUT */
  if (RARRAY_LEN(args_ary) == 0) {
    /* Option 1: explicitly set an empty body */
    ruby_curl_easy_put_data_set(self, rb_str_new2(""));
  }
  /* If a single argument is given and it is a String or responds to read, use legacy behavior */
  else if (RARRAY_LEN(args_ary) == 1 &&
           (rb_type(rb_ary_entry(args_ary, 0)) == T_STRING ||
            rb_respond_to(rb_ary_entry(args_ary, 0), rb_intern("read")))) {
    ruby_curl_easy_put_data_set(self, rb_ary_entry(args_ary, 0));
  }
  /* Otherwise, if multipart_form_post is true, use multipart logic */
  else if (rbce->multipart_form_post) {
    VALUE ret;
    struct curl_httppost *first = NULL, *last = NULL;
    for (i = 0; i < RARRAY_LEN(args_ary); i++) {
      VALUE field = rb_ary_entry(args_ary, i);
      if (rb_obj_is_instance_of(field, cCurlPostField)) {
        append_to_form(field, &first, &last);
      } else if (rb_type(field) == T_ARRAY) {
        long j;
        for (j = 0; j < RARRAY_LEN(field); j++) {
          VALUE subfield = rb_ary_entry(field, j);
          if (rb_obj_is_instance_of(subfield, cCurlPostField)) {
            append_to_form(subfield, &first, &last);
          } else {
            rb_raise(eCurlErrInvalidPostField,
                     "You must use PostFields only with multipart form posts");
          }
        }
      } else {
        rb_raise(eCurlErrInvalidPostField,
                 "You must use PostFields only with multipart form posts");
      }
    }
    curl_easy_setopt(curl, CURLOPT_POST, 0);
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, first);
    /* Set the method explicitly to PUT */
    curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
    struct easy_form_perform_args perform_args = { curl, first };
    ret = rb_ensure(call_easy_perform, self, ensure_free_form_post, (VALUE)&perform_args);
    return ret;
  }
  /* Fallback: join all arguments */
  else {
    VALUE post_body = rb_funcall(args_ary, idJoin, 1, rbstrAmp);
    if (post_body != Qnil && rb_type(post_body) == T_STRING &&
        RSTRING_LEN(post_body) > 0) {
      ruby_curl_easy_put_data_set(self, post_body);
    }
  }
  return rb_funcall(self, rb_intern("perform"), 0);
}
Also aliased as: put
http_version → integer click to toggle source

Returns the HTTP protocol version currently configured.

static VALUE ruby_curl_easy_http_version_get(VALUE self) {
  ruby_curl_easy *rbce;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);

  return LONG2NUM(rbce->http_version);
}
http_version = Curl::HTTP_1_1 → Curl::HTTP_1_1 click to toggle source

Force libcurl to use a specific HTTP protocol version. By default libcurl negotiates the highest version supported by both peers. Supported constants include Curl::HTTP_NONE, Curl::HTTP_1_0, Curl::HTTP_1_1, Curl::HTTP_2_0, Curl::HTTP_2TLS, and Curl::HTTP_2_PRIOR_KNOWLEDGE (when provided by libcurl).

static VALUE ruby_curl_easy_http_version_set(VALUE self, VALUE version) {
  ruby_curl_easy *rbce;
  long http_version;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);

  if (NIL_P(version)) {
    http_version = CURL_HTTP_VERSION_NONE;
  } else {
    http_version = NUM2LONG(version);
  }

  rbce->http_version = http_version;

  return version;
}
ignore_content_length = boolean click to toggle source

Configure whether this Curl::Easy instance should ignore the content length header.

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 click to toggle source

Determine whether this Curl::Easy instance ignores the content length header.

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/>" click to toggle source
static VALUE ruby_curl_easy_inspect(VALUE self) {
  char buf[64];
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 click to toggle source

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.

static VALUE ruby_curl_easy_interface_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, interface_hm);
}
interface = string → string click to toggle source

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.

# File lib/curl/easy.rb, line 345
def interface=(value)
  set :interface, value
end
last_effective_url → "http://some.url" or nil click to toggle source

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.

static VALUE ruby_curl_easy_last_effective_url_get(VALUE self) {
  ruby_curl_easy *rbce;
  char* url;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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" or nil click to toggle source
static VALUE ruby_curl_easy_last_error(VALUE self) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 click to toggle source
static VALUE ruby_curl_easy_last_result(VALUE self) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  return LONG2NUM(rbce->last_result);
}
local_port → fixnum or nil click to toggle source

Obtain the local port that will be used for the following perform calls.

This option is ignored if compiled against libcurl < 7.15.2.

static VALUE ruby_curl_easy_local_port_get(VALUE self) {
  CURB_IMMED_PORT_GETTER(ruby_curl_easy, local_port);
}
local_port = fixnum or nil → fixnum or nil click to toggle source

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.

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 or nil click to toggle source

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.

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 or nil → fixnum or nil click to toggle source

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.

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 or nil click to toggle source

Obtain the minimum transfer speed over +low_speed+time+ below which the transfer will be aborted.

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 or nil → fixnum or nil click to toggle source

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.

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 or nil click to toggle source

Obtain the time that the transfer should be below low_speed_limit for the library to abort it.

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 or nil → fixnum or nil click to toggle source

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.

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 or nil → fixnum or nil click to toggle source

Get the maximal receiving transfer speed (in bytes per second)

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 or nil → fixnum or nil click to toggle source

Set the maximal receiving transfer speed (in bytes per second)

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 or nil click to toggle source

Obtain the maximum number of redirections to follow in the following perform calls.

static VALUE ruby_curl_easy_max_redirects_get(VALUE self) {
  CURB_IMMED_GETTER(ruby_curl_easy, max_redirs, -1);
}
max_redirects = fixnum or nil → fixnum or nil click to toggle source

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.

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 or nil → fixnum or nil click to toggle source

Get the maximal sending transfer speed (in bytes per second)

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 or nil → fixnum or nil click to toggle source

Set the maximal sending transfer speed (in bytes per second)

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>" click to toggle source
static VALUE ruby_curl_easy_multi_get(VALUE self) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  return rbce->multi;
}
multi=multi → "#<Curl::Multi>" click to toggle source
static VALUE ruby_curl_easy_multi_set(VALUE self, VALUE multi) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);

  if (!NIL_P(multi) && rb_obj_is_kind_of(multi, cCurlMulti) != Qtrue) {
    rb_raise(rb_eTypeError, "expected Curl::Multi or nil");
  }

  rbce->multi = multi;
  return rbce->multi;
}
Also aliased as: _curb_native_multi_set
multipart_form_post = boolean → boolean click to toggle source

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.

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 click to toggle source

Determine whether this Curl instance uses multipart/formdata content type for HTTP POST requests.

static VALUE ruby_curl_easy_multipart_form_post_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, multipart_form_post);
}
name_lookup_time → float click to toggle source

Retrieve the time, in seconds, it took from the start until the name resolving was completed.

static VALUE ruby_curl_easy_name_lookup_time_get(VALUE self) {
  ruby_curl_easy *rbce;
  double time;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_NAMELOOKUP_TIME, &time);

  return rb_float_new(time);
}
nosignal=(onoff) click to toggle source

easy = Curl::Easy.new easy.nosignal = true

# File lib/curl/easy.rb, line 229
def nosignal=(onoff)
  set :nosignal, !!onoff
end
num_connects → integer click to toggle source

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).

static VALUE ruby_curl_easy_num_connects_get(VALUE self) {
#ifdef HAVE_CURLINFO_NUM_CONNECTS
  ruby_curl_easy *rbce;
  long result;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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| ... } → <old handler> click to toggle source

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.

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| ... } → <old handler> click to toggle source

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.

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| ... } → <old handler> click to toggle source

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.

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| ... } → <old handler> click to toggle source

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

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| ... } → <old handler> click to toggle source

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.

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| ... } → <old handler;> click to toggle source

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

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| ... } → <old handler> click to toggle source

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.

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| ... } → <old handler;> click to toggle source

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

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| ... } → <old handler> click to toggle source

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

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 click to toggle source

Retrieve the errno variable from a connect failure (requires libcurl 7.12.2 or higher, otherwise 0 is always returned).

static VALUE ruby_curl_easy_os_errno_get(VALUE self) {
#ifdef HAVE_CURLINFO_OS_ERRNO
  ruby_curl_easy *rbce;
  long result;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 click to toggle source

Get the current password

static VALUE ruby_curl_easy_password_get(VALUE self) {
#ifdef HAVE_CURLOPT_PASSWORD
  CURB_OBJECT_HGETTER(ruby_curl_easy, password);
#else
  return Qnil;
#endif
}
password = string → string click to toggle source

Set the HTTP Authentication password.

static VALUE ruby_curl_easy_password_set(VALUE self, VALUE password) {
#ifdef HAVE_CURLOPT_PASSWORD
  CURB_OBJECT_HSETTER(ruby_curl_easy, password);
#else
  return Qnil;
#endif
}
perform → true click to toggle source

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.

# File lib/curl/easy.rb, line 165
def perform
  self.class.flush_deferred_multi_closes

  if Curl.scheduler_active? && self.multi.nil?
    ret = Curl.perform_with_scheduler(self)
  else
    multi = self.multi
    created_multi = multi.nil?
    raised = false

    if created_multi
      multi = Curl::Multi.new
      self.multi = multi
    end

    begin
      multi.add(self)
      ret = multi.perform
      multi.remove(self) if self.multi == multi
    rescue Exception
      raised = true
      raise
    ensure
      if created_multi
        if raised
          unless self.class.release_deferred_multi_close(multi, self)
            self.class.defer_multi_close(multi, self)
          end
          self.multi = nil if self.multi == multi
        elsif Curl::Multi.autoclose
          multi.__send__(:_autoclose)
          self.multi = nil if self.multi == multi
        else
          self.multi = multi
        end
      elsif Curl::Multi.autoclose
        multi.__send__(:_autoclose)
        self.multi = nil if self.multi == multi
      else
        self.multi = multi
      end
    end
  end

  if (callback_error = _take_callback_error)
    raise callback_error
  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(*args)
Alias for: http_post
post_body → string or nil click to toggle source

Obtain the POST body used in this Curl::Easy instance.

static VALUE ruby_curl_easy_post_body_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, postdata_buffer);
}
post_body=(p1) click to toggle source
static VALUE ruby_curl_easy_post_body_set(VALUE self, VALUE post_body) {
  return ruby_curl_easy_post_body_set_with_mode(self, post_body, 1);
}
pre_transfer_time → float click to toggle source

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.

static VALUE ruby_curl_easy_pre_transfer_time_get(VALUE self) {
  ruby_curl_easy *rbce;
  double time;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_PRETRANSFER_TIME, &time);

  return rb_float_new(time);
}
primary_ip → "xx.xx.xx.xx" or nil click to toggle source

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

static VALUE ruby_curl_easy_primary_ip_get(VALUE self) {
  ruby_curl_easy *rbce;
  char* ip;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 or nil click to toggle source

Obtain the proxy authentication types that may be used for the following perform calls.

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 or nil → fixnum or nil click to toggle source

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.

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, Array or Str click to toggle source

Obtain the custom HTTP proxy_headers for following requests.

static VALUE ruby_curl_easy_proxy_headers_get(VALUE self) {
  ruby_curl_easy *rbce;
  VALUE proxy_headers;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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=(p1) click to toggle source
static VALUE ruby_curl_easy_proxy_headers_set(VALUE self, VALUE proxy_headers) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, proxy_headers);
}
proxy_port → fixnum or nil click to toggle source

Obtain the proxy port that will be used for the following perform calls.

static VALUE ruby_curl_easy_proxy_port_get(VALUE self) {
  CURB_IMMED_PORT_GETTER(ruby_curl_easy, proxy_port);
}
proxy_port = fixnum or nil → fixnum or nil click to toggle source

Set the proxy port that will be used for the following perform calls.

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 click to toggle source

Configure whether this Curl instance will use proxy tunneling.

static VALUE ruby_curl_easy_proxy_tunnel_set(VALUE self, VALUE proxy_tunnel) {
  CURB_BOOLEAN_SETTER(ruby_curl_easy, proxy_tunnel);
}
proxy_tunnel? → boolean click to toggle source

Determine whether this Curl instance will use proxy tunneling.

static VALUE ruby_curl_easy_proxy_tunnel_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, proxy_tunnel);
}
proxy_type → fixnum or nil click to toggle source

Obtain the proxy type that will be used for the following perform calls.

static VALUE ruby_curl_easy_proxy_type_get(VALUE self) {
  CURB_IMMED_GETTER(ruby_curl_easy, proxy_type, -1);
}
proxy_type = fixnum or nil → fixnum or nil click to toggle source

Set the proxy type that will be used for the following perform calls. This should be one of the Curl::CURLPROXY constants.

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 click to toggle source

Obtain the HTTP Proxy URL that will be used by subsequent calls to perform.

static VALUE ruby_curl_easy_proxy_url_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, proxy_url);
}
proxy_url = string → string click to toggle source

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.

# File lib/curl/easy.rb, line 298
def proxy_url=(url)
  set :proxy, url
end
proxypwd → string click to toggle source

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”

static VALUE ruby_curl_easy_proxypwd_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, proxypwd);
}
proxypwd = string → string click to toggle source

Set the username/password string to use for proxy connection during subsequent calls to perform. The supplied string should have the form “username:password”

# File lib/curl/easy.rb, line 368
def proxypwd=(value)
  set :proxyuserpwd, value
end
put(*args)
Alias for: http_put
put_data = data → "" click to toggle source

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.

static VALUE ruby_curl_easy_put_data_set(VALUE self, VALUE data) {
  ruby_curl_easy *rbce;
  CURL *curl;
  VALUE upload;
  VALUE headers;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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_POST, 0);
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0);
  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  curl_easy_setopt(curl, CURLOPT_READFUNCTION, (curl_read_callback)read_data_handler);
#ifdef HAVE_CURLOPT_SEEKFUNCTION
  curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, (curl_seek_callback)seek_data_handler);
#endif
  curl_easy_setopt(curl, CURLOPT_READDATA, rbce);
#ifdef 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 click to toggle source

Retrieve the total number of redirections that were actually followed.

Requires libcurl 7.9.7 or higher, otherwise -1 is always returned.

static VALUE ruby_curl_easy_redirect_count_get(VALUE self) {
#ifdef HAVE_CURLINFO_REDIRECT_COUNT
  ruby_curl_easy *rbce;
  long count;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 click to toggle source

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.

static VALUE ruby_curl_easy_redirect_time_get(VALUE self) {
#ifdef HAVE_CURLINFO_REDIRECT_TIME
  ruby_curl_easy *rbce;
  double time;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 → "http://some.url" or nil click to toggle source

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.

static VALUE ruby_curl_easy_redirect_url_get(VALUE self) {
#ifdef HAVE_CURLINFO_REDIRECT_URL
  ruby_curl_easy *rbce;
  char* url;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 click to toggle source

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.

static VALUE ruby_curl_easy_request_size_get(VALUE self) {
  ruby_curl_easy *rbce;
  long size;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_REQUEST_SIZE, &size);

  return LONG2NUM(size);
}
request_target = string → string click to toggle source

Set the request-target used in the HTTP request line (libcurl CURLOPT_REQUEST_TARGET). Useful for absolute-form request targets (e.g., when speaking to proxies) or special targets like “*” (OPTIONS *). Requires libcurl with CURLOPT_REQUEST_TARGET support.

# File lib/curl/easy.rb, line 310
def request_target=(value)
  if Curl.const_defined?(:CURLOPT_REQUEST_TARGET)
    set :request_target, value
  else
    raise NotImplementedError, "CURLOPT_REQUEST_TARGET is not supported by this libcurl"
  end
end
reset → Hash click to toggle source

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.

static VALUE ruby_curl_easy_reset(VALUE self) {
  CURLcode ecode;
  ruby_curl_easy *rbce;
  VALUE opts_dup;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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);

  ruby_curl_easy_cleanup(self, rbce);
  curl_easy_reset(rbce->curl);
  ruby_curl_easy_zero(rbce);
  rbce->self = self;

  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*)rbce);
  if (ecode != CURLE_OK) {
    raise_curl_easy_error_exception(ecode);
  }

  return opts_dup;
}
resolve → array or nil click to toggle source
static VALUE ruby_curl_easy_resolve_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, resolve);
}
resolve = [ "example.com:80:127.0.0.1" ] → [ "example.com:80:127.0.0.1" ] click to toggle source

Set the resolve list to statically resolve hostnames to IP addresses, bypassing DNS for matching hostname/port combinations.

static VALUE ruby_curl_easy_resolve_set(VALUE self, VALUE resolve) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, resolve);
}
resolve_mode → symbol click to toggle source

Determines what type of IP address this Curl::Easy instance resolves DNS names to.

static VALUE ruby_curl_easy_resolve_mode(VALUE self) {
  ruby_curl_easy *rbce;
  unsigned short rm;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 → symbol click to toggle source

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

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;
    TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 click to toggle source

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.

static VALUE ruby_curl_easy_response_code_get(VALUE self) {
  ruby_curl_easy *rbce;
  long code;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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);
}
Also aliased as: code
set :sym|Fixnum, value click to toggle source

set options on the curl easy handle see curl.haxx.se/libcurl/c/curl_easy_setopt.html

# File lib/curl/easy.rb, line 133
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
setopt(opt, val) → val click to toggle source

Initial access to libcurl curl_easy_setopt

@param [Fixnum] opt The option to set, see Curl::CURLOPT_* constants @param [Object] val @return [Object] val @raise [TypeError] if the option is not supported @note Some options - like url or cookie - aren’t set directly throught curl_easy_setopt, but stored in the Ruby object state. @note When curl_easy_setopt is called, return value is not checked here.

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;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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: {
    long http_version = NIL_P(val) ? CURL_HTTP_VERSION_NONE : NUM2LONG(val);
    rbce->http_version = http_version;
    curl_easy_setopt(rbce->curl, CURLOPT_HTTP_VERSION, http_version);
    } 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:
#ifdef HAVE_CURLOPT_PATH_AS_IS
  case CURLOPT_PATH_AS_IS:
#endif
#ifdef 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: {
    ruby_curl_easy_post_body_set_with_mode(self, val, 0);
  } 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;
#ifdef HAVE_CURLOPT_NOPROXY
  case CURLOPT_NOPROXY: {
    VALUE noproxy = val;
    CURB_OBJECT_HSETTER(ruby_curl_easy, noproxy);
    } break;
#endif
  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;
#ifdef HAVE_CURLOPT_REQUEST_TARGET
  case CURLOPT_REQUEST_TARGET: {
    /* Forward request-target directly to libcurl as a string. */
    curl_easy_setopt(rbce->curl, CURLOPT_REQUEST_TARGET, NIL_P(val) ? NULL : StringValueCStr(val));
    } break;
#endif
  case CURLOPT_TCP_NODELAY: {
    curl_easy_setopt(rbce->curl, CURLOPT_TCP_NODELAY, NUM2LONG(val));
    } break;
  /* FTP-specific toggles */
#ifdef HAVE_CURLOPT_DIRLISTONLY
  case CURLOPT_DIRLISTONLY: {
    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, CURLOPT_DIRLISTONLY, NUM2LONG(value));
    } break;
#endif
#ifdef HAVE_CURLOPT_FTP_USE_EPSV
  case CURLOPT_FTP_USE_EPSV: {
    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, CURLOPT_FTP_USE_EPSV, NUM2LONG(value));
    } break;
#endif
#ifdef HAVE_CURLOPT_FTP_USE_EPRT
  case CURLOPT_FTP_USE_EPRT: {
    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, CURLOPT_FTP_USE_EPRT, NUM2LONG(value));
    } break;
#endif
#ifdef HAVE_CURLOPT_FTP_SKIP_PASV_IP
  case CURLOPT_FTP_SKIP_PASV_IP: {
    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, CURLOPT_FTP_SKIP_PASV_IP, NUM2LONG(value));
    } break;
#endif
  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;
#ifdef HAVE_CURLOPT_GSSAPI_DELEGATION
  case CURLOPT_GSSAPI_DELEGATION: {
    curl_easy_setopt(rbce->curl, CURLOPT_GSSAPI_DELEGATION, NUM2LONG(val));
    } break;
#endif
#ifdef HAVE_CURLOPT_UNIX_SOCKET_PATH
  case CURLOPT_UNIX_SOCKET_PATH: {
        curl_easy_setopt(rbce->curl, CURLOPT_UNIX_SOCKET_PATH, StringValueCStr(val));
    } break;
#endif
#ifdef 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
#ifdef 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
#ifdef HAVE_CURLOPT_MAXFILESIZE
  case CURLOPT_MAXFILESIZE:
    curl_easy_setopt(rbce->curl, CURLOPT_MAXFILESIZE, NUM2LONG(val));
    break;
#endif
#ifdef 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
#ifdef 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));
    /* Retain a Ruby reference to the IO to prevent GC/finalization
     * while libcurl still holds and writes to the underlying FILE*. */
    rb_easy_set("stderr_io", val);
    break;
  case CURLOPT_PROTOCOLS:
  case CURLOPT_REDIR_PROTOCOLS:
    curl_easy_setopt(rbce->curl, option, NUM2LONG(val));
    break;
#ifdef HAVE_CURLOPT_SSL_SESSIONID_CACHE
  case CURLOPT_SSL_SESSIONID_CACHE:
    curl_easy_setopt(rbce->curl, CURLOPT_SSL_SESSIONID_CACHE, NUM2LONG(val));
    break;
#endif
#ifdef HAVE_CURLOPT_COOKIELIST
  case CURLOPT_COOKIELIST: {
        /* Forward to libcurl */
        curl_easy_setopt(rbce->curl, CURLOPT_COOKIELIST, StringValueCStr(val));
        /* Track whether the cookie engine should be enabled for requests.
         * According to libcurl docs, CURLOPT_COOKIELIST also enables the cookie engine
         * when provided with a non-command string. Some environments may still require
         * an explicit "enable" via CURLOPT_COOKIEFILE="" to send cookies on requests.
         * We do that in the perform setup when this flag is set.
         */
        if (RB_TYPE_P(val, T_STRING)) {
          const char *s = StringValueCStr(val);
          if (!(strcmp(s, "ALL") == 0 || strcmp(s, "SESS") == 0 || strcmp(s, "FLUSH") == 0 || strcmp(s, "RELOAD") == 0)) {
            rbce->cookielist_engine_enabled = 1;
          }
        } else {
          /* Non-string values are unexpected; be conservative and do not enable. */
        }
  } break;
#endif
#ifdef HAVE_CURLOPT_PROXY_SSL_VERIFYHOST
  case CURLOPT_PROXY_SSL_VERIFYHOST:
    curl_easy_setopt(rbce->curl, CURLOPT_PROXY_SSL_VERIFYHOST, NUM2LONG(val));
    break;
#endif
#ifdef HAVE_CURLOPT_RESOLVE
  case CURLOPT_RESOLVE: {
    struct curl_slist *list = NULL;
    ruby_curl_easy_clear_resolve_list(rbce);
    if (NIL_P(val)) {
      /* When nil is passed, we clear any previous resolve list */
      list = NULL;
    } else if (TYPE(val) == T_ARRAY) {
      long i, len = RARRAY_LEN(val);
      for (i = 0; i < len; i++) {
        VALUE item = rb_ary_entry(val, i);
        struct curl_slist *new_list = curl_slist_append(list, StringValueCStr(item));
        if (!new_list) {
          curl_slist_free_all(list);
          rb_raise(rb_eNoMemError, "Failed to append to resolve list");
        }
        list = new_list;
      }
    } else {
      /* If a single string is passed, use it directly */
      list = curl_slist_append(NULL, StringValueCStr(val));
      if (!list) {
        rb_raise(rb_eNoMemError, "Failed to create resolve list");
      }
    }
    /* Save the list pointer in the ruby_curl_easy structure for cleanup later */
    rbce->curl_resolve = list;
    curl_easy_setopt(rbce->curl, CURLOPT_RESOLVE, list);
  } break;
#endif
  default:
    rb_raise(rb_eTypeError, "Curb unsupported option");
  }

  return val;
}
ssl_verify_host → number click to toggle source

Determine whether this Curl instance will verify that the server cert is for the server it is known as.

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) click to toggle source
# File lib/curl/easy.rb, line 318
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 click to toggle source

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.

# File lib/curl/easy.rb, line 334
def ssl_verify_host?
  ssl_verify_host.nil? ? false : (ssl_verify_host > 0)
end
ssl_verify_host = [0, 1, 2] → [0, 1, 2] click to toggle source

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? .

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 click to toggle source

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.

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 click to toggle source

Determine whether this Curl instance will verify the SSL peer certificate.

static VALUE ruby_curl_easy_ssl_verify_peer_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, ssl_verify_peer);
}
ssl_verify_result → integer click to toggle source

Retrieve the result of the certification verification that was requested (by setting ssl_verify_peer? to true).

static VALUE ruby_curl_easy_ssl_verify_result_get(VALUE self) {
  ruby_curl_easy *rbce;
  long result;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_SSL_VERIFYRESULT, &result);

  return LONG2NUM(result);
}
ssl_version → fixnum click to toggle source

Get the version of SSL/TLS that libcurl will attempt to use.

static VALUE ruby_curl_easy_ssl_version_get(VALUE self) {
  CURB_IMMED_GETTER(ruby_curl_easy, ssl_version, -1);
}
ssl_version = value → fixnum or nil click to toggle source

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
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 click to toggle source

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.

static VALUE ruby_curl_easy_start_transfer_time_get(VALUE self) {
  ruby_curl_easy *rbce;
  double time;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_STARTTRANSFER_TIME, &time);

  return rb_float_new(time);
}
status → String click to toggle source
# File lib/curl/easy.rb, line 121
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 :symbol → Fixnum click to toggle source

translates ruby symbols to libcurl options

# File lib/curl/easy.rb, line 153
def sym2curl(opt)
  Curl.const_get("CURLOPT_#{opt.to_s.upcase}")
end
timeout → numeric click to toggle source

Obtain the maximum time in seconds that you allow the libcurl transfer operation to take.

Uses timeout_ms internally instead of timeout.

static VALUE ruby_curl_easy_timeout_get(VALUE self) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  return DBL2NUM(rbce->timeout_ms / 1000.0);
}
timeout = float, fixnum or nil → numeric click to toggle source

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.

static VALUE ruby_curl_easy_timeout_set(VALUE self, VALUE timeout_s) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 or nil click to toggle source

Obtain the maximum time in milliseconds that you allow the libcurl transfer operation to take.

static VALUE ruby_curl_easy_timeout_ms_get(VALUE self) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  return LONG2NUM(rbce->timeout_ms);
}
timeout_ms = fixnum or nil → fixnum or nil click to toggle source

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).

static VALUE ruby_curl_easy_timeout_ms_set(VALUE self, VALUE timeout_ms) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 click to toggle source

Retrieve the total time in seconds for the previous transfer, including name resolving, TCP connect etc.

static VALUE ruby_curl_easy_total_time_get(VALUE self) {
  ruby_curl_easy *rbce;
  double time;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_TOTAL_TIME, &time);

  return rb_float_new(time);
}
unescape("some%20text") → "some text" click to toggle source

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.

static VALUE ruby_curl_easy_unescape(VALUE self, VALUE str) {
  ruby_curl_easy *rbce;
  int rlen;
  char *result;
  VALUE rresult;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, 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 click to toggle source

Configure whether this Curl instance may use any HTTP authentication method available when necessary.

static VALUE ruby_curl_easy_unrestricted_auth_set(VALUE self, VALUE unrestricted_auth) {
  CURB_BOOLEAN_SETTER(ruby_curl_easy, unrestricted_auth);
}
unrestricted_auth? → boolean click to toggle source

Determine whether this Curl instance may use any HTTP authentication method available when necessary.

static VALUE ruby_curl_easy_unrestricted_auth_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, unrestricted_auth);
}
upload_speed → float click to toggle source

Retrieve the average upload speed that curl measured for the preceeding complete upload.

static VALUE ruby_curl_easy_upload_speed_get(VALUE self) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);

#ifdef HAVE_CURLINFO_SPEED_UPLOAD_T
  curl_off_t bytes;
  curl_easy_getinfo(rbce->curl, CURLINFO_SPEED_UPLOAD_T, &bytes);
  return LL2NUM(bytes);
#else
  double bytes;
  curl_easy_getinfo(rbce->curl, CURLINFO_SPEED_UPLOAD, &bytes);
  return rb_float_new(bytes);
#endif
}
uploaded_bytes → float click to toggle source

Retrieve the total amount of bytes that were uploaded in the preceeding transfer.

static VALUE ruby_curl_easy_uploaded_bytes_get(VALUE self) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);

#ifdef HAVE_CURLINFO_SIZE_UPLOAD_T
  curl_off_t bytes;
  curl_easy_getinfo(rbce->curl, CURLINFO_SIZE_UPLOAD_T, &bytes);
  return LL2NUM(bytes);
#else
  double bytes;
  curl_easy_getinfo(rbce->curl, CURLINFO_SIZE_UPLOAD, &bytes);
  return rb_float_new(bytes);
#endif
}
uploaded_content_length → float click to toggle source

Retrieve the content-length of the upload.

static VALUE ruby_curl_easy_uploaded_content_length_get(VALUE self) {
  ruby_curl_easy *rbce;
  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);

#ifdef HAVE_CURLINFO_CONTENT_LENGTH_UPLOAD_T
  curl_off_t bytes;
  curl_easy_getinfo(rbce->curl, CURLINFO_CONTENT_LENGTH_UPLOAD_T, &bytes);
  return LL2NUM(bytes);
#else
  double bytes;
  curl_easy_getinfo(rbce->curl, CURLINFO_CONTENT_LENGTH_UPLOAD, &bytes);
  return rb_float_new(bytes);
#endif
}
url → string click to toggle source

Obtain the URL that will be used by subsequent calls to perform.

static VALUE ruby_curl_easy_url_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, url);
}
url = "http://some.url/" → "http://some.url/" click to toggle source

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.

# File lib/curl/easy.rb, line 269
def url=(u)
  set :url, u
end
use_netrc = boolean → boolean click to toggle source

Configure whether this Curl instance will use data from the user’s .netrc file for FTP connections.

static VALUE ruby_curl_easy_use_netrc_set(VALUE self, VALUE use_netrc) {
  CURB_BOOLEAN_SETTER(ruby_curl_easy, use_netrc);
}
use_netrc? → boolean click to toggle source

Determine whether this Curl instance will use data from the user’s .netrc file for FTP connections.

static VALUE ruby_curl_easy_use_netrc_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, use_netrc);
}
use_ssl → fixnum click to toggle source

Get the desired level for using SSL on FTP connections.

static VALUE ruby_curl_easy_use_ssl_get(VALUE self) {
  CURB_IMMED_GETTER(ruby_curl_easy, use_ssl, -1);
}
use_ssl = value → fixnum or nil click to toggle source

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.

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" click to toggle source

Obtain the user agent string used for this Curl::Easy instance

static VALUE ruby_curl_easy_useragent_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, useragent);
}
useragent = "Ruby/Curb" → "" click to toggle source

Set the user agent string for this Curl::Easy instance

static VALUE ruby_curl_easy_useragent_set(VALUE self, VALUE useragent) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, useragent);
}
username → string click to toggle source

Get the current username

static VALUE ruby_curl_easy_username_get(VALUE self) {
#ifdef HAVE_CURLOPT_USERNAME
  CURB_OBJECT_HGETTER(ruby_curl_easy, username);
#else
  return Qnil;
#endif
}
username = string → string click to toggle source

Set the HTTP Authentication username.

static VALUE ruby_curl_easy_username_set(VALUE self, VALUE username) {
#ifdef HAVE_CURLOPT_USERNAME
  CURB_OBJECT_HSETTER(ruby_curl_easy, username);
#else
  return Qnil;
#endif
}
userpwd → string click to toggle source

Obtain the username/password string that will be used for subsequent calls to perform.

static VALUE ruby_curl_easy_userpwd_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, userpwd);
}
userpwd = string → string click to toggle source

Set the username/password string to use for subsequent calls to perform. The supplied string should have the form “username:password”

# File lib/curl/easy.rb, line 356
def userpwd=(value)
  set :userpwd, value
end
verbose = boolean → boolean click to toggle source

Configure whether this Curl instance gives verbose output to STDERR during transfers. Ignored if this instance has an on_debug handler.

static VALUE ruby_curl_easy_verbose_set(VALUE self, VALUE verbose) {
  CURB_BOOLEAN_SETTER(ruby_curl_easy, verbose);
}
verbose? → boolean click to toggle source

Determine whether this Curl instance gives verbose output to STDERR during transfers.

static VALUE ruby_curl_easy_verbose_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, verbose);
}
version() click to toggle source
# File lib/curl/easy.rb, line 257
def version
  http_version
end
version=(http_version) click to toggle source

easy = Curl::Easy.new(“url”) easy.version = Curl::HTTP_2_0 easy.http_version = Curl::HTTP_1_1 easy.http_version = Curl::HTTP_1_0 easy.http_version = Curl::HTTP_NONE

# File lib/curl/easy.rb, line 253
def version=(http_version)
  self.http_version = http_version
end

Private Instance Methods

_take_callback_error() click to toggle source
static VALUE ruby_curl_easy_take_callback_error(VALUE self) {
  ruby_curl_easy *rbce = NULL;

  TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
  return rb_curl_easy_take_callback_error(rbce);
}