Class: Curl::Easy

Inherits:
Object show all
Defined in:
lib/rhack/curl/easy.rb,
ext/curb/curb_easy.c,
ext/curb-original/curb_easy.c

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#baseObject

Returns the value of attribute base.



6
7
8
# File 'lib/rhack/curl/easy.rb', line 6

def base
  @base
end

Class Method Details

.Curl::Easy.error(code) ⇒ String

translate an internal libcurl error to ruby error class

Returns:



3256
3257
3258
# File 'ext/curb/curb_easy.c', line 3256

static VALUE ruby_curl_easy_error_message(VALUE klass, VALUE code) {
  return rb_curl_easy_error(FIX2INT(code));
}

.Curl::Easy.new#<Curl::Easy...> .Curl::Easy.new(url = nil) ⇒ #<Curl::Easy...> .Curl::Easy.new(url = nil) {|self| ... } ⇒ #<Curl::Easy...>

Create a new Curl::Easy instance, optionally supplying the URL. The block form allows further configuration to be supplied before the instance is returned.

Overloads:



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'ext/curb/curb_easy.c', line 284

static VALUE ruby_curl_easy_new(int argc, VALUE *argv, VALUE klass) {
  CURLcode ecode;
  VALUE url, blk;
  VALUE new_curl;
  ruby_curl_easy *rbce;

  rb_scan_args(argc, argv, "01&", &url, &blk);

  rbce = ALLOC(ruby_curl_easy);

  /* handler */
  rbce->curl = curl_easy_init();
  if (!rbce->curl) {
    rb_raise(eCurlErrFailedInit, "Failed to initialize easy handle");
  }

  new_curl = Data_Wrap_Struct(klass, curl_easy_mark, curl_easy_free, rbce);

  rbce->multi = Qnil;
  rbce->opts  = Qnil;

  ruby_curl_easy_zero(rbce);

  rb_easy_set("url", url);

  /* set the new_curl pointer to the curl handle */
  ecode = curl_easy_setopt(rbce->curl, CURLOPT_PRIVATE, (void*)new_curl);
  if (ecode != CURLE_OK) {
    raise_curl_easy_error_exception(ecode);
  }

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

  return new_curl;
}

Instance Method Details

#autoreferer=(autoreferer) ⇒ Object

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



1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
# File 'ext/curb/curb_easy.c', line 1536

static VALUE ruby_curl_easy_autoreferer_set(VALUE self, VALUE autoreferer) {
  ruby_curl_easy *rbce;
  Data_Get_Struct(self, ruby_curl_easy, rbce);

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

  return autoreferer;
}

#body_strObject

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.



2423
2424
2425
# File 'ext/curb/curb_easy.c', line 2423

static VALUE ruby_curl_easy_body_str_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, body_data);
}

#cacertString

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

Returns:



615
616
617
# File 'ext/curb/curb_easy.c', line 615

static VALUE ruby_curl_easy_cacert_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, cacert);
}

#cacert=(string) ⇒ Object

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



605
606
607
# File 'ext/curb/curb_easy.c', line 605

static VALUE ruby_curl_easy_cacert_set(VALUE self, VALUE cacert) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, cacert);
}

#certString

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

Returns:



571
572
573
# File 'ext/curb/curb_easy.c', line 571

static VALUE ruby_curl_easy_cert_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, cert);
}

#cert=(string) ⇒ Object

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



561
562
563
# File 'ext/curb/curb_easy.c', line 561

static VALUE ruby_curl_easy_cert_set(VALUE self, VALUE cert) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, cert);
}

#cert_keyObject

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



593
594
595
# File 'ext/curb/curb_easy.c', line 593

static VALUE ruby_curl_easy_cert_key_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, cert_key);
}

#cert_key=(cert_key) ⇒ Object

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



583
584
585
# File 'ext/curb/curb_easy.c', line 583

static VALUE ruby_curl_easy_cert_key_set(VALUE self, VALUE cert_key) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, cert_key);
}

#certpassword=(string) ⇒ Object

Set a password used to open the specified cert



625
626
627
# File 'ext/curb/curb_easy.c', line 625

static VALUE ruby_curl_easy_certpassword_set(VALUE self, VALUE certpassword) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, certpassword);
}

#certtypeString

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

Returns:



647
648
649
# File 'ext/curb/curb_easy.c', line 647

static VALUE ruby_curl_easy_certtype_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, certtype);
}

#certtype=(certtype) ⇒ Object

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



637
638
639
# File 'ext/curb/curb_easy.c', line 637

static VALUE ruby_curl_easy_certtype_set(VALUE self, VALUE certtype) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, certtype);
}

#cloneObject #dupObject Also known as: dup

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



330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'ext/curb/curb_easy.c', line 330

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);

  newrbce = ALLOC(ruby_curl_easy);
  memcpy(newrbce, rbce, sizeof(ruby_curl_easy));
  newrbce->curl = curl_easy_duphandle(rbce->curl);
  newrbce->curl_headers = NULL;
  newrbce->curl_ftp_commands = NULL;

  return Data_Wrap_Struct(cCurlEasy, curl_easy_mark, curl_easy_free, newrbce);
}

#closenil

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.

Returns:

  • (nil)


352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'ext/curb/curb_easy.c', line 352

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);

  if (rbce->callback_active) {
    rb_raise(rb_eRuntimeError, "Cannot close an active curl handle within a callback");
  }

  ruby_curl_easy_free(rbce);

  /* reinit the handle */
  rbce->curl = curl_easy_init();
  if (!rbce->curl) {
    rb_raise(eCurlErrFailedInit, "Failed to initialize easy handle");
  }

  rbce->multi = Qnil;

  ruby_curl_easy_zero(rbce);

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

  return Qnil;
}

#connect_timeFloat

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

Returns:

  • (Float)


2601
2602
2603
2604
2605
2606
2607
2608
2609
# File 'ext/curb/curb_easy.c', line 2601

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

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

  return rb_float_new(time);
}

#connect_timeoutFixnum?

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

Returns:

  • (Fixnum, nil)


1165
1166
1167
# File 'ext/curb/curb_easy.c', line 1165

static VALUE ruby_curl_easy_connect_timeout_get(VALUE self, VALUE connect_timeout) {
  CURB_IMMED_GETTER(ruby_curl_easy, connect_timeout, 0);
}

#connect_timeout=(fixnum) ⇒ Fixnum?

Set the maximum time in seconds that you allow the connection to the server to take. This only limits the connection phase, once it has connected, this option is of no more use.

Set to nil (or zero) to disable connection timeout (it will then only timeout on the system’s internal timeouts).

Returns:

  • (Fixnum, nil)


1154
1155
1156
# File 'ext/curb/curb_easy.c', line 1154

static VALUE ruby_curl_easy_connect_timeout_set(VALUE self, VALUE connect_timeout) {
  CURB_IMMED_SETTER(ruby_curl_easy, connect_timeout, 0);
}

#content_typenil

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.

Returns:

  • (nil)


2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
# File 'ext/curb/curb_easy.c', line 2898

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_CONTENT_TYPE, &type);

  if (type && type[0]) {    // curl returns empty string if none
    return rb_str_new2(type);
  } else {
    return Qnil;
  }
}

#cookiefileString

Obtain the cookiefile file for this Curl::Easy instance.

Returns:



539
540
541
# File 'ext/curb/curb_easy.c', line 539

static VALUE ruby_curl_easy_cookiefile_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, cookiefile);
}

#cookiejarString

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

Returns:



549
550
551
# File 'ext/curb/curb_easy.c', line 549

static VALUE ruby_curl_easy_cookiejar_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, cookiejar);
}

#cookiesObject

Obtain the cookies for this Curl::Easy instance.



529
530
531
# File 'ext/curb/curb_easy.c', line 529

static VALUE ruby_curl_easy_cookies_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, cookies);
}

#delete=(onoff) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/rhack/curl/easy.rb', line 101

def delete=(onoff)
  if onoff
    set :nobody, false
    set :httpget, false
    set :customrequest, 'DELETE'
  else
    set :customrequest, nil
  end
end

#dns_cache_timeoutFixnum?

Obtain the dns cache timeout in seconds.

Returns:

  • (Fixnum, nil)


1188
1189
1190
# File 'ext/curb/curb_easy.c', line 1188

static VALUE ruby_curl_easy_dns_cache_timeout_get(VALUE self, VALUE dns_cache_timeout) {
  CURB_IMMED_GETTER(ruby_curl_easy, dns_cache_timeout, -1);
}

#dns_cache_timeout=(fixnum) ⇒ Fixnum?

Set the dns cache timeout in seconds. Name resolves will be kept in memory for this number of seconds. Set to zero (0) to completely disable caching, or set to nil (or -1) to make the cached entries remain forever. By default, libcurl caches this info for 60 seconds.

Returns:

  • (Fixnum, nil)


1178
1179
1180
# File 'ext/curb/curb_easy.c', line 1178

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_speedFloat

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

Returns:

  • (Float)


2786
2787
2788
2789
2790
2791
2792
2793
2794
# File 'ext/curb/curb_easy.c', line 2786

static VALUE ruby_curl_easy_download_speed_get(VALUE self) {
  ruby_curl_easy *rbce;
  double bytes;

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_SPEED_DOWNLOAD, &bytes);

  return rb_float_new(bytes);
}

#downloaded_bytesFloat

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

Returns:

  • (Float)


2752
2753
2754
2755
2756
2757
2758
2759
2760
# File 'ext/curb/curb_easy.c', line 2752

static VALUE ruby_curl_easy_downloaded_bytes_get(VALUE self) {
  ruby_curl_easy *rbce;
  double bytes;

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_SIZE_DOWNLOAD, &bytes);

  return rb_float_new(bytes);
}

#downloaded_content_lengthFloat

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

Returns:

  • (Float)


2863
2864
2865
2866
2867
2868
2869
2870
2871
# File 'ext/curb/curb_easy.c', line 2863

static VALUE ruby_curl_easy_downloaded_content_length_get(VALUE self) {
  ruby_curl_easy *rbce;
  double bytes;

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &bytes);

  return rb_float_new(bytes);
}

#enable_cookies=(boolean) ⇒ Boolean

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

Returns:

  • (Boolean)


1641
1642
1643
1644
# File 'ext/curb/curb_easy.c', line 1641

static VALUE ruby_curl_easy_enable_cookies_set(VALUE self, VALUE enable_cookies)
{
  CURB_BOOLEAN_SETTER(ruby_curl_easy, enable_cookies);
}

#enable_cookies?Boolean

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

Returns:

  • (Boolean)


1653
1654
1655
# File 'ext/curb/curb_easy.c', line 1653

static VALUE ruby_curl_easy_enable_cookies_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, enable_cookies);
}

#encodingString

Get the set encoding types

Returns:



668
669
670
# File 'ext/curb/curb_easy.c', line 668

static VALUE ruby_curl_easy_encoding_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, encoding);
}

#encoding=(string) ⇒ String

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

Returns:



658
659
660
# File 'ext/curb/curb_easy.c', line 658

static VALUE ruby_curl_easy_encoding_set(VALUE self, VALUE encoding) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, encoding);
}

#escape("some text") ⇒ Object

Convert the given input string to a URL encoded string and return the result. All input characters that are not a-z, A-Z or 0-9 are converted to their “URL escaped” version (%NN where NN is a two-digit hexadecimal number).



3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
# File 'ext/curb/curb_easy.c', line 3195

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);

  /* NOTE: make sure the value is a string, if not call to_s */
  if( rb_type(str) != T_STRING ) { str = rb_funcall(str,rb_intern("to_s"),0); }

#if (LIBCURL_VERSION_NUM >= 0x070f04)
  result = (char*)curl_easy_escape(rbce->curl, StringValuePtr(str), (int)RSTRING_LEN(str));
#else
  result = (char*)curl_escape(StringValuePtr(str), (int)RSTRING_LEN(str));
#endif

  rresult = rb_str_new2(result);
  curl_free(result);

  return rresult;
}

#fetch_file_time=(boolean) ⇒ Boolean

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

Returns:

  • (Boolean)


1413
1414
1415
# File 'ext/curb/curb_easy.c', line 1413

static VALUE ruby_curl_easy_fetch_file_time_set(VALUE self, VALUE fetch_file_time) {
  CURB_BOOLEAN_SETTER(ruby_curl_easy, fetch_file_time);
}

#fetch_file_time?Boolean

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

Returns:

  • (Boolean)


1424
1425
1426
# File 'ext/curb/curb_easy.c', line 1424

static VALUE ruby_curl_easy_fetch_file_time_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, fetch_file_time);
}

#file_timeFixnum

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.

Returns:

  • (Fixnum)


2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
# File 'ext/curb/curb_easy.c', line 2545

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_FILETIME, &time);

  return LONG2NUM(time);
#else
  rb_warn("Installed libcurl is too old to support file_time");
  return INT2FIX(0);
#endif
}

#follow_location=(onoff) ⇒ Object



77
78
79
# File 'lib/rhack/curl/easy.rb', line 77

def follow_location=(onoff)
  set :followlocation, onoff
end

#follow_location?Boolean

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

Returns:

  • (Boolean)


1557
1558
1559
# File 'ext/curb/curb_easy.c', line 1557

static VALUE ruby_curl_easy_follow_location_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, follow_location);
}

#ftp_commandsObject

call-seq

easy.ftp_commands                                => array or nil


891
892
893
# File 'ext/curb/curb_easy.c', line 891

static VALUE ruby_curl_easy_ftp_commands_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, ftp_commands);
}

#ftp_commands=(ftp_commands) ⇒ Object

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



883
884
885
# File 'ext/curb/curb_easy.c', line 883

static VALUE ruby_curl_easy_ftp_commands_set(VALUE self, VALUE ftp_commands) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, ftp_commands);
}

#ftp_entry_pathnil

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

Returns:

  • (nil)


3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
# File 'ext/curb/curb_easy.c', line 3010

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_FTP_ENTRY_PATH, &path);

  if (path && path[0]) {    // curl returns NULL or empty string if none
    return rb_str_new2(path);
  } else {
    return Qnil;
  }
#else
  rb_warn("Installed libcurl is too old to support num_connects");
  return Qnil;
#endif
}

#ftp_filemethod(ftp_filemethod) ⇒ Object

call-seq

easy.ftp_filemethod                              => fixnum

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



1380
1381
1382
# File 'ext/curb/curb_easy.c', line 1380

static VALUE ruby_curl_easy_ftp_filemethod_get(VALUE self, VALUE ftp_filemethod) {
  CURB_IMMED_GETTER(ruby_curl_easy, ftp_filemethod, -1);
}

#ftp_filemethod=(value) ⇒ Fixnum?

Controls how libcurl reaches files on the server. Valid options are Curl::CURL_MULTICWD, Curl::CURL_NOCWD, and Curl::CURL_SINGLECWD (see libcurl docs for CURLOPT_FTP_METHOD).

Returns:

  • (Fixnum, nil)


1370
1371
1372
# File 'ext/curb/curb_easy.c', line 1370

static VALUE ruby_curl_easy_ftp_filemethod_set(VALUE self, VALUE ftp_filemethod) {
  CURB_IMMED_SETTER(ruby_curl_easy, ftp_filemethod, -1);
}

#ftp_response_timeoutFixnum?

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

Returns:

  • (Fixnum, nil)


1215
1216
1217
# File 'ext/curb/curb_easy.c', line 1215

static VALUE ruby_curl_easy_ftp_response_timeout_get(VALUE self, VALUE ftp_response_timeout) {
  CURB_IMMED_GETTER(ruby_curl_easy, ftp_response_timeout, 0);
}

#ftp_response_timeout=(fixnum) ⇒ Fixnum?

Set a timeout period (in seconds) on the amount of time that the server is allowed to take in order to generate a response message for a command before the session is considered hung. While curl is waiting for a response, this value overrides timeout. It is recommended that if used in conjunction with timeout, you set ftp_response_timeout to a value smaller than timeout.

Ignored if libcurl version is < 7.10.8.

Returns:

  • (Fixnum, nil)


1205
1206
1207
# File 'ext/curb/curb_easy.c', line 1205

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=(onoff) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/rhack/curl/easy.rb', line 91

def get=(onoff)
  if onoff
    set :nobody, false
    set :customrequest, nil
    set :httpget, true
  else
    set :httpget, false
  end
end

#FixnumObject

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



3158
3159
3160
# File 'ext/curb/curb_easy.c', line 3158

static VALUE ruby_curl_easy_get_opt(VALUE self, VALUE opt) {
  return Qnil;
}

#head=(onoff) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/rhack/curl/easy.rb', line 81

def head=(onoff)
  if onoff
    set :httpget, false
    set :customrequest, nil
    set :nobody, true
  else
    set :nobody, false
  end
end

#header_in_body=(boolean) ⇒ Boolean

Configure whether this Curl instance will return HTTP headers combined with body data. If this option is set true, both header and body data will go to body_str (or the configured on_body handler).

Returns:

  • (Boolean)


1493
1494
1495
# File 'ext/curb/curb_easy.c', line 1493

static VALUE ruby_curl_easy_header_in_body_set(VALUE self, VALUE header_in_body) {
  CURB_BOOLEAN_SETTER(ruby_curl_easy, header_in_body);
}

#header_in_body?Boolean

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

Returns:

  • (Boolean)


1504
1505
1506
# File 'ext/curb/curb_easy.c', line 1504

static VALUE ruby_curl_easy_header_in_body_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, header_in_body);
}

#header_sizeFixnum

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

Returns:

  • (Fixnum)


2803
2804
2805
2806
2807
2808
2809
2810
2811
# File 'ext/curb/curb_easy.c', line 2803

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

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

  return LONG2NUM(size);
}

#header_strObject

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.



2435
2436
2437
# File 'ext/curb/curb_easy.c', line 2435

static VALUE ruby_curl_easy_header_str_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, header_data);
}

#headersHash, ...

Obtain the custom HTTP headers for following requests.

Returns:



480
481
482
483
484
485
486
487
# File 'ext/curb/curb_easy.c', line 480

static VALUE ruby_curl_easy_headers_get(VALUE self) {
  ruby_curl_easy *rbce;
  VALUE headers;
  Data_Get_Struct(self, ruby_curl_easy, rbce);
  headers = rb_easy_get("headers");//rb_hash_aref(rbce->opts, rb_intern("headers")); 
  if (headers == Qnil) { headers = rb_easy_set("headers", rb_hash_new()); }
  return headers;
}

#headers=(headers) ⇒ Object

easy.headers = => “val” …, “Header” => “val” => val”, …

easy.headers = ["Header: val" ..., "Header: val"]         => ["Header: val", ...]

Set custom HTTP headers for following requests. This can be used to add custom headers, or override standard headers used by libcurl. It defaults to a Hash.

For example to set a standard or custom header:

easy.headers["MyHeader"] = "myval"

To remove a standard header (this is useful when removing libcurls default ‘Expect: 100-Continue’ header when using HTTP form posts):

easy.headers["Expect"] = ''

Anything passed to libcurl as a header will be converted to a string during the perform step.



470
471
472
# File 'ext/curb/curb_easy.c', line 470

static VALUE ruby_curl_easy_headers_set(VALUE self, VALUE headers) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, headers);
}

#hostObject



27
28
29
# File 'lib/rhack/curl/easy.rb', line 27

def host
  url.parse(:uri).root
end

#http(verb) ⇒ Object

Send an HTTP request with method set to verb, using the current options set for this Curl::Easy instance. This method always returns true or raises an exception (defined under Curl::Err) on error.



2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
# File 'ext/curb/curb_easy.c', line 2307

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

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

Returns:

  • (Fixnum, nil)


1063
1064
1065
# File 'ext/curb/curb_easy.c', line 1063

static VALUE ruby_curl_easy_http_auth_types_get(VALUE self) {
  CURB_IMMED_GETTER(ruby_curl_easy, http_auth_types, 0);
}

#http_auth_types=(*args) ⇒ Object

VALUE self, VALUE http_auth_types) {



1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
# File 'ext/curb/curb_easy.c', line 1023

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;
  int i, len;
  char* node = NULL;
  long mask = 0x000000;

  rb_scan_args(argc, argv, "*", &args_ary);
  Data_Get_Struct(self, ruby_curl_easy, rbce);

  len = (int)RARRAY_LEN(args_ary);

  if (len == 1 && (TYPE(rb_ary_entry(args_ary,0)) == T_FIXNUM || rb_ary_entry(args_ary,0) == Qnil)) {
    if (rb_ary_entry(args_ary,0) == Qnil) { 
      rbce->http_auth_types = 0;
    }
    else {
      rbce->http_auth_types = NUM2INT(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 INT2NUM(rbce->http_auth_types);
}

#http_connect_codeFixnum

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

Returns:

  • (Fixnum)


2518
2519
2520
2521
2522
2523
2524
2525
2526
# File 'ext/curb/curb_easy.c', line 2518

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

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

  return LONG2NUM(code);
}

#http_post("url = encoded%20form%20data;and=so%20on") ⇒ true #http_post("url = encoded%20form%20data", "and = so%20on", ...) ⇒ true #http_post("url = encoded%20form%20data", Curl: :PostField, "and = so%20on", ...) ⇒ true #http_post(Curl: :PostField, Curl: :PostField..., Curl: :PostField) ⇒ true

POST the specified formdata to the currently configured URL using the current options set for this Curl::Easy instance. This method always returns true, or raises an exception (defined under Curl::Err) on error.

The Content-type of the POST is determined by the current setting of multipart_form_post? , according to the following rules:

  • When false (the default): the form will be POSTed with a content-type of ‘application/x-www-form-urlencoded’, and any of the four calling forms may be used.

  • When true: the form will be POSTed with a content-type of ‘multipart/formdata’. Only the last calling form may be used, i.e. only PostField instances may be POSTed. In this mode, individual fields’ content-types are recognised, and file upload fields are supported.

Overloads:

  • #http_post("url = encoded%20form%20data;and=so%20on") ⇒ true

    Returns:

    • (true)
  • #http_post("url = encoded%20form%20data", "and = so%20on", ...) ⇒ true

    Returns:

    • (true)
  • #http_post("url = encoded%20form%20data", Curl: :PostField, "and = so%20on", ...) ⇒ true

    Returns:

    • (true)
  • #http_post(Curl: :PostField, Curl: :PostField..., Curl: :PostField) ⇒ true

    Returns:

    • (true)


2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
# File 'ext/curb/curb_easy.c', line 2345

static VALUE ruby_curl_easy_perform_post(int argc, VALUE *argv, VALUE self) {
  ruby_curl_easy *rbce;
  CURL *curl;
  VALUE args_ary;
  VALUE post_body = Qnil;
  rb_scan_args(argc, argv, "*", &args_ary);

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl = rbce->curl;

  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, NULL);

  if (rbce->multipart_form_post) {
    VALUE ret;
    if ((post_body = rb_funcall(args_ary, idFlatten, 0)) == Qnil) {
      rb_raise(eCurlErrError, "Failed to flatten arguments");
      return Qnil;
    } else {
      ruby_curl_easy_multipart_post_body_set(self, post_body);
      ret = rb_funcall(self, rb_intern("perform"), 0);
      curl_formfree(rbce->first);

      return ret;
    }
  } else {
    /* TODO: check for PostField.file and raise error before to_s fails */
    if ((post_body = rb_funcall(args_ary, idJoin, 1, rbstrAmp)) == Qnil) {
      rb_raise(eCurlErrError, "Failed to join arguments");
      return Qnil;
    } else {
      /* if the function call above returns an empty string because no additional arguments were passed this makes sure
         a previously set easy.post_body = "arg=foo&bar=bin"  will be honored */
      if( post_body != Qnil && rb_type(post_body) == T_STRING && RSTRING_LEN(post_body) > 0 ) {
        ruby_curl_easy_post_body_set(self, post_body);
      }

      /* if post body is not defined, set it so we enable POST header, even though the request body is empty */
      if( rb_easy_nil("postdata_buffer") ) {
        ruby_curl_easy_post_body_set(self, post_body);
      }

      return rb_funcall(self, rb_intern("perform"), 0);
    }
  }
}

#http_put(data) ⇒ true

PUT the supplied data to the currently configured URL using the current options set for this Curl::Easy instance. This method always returns true, or raises an exception (defined under Curl::Err) on error.

Returns:

  • (true)


2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
# File 'ext/curb/curb_easy.c', line 2399

static VALUE ruby_curl_easy_perform_put(VALUE self, VALUE data) {
  ruby_curl_easy *rbce;
  CURL *curl;

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl = rbce->curl;

  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, NULL);
  ruby_curl_easy_put_data_set(self, data);

  return rb_funcall(self, rb_intern("perform"), 0);
}

#ignore_content_length=(boolean) ⇒ Object

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



1664
1665
1666
1667
# File 'ext/curb/curb_easy.c', line 1664

static VALUE ruby_curl_easy_ignore_content_length_set(VALUE self, VALUE ignore_content_length)
{
  CURB_BOOLEAN_SETTER(ruby_curl_easy, ignore_content_length);
}

#ignore_content_length?Boolean

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

Returns:

  • (Boolean)


1676
1677
1678
# File 'ext/curb/curb_easy.c', line 1676

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/>"

Returns:



3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
# File 'ext/curb/curb_easy.c', line 3166

static VALUE ruby_curl_easy_inspect(VALUE self) {
  char buf[64];
  ruby_curl_easy *rbce;
  Data_Get_Struct(self, ruby_curl_easy, rbce);
  /* if we don't have a url set... we'll crash... */
  if( !rb_easy_nil("url") && rb_easy_type_check("url", T_STRING)) {
    VALUE url = rb_easy_get("url");
    size_t len = 13+((RSTRING_LEN(url) > 50) ? 50 : RSTRING_LEN(url));
    /* "#<Net::HTTP http://www.google.com/:80 open=false>" */
    memcpy(buf,"#<Curl::Easy ", 13);
    memcpy(buf+13,StringValueCStr(url), (len - 13));
    buf[len++] = '>';
    return rb_str_new(buf,len);
  }
  return rb_str_new2("#<Curl::Easy>");
}

#interfaceString

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.

Returns:



496
497
498
# File 'ext/curb/curb_easy.c', line 496

static VALUE ruby_curl_easy_interface_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, interface_hm);
}

#interface=(value) ⇒ Object



53
54
55
# File 'lib/rhack/curl/easy.rb', line 53

def interface=(value)
  set :interface, value
end

#last_effective_urlnil

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.

Returns:

  • (nil)


2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
# File 'ext/curb/curb_easy.c', line 2450

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_EFFECTIVE_URL, &url);

  if (url && url[0]) {    // curl returns empty string if none
    return rb_str_new2(url);
  } else {
    return Qnil;
  }
}

#last_result0

Returns:

  • (0)


3054
3055
3056
3057
3058
# File 'ext/curb/curb_easy.c', line 3054

static VALUE ruby_curl_easy_last_result(VALUE self) {
  ruby_curl_easy *rbce;
  Data_Get_Struct(self, ruby_curl_easy, rbce);
  return INT2FIX(rbce->last_result);
}

#local_portFixnum?

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

This option is ignored if compiled against libcurl < 7.15.2.

Returns:

  • (Fixnum, nil)


920
921
922
# File 'ext/curb/curb_easy.c', line 920

static VALUE ruby_curl_easy_local_port_get(VALUE self) {
  CURB_IMMED_PORT_GETTER(ruby_curl_easy, local_port);
}

#local_port=(fixnum) ⇒ Fixnum?

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

Passing nil will return to the default behaviour (no local port preference).

This option is ignored if compiled against libcurl < 7.15.2.

Returns:

  • (Fixnum, nil)


908
909
910
# File 'ext/curb/curb_easy.c', line 908

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

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.

Returns:

  • (Fixnum, nil)


951
952
953
# File 'ext/curb/curb_easy.c', line 951

static VALUE ruby_curl_easy_local_port_range_get(VALUE self) {
  CURB_IMMED_PORT_GETTER(ruby_curl_easy, local_port_range);
}

#local_port_range=(fixnum) ⇒ Fixnum?

Set the local port range that will be used for the following perform calls. This is a number (between 0 and 65535) that determines how far libcurl may deviate from the supplied local_port in order to find an available port.

If you set local_port it’s also recommended that you set this, since it is fairly likely that your specified port will be unavailable.

This option is ignored if compiled against libcurl < 7.15.2.

Returns:

  • (Fixnum, nil)


938
939
940
# File 'ext/curb/curb_easy.c', line 938

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

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

Returns:

  • (Fixnum, nil)


1238
1239
1240
# File 'ext/curb/curb_easy.c', line 1238

static VALUE ruby_curl_easy_low_speed_limit_get(VALUE self, VALUE low_speed_limit) {
  CURB_IMMED_GETTER(ruby_curl_easy, low_speed_limit, 0);
}

#low_speed_limit=(fixnum) ⇒ Fixnum?

Set the transfer speed (in bytes per second) that the transfer should be below during low_speed_time seconds for the library to consider it too slow and abort.

Returns:

  • (Fixnum, nil)


1227
1228
1229
# File 'ext/curb/curb_easy.c', line 1227

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

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

Returns:

  • (Fixnum, nil)


1260
1261
1262
# File 'ext/curb/curb_easy.c', line 1260

static VALUE ruby_curl_easy_low_speed_time_get(VALUE self, VALUE low_speed_time) {
  CURB_IMMED_GETTER(ruby_curl_easy, low_speed_time, 0);
}

#low_speed_time=(fixnum) ⇒ Fixnum?

Set the time (in seconds) that the transfer should be below the low_speed_limit for the library to consider it too slow and abort.

Returns:

  • (Fixnum, nil)


1249
1250
1251
# File 'ext/curb/curb_easy.c', line 1249

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

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

Returns:

  • (Fixnum, nil)


1112
1113
1114
# File 'ext/curb/curb_easy.c', line 1112

static VALUE ruby_curl_easy_max_redirects_get(VALUE self) {
  CURB_IMMED_GETTER(ruby_curl_easy, max_redirs, -1);
}

#max_redirects=(fixnum) ⇒ Fixnum?

Set the maximum number of redirections to follow in the following perform calls. Set to nil or -1 allow an infinite number (the default). Setting this option only makes sense if follow_location is also set true.

With libcurl >= 7.15.1, setting this to 0 will cause libcurl to refuse any redirect.

Returns:

  • (Fixnum, nil)


1101
1102
1103
# File 'ext/curb/curb_easy.c', line 1101

static VALUE ruby_curl_easy_max_redirects_set(VALUE self, VALUE max_redirs) {
  CURB_IMMED_SETTER(ruby_curl_easy, max_redirs, -1);
}

#multi"#<Curl::Multi>"

Returns:



3033
3034
3035
3036
3037
# File 'ext/curb/curb_easy.c', line 3033

static VALUE ruby_curl_easy_multi_get(VALUE self) {
  ruby_curl_easy *rbce;
  Data_Get_Struct(self, ruby_curl_easy, rbce);
  return rbce->multi;
}

#multi="#<Curl::Multi>"

Returns:



3043
3044
3045
3046
3047
3048
# File 'ext/curb/curb_easy.c', line 3043

static VALUE ruby_curl_easy_multi_set(VALUE self, VALUE multi) {
  ruby_curl_easy *rbce;
  Data_Get_Struct(self, ruby_curl_easy, rbce);
  rbce->multi = multi;
  return rbce->multi;
}

#multipart_form_post=(boolean) ⇒ Boolean

Configure whether this Curl instance uses multipart/formdata content type for HTTP POST requests. If this is false (the default), then the application/x-www-form-urlencoded content type is used for the form data.

If this is set true, you must pass one or more PostField instances to the http_post method - no support for posting multipart forms from a string is provided.

Returns:

  • (Boolean)


1618
1619
1620
1621
# File 'ext/curb/curb_easy.c', line 1618

static VALUE ruby_curl_easy_multipart_form_post_set(VALUE self, VALUE multipart_form_post)
{
  CURB_BOOLEAN_SETTER(ruby_curl_easy, multipart_form_post);
}

#multipart_form_post?Boolean

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

Returns:

  • (Boolean)


1630
1631
1632
# File 'ext/curb/curb_easy.c', line 1630

static VALUE ruby_curl_easy_multipart_form_post_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, multipart_form_post);
}

#multipart_post_body=(ary) ⇒ Object



750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
# File 'ext/curb/curb_easy.c', line 750

static VALUE ruby_curl_easy_multipart_post_body_set(VALUE self, VALUE ary) {
  ruby_curl_easy *rbce;
  CURL *curl;
  int i;
  
  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl = rbce->curl;
  if (rbce->first != NULL) {
    curl_formfree(rbce->first);
    rbce->first = NULL;
    rbce->last = NULL;
  }
  
  // Make the multipart form
  rbce->multipart_form_post = 1;
  for (i=0; i<RARRAY_LEN(ary); i++) {
    if (rb_obj_is_instance_of(RARRAY_PTR(ary)[i], cCurlPostField)) {
      append_to_form(RARRAY_PTR(ary)[i], &(rbce->first), &(rbce->last));
    } 
    else {
      if (rbce->first != NULL) {
        curl_formfree(rbce->first);
        rbce->first = NULL;
        rbce->last = NULL;
      }
      rb_raise(eCurlErrInvalidPostField, "You must use only PostFields with multipart form posts");
      return Qnil;
    }
  }
  //rbce->postdata_buffer = ary;
  rb_easy_set("postdata_buffer", ary);

  curl_easy_setopt(curl, CURLOPT_POST, 0);
  curl_easy_setopt(curl, CURLOPT_HTTPPOST, rbce->first);
  return Qnil;
}

#name_lookup_timeFloat

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

Returns:

  • (Float)


2584
2585
2586
2587
2588
2589
2590
2591
2592
# File 'ext/curb/curb_easy.c', line 2584

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

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

  return rb_float_new(time);
}

#num_connectsInteger

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

Returns:

  • (Integer)


2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
# File 'ext/curb/curb_easy.c', line 2969

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_NUM_CONNECTS, &result);

  return LONG2NUM(result);
#else
  rb_warn("Installed libcurl is too old to support num_connects");
  return INT2FIX(-1);
#endif
}

#on_body {|body_data| ... } ⇒ Object

Assign or remove the on_body handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.

The on_body handler is called for each chunk of response body passed back by libcurl during perform. It should perform any processing necessary, and return the actual number of bytes handled. Normally, this will equal the length of the data string, and CURL will continue processing. If the returned length does not equal the input length, CURL will abort the processing with a Curl::Err::AbortedByCallbackError.

Yields:

  • (body_data)


1758
1759
1760
# File 'ext/curb/curb_easy.c', line 1758

static VALUE ruby_curl_easy_on_body_set(int argc, VALUE *argv, VALUE self) {
  CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, body_proc);
}

#on_complete {|easy| ... } ⇒ Object

Assign or remove the on_complete handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.

The on_complete handler is called when the request is finished.

Yields:

  • (easy)


1836
1837
1838
# File 'ext/curb/curb_easy.c', line 1836

static VALUE ruby_curl_easy_on_complete_set(int argc, VALUE *argv, VALUE self) {
  CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, complete_proc);
}

#on_debug {|type, data| ... } ⇒ Object

Assign or remove the on_debug handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.

The on_debug handler, if configured, will receive detailed information from libcurl during the perform call. This can be useful for debugging. Setting a debug handler overrides libcurl’s internal handler, disabling any output from verbose, if set.

The type argument will match one of the Curl::Easy::CURLINFO_XXXX constants, and specifies the kind of information contained in the data. The data is passed as a String.

Yields:

  • (type, data)


1892
1893
1894
# File 'ext/curb/curb_easy.c', line 1892

static VALUE ruby_curl_easy_on_debug_set(int argc, VALUE *argv, VALUE self) {
  CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, debug_proc);
}

#on_failure {|easy, code| ... } ⇒ Object

Assign or remove the on_failure handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.

The on_failure handler is called when the request is finished with a status of 50x

Yields:

  • (easy, code)


1784
1785
1786
# File 'ext/curb/curb_easy.c', line 1784

static VALUE ruby_curl_easy_on_failure_set(int argc, VALUE *argv, VALUE self) {
  CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, failure_proc);
}

#on_header {|header_data| ... } ⇒ Object

Assign or remove the on_header handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.

The on_header handler is called for each chunk of response header passed back by libcurl during perform. The semantics are the same as for the block supplied to on_body.

Yields:

  • (header_data)


1850
1851
1852
# File 'ext/curb/curb_easy.c', line 1850

static VALUE ruby_curl_easy_on_header_set(int argc, VALUE *argv, VALUE self) {
  CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, header_proc);
}

#on_missing {|easy, code| ... } ⇒ Object

Assign or remove the on_missing handler for this Curl::Easy instance.

To remove a previously-supplied handler, call this method with no attached
block.

The +on_missing+ handler is called when request is finished with a
status of 40x

Yields:

  • (easy, code)


1811
1812
1813
# File 'ext/curb/curb_easy.c', line 1811

static VALUE ruby_curl_easy_on_missing_set(int argc, VALUE *argv, VALUE self) {
  CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, missing_proc);
}

#on_progress {|dl_total, dl_now, ul_total, ul_now| ... } ⇒ Object

Assign or remove the on_progress handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.

The on_progress handler is called regularly by libcurl (approximately once per second) during transfers to allow the application to receive progress information. There is no guarantee that the reported progress will change between calls.

The result of the block call determines whether libcurl continues the transfer. Returning a non-true value (i.e. nil or false) will cause the transfer to abort, throwing a Curl::Err::AbortedByCallbackError.

Yields:

  • (dl_total, dl_now, ul_total, ul_now)


1871
1872
1873
# File 'ext/curb/curb_easy.c', line 1871

static VALUE ruby_curl_easy_on_progress_set(int argc, VALUE *argv, VALUE self) {
  CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, progress_proc);
}

#on_redirect {|easy, code| ... } ⇒ Object

Assign or remove the on_redirect handler for this Curl::Easy instance.

To remove a previously-supplied handler, call this method with no attached
block.

The +on_redirect+ handler is called when request is finished with a
status of 30x

Yields:

  • (easy, code)


1824
1825
1826
# File 'ext/curb/curb_easy.c', line 1824

static VALUE ruby_curl_easy_on_redirect_set(int argc, VALUE *argv, VALUE self) {
  CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, redirect_proc);
}

#on_server_error {|easy, code| ... } ⇒ Object

Assign the on_server_error handler for this Curl::Easy instance.

The on_server_error handler is called when the request is finished with a status of 50x

Yields:

  • (easy, code)


1798
1799
1800
# File 'ext/curb/curb_easy.c', line 1798

static VALUE ruby_curl_easy_on_server_error_set(int argc, VALUE *argv, VALUE self) {
  CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, server_error_proc);
}

#on_success {|easy| ... } ⇒ Object

Assign or remove the on_success handler for this Curl::Easy instance. To remove a previously-supplied handler, call this method with no attached block.

The on_success handler is called when the request is finished with a status of 20x

Yields:

  • (easy)


1771
1772
1773
# File 'ext/curb/curb_easy.c', line 1771

static VALUE ruby_curl_easy_on_success_set(int argc, VALUE *argv, VALUE self) {
  CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, success_proc);
}

#os_errnoInteger

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

Returns:

  • (Integer)


2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
# File 'ext/curb/curb_easy.c', line 2940

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_OS_ERRNO, &result);

  return LONG2NUM(result);
#else
  rb_warn("Installed libcurl is too old to support os_errno");
  return INT2FIX(0);
#endif
}

#outdate!Object



8
9
10
# File 'lib/rhack/curl/easy.rb', line 8

def outdate!
  @outdated = true
end

#passwordString

Get the current password

Returns:



1312
1313
1314
1315
1316
1317
1318
# File 'ext/curb/curb_easy.c', line 1312

static VALUE ruby_curl_easy_password_get(VALUE self, VALUE password) {
#if HAVE_CURLOPT_PASSWORD
  CURB_OBJECT_HGETTER(ruby_curl_easy, password);
#else
  return Qnil;
#endif
}

#password=(string) ⇒ String

Set the HTTP Authentication password.

Returns:



1298
1299
1300
1301
1302
1303
1304
# File 'ext/curb/curb_easy.c', line 1298

static VALUE ruby_curl_easy_password_set(VALUE self, VALUE password) {
#if HAVE_CURLOPT_PASSWORD
  CURB_OBJECT_HSETTER(ruby_curl_easy, password);
#else
  return Qnil;
#endif
}

#path=(href) ⇒ Object



31
32
33
# File 'lib/rhack/curl/easy.rb', line 31

def path=(href)
  self.url = host+href.parse(:uri).fullpath
end

#post_bodyString?

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

Returns:



793
794
795
# File 'ext/curb/curb_easy.c', line 793

static VALUE ruby_curl_easy_post_body_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, postdata_buffer);
}

#post_body=(post_body) ⇒ Object

Sets the POST body of this Curl::Easy instance. This is expected to be URL encoded; no additional processing or encoding is done on the string. The content-type header will be set to application/x-www-form-urlencoded.

This is handy if you want to perform a POST against a Curl::Multi instance.



703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
# File 'ext/curb/curb_easy.c', line 703

static VALUE ruby_curl_easy_post_body_set(VALUE self, VALUE post_body) {
  ruby_curl_easy *rbce;
  CURL *curl;
  
  char *data;
  long len;

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  
  curl = rbce->curl;
  if (rbce->first != NULL) {
    curl_formfree(rbce->first);
    rbce->first = NULL;
    rbce->last = NULL;
  }
  rbce->multipart_form_post = 0;
  if ( post_body == Qnil ) {
    //rbce->postdata_buffer = Qnil;
    rb_easy_del("postdata_buffer");    
  } else {  
    if (rb_type(post_body) == T_STRING) {
      data = StringValuePtr(post_body);
      len = RSTRING_LEN(post_body);
    }
    else if (rb_respond_to(post_body, rb_intern("to_s"))) {
      VALUE str_body = rb_funcall(post_body, rb_intern("to_s"), 0);
      data = StringValuePtr(str_body);
      len = RSTRING_LEN(post_body);
    }
    else {
      rb_raise(rb_eRuntimeError, "post data must respond_to .to_s");
    }
  
    // Store the string, since it has to hang around for the duration of the 
    // request.  See CURLOPT_POSTFIELDS in the libcurl docs.
    //rbce->postdata_buffer = post_body;
    rb_easy_set("postdata_buffer", post_body);
  
    curl_easy_setopt(curl, CURLOPT_POST, 1);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, len);
    
    return post_body;
  }
  
  return Qnil;
}

#pre_transfer_timeFloat

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.

Returns:

  • (Float)


2620
2621
2622
2623
2624
2625
2626
2627
2628
# File 'ext/curb/curb_easy.c', line 2620

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

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

  return rb_float_new(time);
}

#primary_ipnil

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

Returns:

  • (nil)


2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
# File 'ext/curb/curb_easy.c', line 2497

static VALUE ruby_curl_easy_primary_ip_get(VALUE self) {
  ruby_curl_easy *rbce;
  char* ip;
  
  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_PRIMARY_IP, &ip);

  if (ip && ip[0]) {    // curl returns empty string if none
    return rb_str_new2(ip);
  } else {
    return Qnil;
  }
}

#proxy_auth_typesFixnum?

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

Returns:

  • (Fixnum, nil)


1086
1087
1088
# File 'ext/curb/curb_easy.c', line 1086

static VALUE ruby_curl_easy_proxy_auth_types_get(VALUE self) {
  CURB_IMMED_GETTER(ruby_curl_easy, proxy_auth_types, 0);
}

#proxy_auth_types=(fixnum) ⇒ Fixnum?

Set the proxy authentication types that may be used for the following perform calls. This is a bitmap made by ORing together the Curl::CURLAUTH constants.

Returns:

  • (Fixnum, nil)


1075
1076
1077
# File 'ext/curb/curb_easy.c', line 1075

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

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

Returns:

  • (Fixnum, nil)


971
972
973
# File 'ext/curb/curb_easy.c', line 971

static VALUE ruby_curl_easy_proxy_port_get(VALUE self) {
  CURB_IMMED_PORT_GETTER(ruby_curl_easy, proxy_port);
}

#proxy_port=(fixnum) ⇒ Fixnum?

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

Returns:

  • (Fixnum, nil)


961
962
963
# File 'ext/curb/curb_easy.c', line 961

static VALUE ruby_curl_easy_proxy_port_set(VALUE self, VALUE proxy_port) {
  CURB_IMMED_PORT_SETTER(ruby_curl_easy, proxy_port, "port");
}

#proxy_tunnel=(boolean) ⇒ Boolean

Configure whether this Curl instance will use proxy tunneling.

Returns:

  • (Boolean)


1392
1393
1394
# File 'ext/curb/curb_easy.c', line 1392

static VALUE ruby_curl_easy_proxy_tunnel_set(VALUE self, VALUE proxy_tunnel) {
  CURB_BOOLEAN_SETTER(ruby_curl_easy, proxy_tunnel);
}

#proxy_tunnel?Boolean

Determine whether this Curl instance will use proxy tunneling.

Returns:

  • (Boolean)


1402
1403
1404
# File 'ext/curb/curb_easy.c', line 1402

static VALUE ruby_curl_easy_proxy_tunnel_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, proxy_tunnel);
}

#proxy_typeFixnum?

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

Returns:

  • (Fixnum, nil)


992
993
994
# File 'ext/curb/curb_easy.c', line 992

static VALUE ruby_curl_easy_proxy_type_get(VALUE self) {
  CURB_IMMED_GETTER(ruby_curl_easy, proxy_type, -1);
}

#proxy_type=(fixnum) ⇒ Fixnum?

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

Returns:

  • (Fixnum, nil)


982
983
984
# File 'ext/curb/curb_easy.c', line 982

static VALUE ruby_curl_easy_proxy_type_set(VALUE self, VALUE proxy_type) {
  CURB_IMMED_SETTER(ruby_curl_easy, proxy_type, -1);
}

#proxy_urlString

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

Returns:



444
445
446
# File 'ext/curb/curb_easy.c', line 444

static VALUE ruby_curl_easy_proxy_url_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, proxy_url);
}

#proxy_url=(url) ⇒ Object

<host>:<port>



63
64
65
# File 'lib/rhack/curl/easy.rb', line 63

def proxy_url=(url)
  set :proxy, url
end

#proxypwdString

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”

Returns:



519
520
521
# File 'ext/curb/curb_easy.c', line 519

static VALUE ruby_curl_easy_proxypwd_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, proxypwd);
}

#proxypwd=(value) ⇒ Object

<username>:<password>



73
74
75
# File 'lib/rhack/curl/easy.rb', line 73

def proxypwd=(value)
  set :proxyuserpwd, value
end

#put_data=(data) ⇒ Object

Points this Curl::Easy instance to data to be uploaded via PUT. This sets the request to a PUT type request - useful if you want to PUT via a multi handle.



805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
# File 'ext/curb/curb_easy.c', line 805

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);

  upload = ruby_curl_upload_new(cCurlUpload);
  ruby_curl_upload_stream_set(upload,data);

  curl = rbce->curl;
  rb_easy_set("upload", upload); /* keep the upload object alive as long as
                                    the easy handle is active or until the upload
                                    is complete or terminated... */

  curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  curl_easy_setopt(curl, CURLOPT_READFUNCTION, (curl_read_callback)read_data_handler);
  curl_easy_setopt(curl, CURLOPT_READDATA, rbce);

  /* 
   * 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, FIX2LONG(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, FIX2LONG(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_countInteger

Retrieve the total number of redirections that were actually followed.

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

Returns:

  • (Integer)


2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
# File 'ext/curb/curb_easy.c', line 2682

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_REDIRECT_COUNT, &count);

  return LONG2NUM(count);
#else
  rb_warn("Installed libcurl is too old to support redirect_count");
  return INT2FIX(-1);
#endif

}

#redirect_timeFloat

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.

Returns:

  • (Float)


2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
# File 'ext/curb/curb_easy.c', line 2659

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_REDIRECT_TIME, &time);

  return rb_float_new(time);
#else
  rb_warn("Installed libcurl is too old to support redirect_time");
  return rb_float_new(-1);
#endif
}

#redirect_urlnil

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.

Returns:

  • (nil)


2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
# File 'ext/curb/curb_easy.c', line 2707

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_REDIRECT_URL, &url);

  if (url && url[0]) {    // curl returns empty string if none
    return rb_str_new2(url);
  } else {
    return Qnil;
  }
#else
  rb_warn("Installed libcurl is too old to support redirect_url");
  return INT2FIX(-1);
#endif
}

#reqObject Also known as: request



22
23
24
# File 'lib/rhack/curl/easy.rb', line 22

def req
  res.req
end

#request_sizeFixnum

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.

Returns:

  • (Fixnum)


2821
2822
2823
2824
2825
2826
2827
2828
2829
# File 'ext/curb/curb_easy.c', line 2821

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

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

  return LONG2NUM(size);
}

#resObject Also known as: response



12
13
14
15
16
17
18
19
# File 'lib/rhack/curl/easy.rb', line 12

def res
  if @res && !@outdated
    @res
  else 
    @outdated = false
    @res = Response(self)
  end
end

#resetHash

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.

Returns:

  • (Hash)


395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'ext/curb/curb_easy.c', line 395

static VALUE ruby_curl_easy_reset(VALUE self) {
  CURLcode ecode;
  ruby_curl_easy *rbce;
  VALUE opts_dup;
  Data_Get_Struct(self, ruby_curl_easy, rbce);

  if (rbce->callback_active) {
    rb_raise(rb_eRuntimeError, "Cannot close an active curl handle within a callback");
  }

  opts_dup = rb_funcall(rbce->opts, rb_intern("dup"), 0);

  curl_easy_reset(rbce->curl);
  ruby_curl_easy_zero(rbce);

  /* rest clobbers the private setting, so reset it to self */
  ecode = curl_easy_setopt(rbce->curl, CURLOPT_PRIVATE, (void*)self);
  if (ecode != CURLE_OK) {
    raise_curl_easy_error_exception(ecode);
  }

  /* Free everything up */
  if (rbce->curl_headers) {
    curl_slist_free_all(rbce->curl_headers);
    rbce->curl_headers = NULL;
  }

  return opts_dup;
}

#resolve_modeObject

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



1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
# File 'ext/curb/curb_easy.c', line 1687

static VALUE ruby_curl_easy_resolve_mode(VALUE self) {
  ruby_curl_easy *rbce;
  Data_Get_Struct(self, ruby_curl_easy, rbce);

  unsigned short rm = rbce->resolve_mode;

  switch(rm) {
    case CURL_IPRESOLVE_V4:
      return rb_easy_sym("ipv4");
    case CURL_IPRESOLVE_V6:
      return rb_easy_sym("ipv6");
    default:
      return rb_easy_sym("auto");
  }
}

#resolve_mode=(symbol) ⇒ Object

Configures what type of IP address this Curl::Easy instance resolves DNS names to. Valid options are:

:auto

resolves DNS names to all IP versions your system allows

:ipv4

resolves DNS names to IPv4 only

:ipv6

resolves DNS names to IPv6 only



1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
# File 'ext/curb/curb_easy.c', line 1714

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;
    Data_Get_Struct(self, ruby_curl_easy, rbce);

    ID 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_codeFixnum

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.

Returns:

  • (Fixnum)


2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
# File 'ext/curb/curb_easy.c', line 2473

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);
#ifdef HAVE_CURLINFO_RESPONSE_CODE
  curl_easy_getinfo(rbce->curl, CURLINFO_RESPONSE_CODE, &code);
#else
  // old libcurl
  curl_easy_getinfo(rbce->curl, CURLINFO_HTTP_CODE, &code);
#endif

  return LONG2NUM(code);
}

#retry!Object



35
36
37
38
# File 'lib/rhack/curl/easy.rb', line 35

def retry!
  @base.retry!
  # <self> is forgotten now
end

#set(opt, val) ⇒ Object

curb changed getters interface, so i get some shortcuts from curb/lib/curl/easy.rb



41
42
43
44
45
46
47
# File 'lib/rhack/curl/easy.rb', line 41

def set(opt,val)
  if opt.is_a?(Symbol)
    setopt(sym2curl(opt), val)
  else
    setopt(opt.to_i, val)
  end
end

#FixnumObject

Iniital access to libcurl curl_easy_setopt



3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
# File 'ext/curb/curb_easy.c', line 3066

static VALUE ruby_curl_easy_set_opt(VALUE self, VALUE opt, VALUE val) {
  ruby_curl_easy *rbce;
  long option = FIX2LONG(opt);

  Data_Get_Struct(self, ruby_curl_easy, rbce);

  switch (option) {
  /* BEHAVIOR OPTIONS */
  case CURLOPT_VERBOSE: {
    VALUE verbose = val;
    CURB_BOOLEAN_SETTER(ruby_curl_easy, verbose);
    } break;
  case CURLOPT_FOLLOWLOCATION: {
    VALUE follow_location = val;
    CURB_BOOLEAN_SETTER(ruby_curl_easy, follow_location);
    } break;
  /* TODO: CALLBACK OPTIONS */
  /* TODO: ERROR OPTIONS */
  /* NETWORK OPTIONS */
  case CURLOPT_URL: {
    VALUE url = val;
    CURB_OBJECT_HSETTER(ruby_curl_easy, url);
    } break;
  case CURLOPT_CUSTOMREQUEST:
    curl_easy_setopt(rbce->curl, CURLOPT_CUSTOMREQUEST, NIL_P(val) ? NULL : StringValueCStr(val));
    break;
  case CURLOPT_HTTP_VERSION:
    curl_easy_setopt(rbce->curl, CURLOPT_HTTP_VERSION, FIX2INT(val));
    break;
  case CURLOPT_PROXY: {
    VALUE proxy_url = val;
    CURB_OBJECT_HSETTER(ruby_curl_easy, proxy_url);
    } break;
  case CURLOPT_INTERFACE: {
    VALUE interface_hm = val;
    CURB_OBJECT_HSETTER(ruby_curl_easy, interface_hm);
    } break;
  case CURLOPT_HEADER:
  case CURLOPT_NOPROGRESS:
  case CURLOPT_NOSIGNAL:
  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, FIX2INT(value));
    } break;
  case CURLOPT_USERPWD: {
    VALUE userpwd = val;
    CURB_OBJECT_HSETTER(ruby_curl_easy, userpwd);
    } break;
  case CURLOPT_PROXYUSERPWD: {
    VALUE proxypwd = val;
    CURB_OBJECT_HSETTER(ruby_curl_easy, proxypwd);
    } break;
  case CURLOPT_COOKIE: {
    VALUE cookies = val;
    CURB_OBJECT_HSETTER(ruby_curl_easy, cookies);
    } break;
  case CURLOPT_COOKIEFILE: {
    VALUE cookiefile = val;
    CURB_OBJECT_HSETTER(ruby_curl_easy, cookiefile);
    } break;
  case CURLOPT_COOKIEJAR: {
    VALUE cookiejar = val;
    CURB_OBJECT_HSETTER(ruby_curl_easy, cookiejar);
    } break;
  case CURLOPT_RESUME_FROM: {
    curl_easy_setopt(rbce->curl, CURLOPT_RESUME_FROM, FIX2LONG(val));
    } break;
  case CURLOPT_FAILONERROR: {
    curl_easy_setopt(rbce->curl, CURLOPT_FAILONERROR, FIX2LONG(val));
    } break;
  default:
    break;
  }

  return val;
}

#ssl_verify_hostNumeric

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

Returns:

  • (Numeric)


1481
1482
1483
# File 'ext/curb/curb_easy.c', line 1481

static VALUE ruby_curl_easy_ssl_verify_host_get(VALUE self) {
  CURB_IMMED_GETTER(ruby_curl_easy, ssl_verify_host, 0);
}

#ssl_verify_host_integer=(ssl_verify_host) ⇒ Object

Configure whether this Curl instance will verify that the server cert is for the server it is known as. When true (the default) the server certificate must indicate that the server is the server to which you meant to connect, or the connection fails. When false, the connection will succeed regardless of the names in the certificate.

this option controls is of the identity that the server claims. The server could be lying. To control lying, see ssl_verify_peer? .



1470
1471
1472
# File 'ext/curb/curb_easy.c', line 1470

static VALUE ruby_curl_easy_ssl_verify_host_set(VALUE self, VALUE ssl_verify_host) {
  CURB_IMMED_SETTER(ruby_curl_easy, ssl_verify_host, 0);
}

#ssl_verify_peer=(boolean) ⇒ Boolean

Configure whether this Curl instance will verify the SSL peer certificate. When true (the default), and the verification fails to prove that the certificate is authentic, the connection fails. When false, the connection succeeds regardless.

Authenticating the certificate is not by itself very useful. You typically want to ensure that the server, as authentically identified by its certificate, is the server you mean to be talking to. The ssl_verify_host? options controls that.

Returns:

  • (Boolean)


1442
1443
1444
# File 'ext/curb/curb_easy.c', line 1442

static VALUE ruby_curl_easy_ssl_verify_peer_set(VALUE self, VALUE ssl_verify_peer) {
  CURB_BOOLEAN_SETTER(ruby_curl_easy, ssl_verify_peer);
}

#ssl_verify_peer?Boolean

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

Returns:

  • (Boolean)


1453
1454
1455
# File 'ext/curb/curb_easy.c', line 1453

static VALUE ruby_curl_easy_ssl_verify_peer_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, ssl_verify_peer);
}

#ssl_verify_resultInteger

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

Returns:

  • (Integer)


2838
2839
2840
2841
2842
2843
2844
2845
2846
# File 'ext/curb/curb_easy.c', line 2838

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

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

  return LONG2NUM(result);
}

#ssl_versionFixnum

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

Returns:

  • (Fixnum)


1338
1339
1340
# File 'ext/curb/curb_easy.c', line 1338

static VALUE ruby_curl_easy_ssl_version_get(VALUE self, VALUE ssl_version) {
  CURB_IMMED_GETTER(ruby_curl_easy, ssl_version, -1);
}

#ssl_version=(value) ⇒ Fixnum?

Sets the version of SSL/TLS that libcurl will attempt to use. Valid options are Curl::CURL_SSLVERSION_TLSv1, Curl::CURL_SSLVERSION::SSLv2, Curl::CURL_SSLVERSION_SSLv3 and Curl::CURL_SSLVERSION_DEFAULT

Returns:

  • (Fixnum, nil)


1328
1329
1330
# File 'ext/curb/curb_easy.c', line 1328

static VALUE ruby_curl_easy_ssl_version_set(VALUE self, VALUE ssl_version) {
  CURB_IMMED_SETTER(ruby_curl_easy, ssl_version, -1);
}

#start_transfer_timeFloat

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.

Returns:

  • (Float)


2638
2639
2640
2641
2642
2643
2644
2645
2646
# File 'ext/curb/curb_easy.c', line 2638

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

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

  return rb_float_new(time);
}

#sym2curl(opt) ⇒ Object



49
50
51
# File 'lib/rhack/curl/easy.rb', line 49

def sym2curl(opt)
  Curl.const_get("CURLOPT_#{opt.to_s.upcase}")
end

#timeoutFixnum?

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

Returns:

  • (Fixnum, nil)


1139
1140
1141
# File 'ext/curb/curb_easy.c', line 1139

static VALUE ruby_curl_easy_timeout_get(VALUE self, VALUE timeout) {
  CURB_IMMED_GETTER(ruby_curl_easy, timeout, 0);
}

#timeout=(fixnum) ⇒ Fixnum?

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

Returns:

  • (Fixnum, nil)


1128
1129
1130
# File 'ext/curb/curb_easy.c', line 1128

static VALUE ruby_curl_easy_timeout_set(VALUE self, VALUE timeout) {
  CURB_IMMED_SETTER(ruby_curl_easy, timeout, 0);
}

#total_timeFloat

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

Returns:

  • (Float)


2567
2568
2569
2570
2571
2572
2573
2574
2575
# File 'ext/curb/curb_easy.c', line 2567

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

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

  return rb_float_new(time);
}

#unescape("some%20text") ⇒ Object

Convert the given URL encoded input string to a “plain string” and return the result. All input characters that are URL encoded (%XX where XX is a two-digit hexadecimal number) are converted to their binary versions.



3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
# File 'ext/curb/curb_easy.c', line 3226

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

  Data_Get_Struct(self, ruby_curl_easy, rbce);

#if (LIBCURL_VERSION_NUM >= 0x070f04)
  result = (char*)curl_easy_unescape(rbce->curl, StringValuePtr(str), (int)RSTRING_LEN(str), &rlen);
#else
  result = (char*)curl_unescape(StringValuePtr(str), RSTRING_LEN(str));
  rlen = strlen(result);
#endif

  rresult = rb_str_new(result, rlen);
  curl_free(result);

  return rresult;
}

#unrestricted_auth=(boolean) ⇒ Boolean

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

Returns:

  • (Boolean)


1568
1569
1570
# File 'ext/curb/curb_easy.c', line 1568

static VALUE ruby_curl_easy_unrestricted_auth_set(VALUE self, VALUE unrestricted_auth) {
  CURB_BOOLEAN_SETTER(ruby_curl_easy, unrestricted_auth);
}

#unrestricted_auth?Boolean

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

Returns:

  • (Boolean)


1579
1580
1581
# File 'ext/curb/curb_easy.c', line 1579

static VALUE ruby_curl_easy_unrestricted_auth_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, unrestricted_auth);
}

#upload_speedFloat

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

Returns:

  • (Float)


2769
2770
2771
2772
2773
2774
2775
2776
2777
# File 'ext/curb/curb_easy.c', line 2769

static VALUE ruby_curl_easy_upload_speed_get(VALUE self) {
  ruby_curl_easy *rbce;
  double bytes;

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_SPEED_UPLOAD, &bytes);

  return rb_float_new(bytes);
}

#uploaded_bytesFloat

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

Returns:

  • (Float)


2735
2736
2737
2738
2739
2740
2741
2742
2743
# File 'ext/curb/curb_easy.c', line 2735

static VALUE ruby_curl_easy_uploaded_bytes_get(VALUE self) {
  ruby_curl_easy *rbce;
  double bytes;

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_SIZE_UPLOAD, &bytes);

  return rb_float_new(bytes);
}

#uploaded_content_lengthFloat

Retrieve the content-length of the upload.

Returns:

  • (Float)


2879
2880
2881
2882
2883
2884
2885
2886
2887
# File 'ext/curb/curb_easy.c', line 2879

static VALUE ruby_curl_easy_uploaded_content_length_get(VALUE self) {
  ruby_curl_easy *rbce;
  double bytes;

  Data_Get_Struct(self, ruby_curl_easy, rbce);
  curl_easy_getinfo(rbce->curl, CURLINFO_CONTENT_LENGTH_UPLOAD, &bytes);

  return rb_float_new(bytes);
}

#urlString

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

Returns:



434
435
436
# File 'ext/curb/curb_easy.c', line 434

static VALUE ruby_curl_easy_url_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, url);
}

#url=(u) ⇒ Object

<host>:<port>



58
59
60
# File 'lib/rhack/curl/easy.rb', line 58

def url=(u)
  set :url, u
end

#use_netrc=(boolean) ⇒ Boolean

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

Returns:

  • (Boolean)


1515
1516
1517
# File 'ext/curb/curb_easy.c', line 1515

static VALUE ruby_curl_easy_use_netrc_set(VALUE self, VALUE use_netrc) {
  CURB_BOOLEAN_SETTER(ruby_curl_easy, use_netrc);
}

#use_netrc?Boolean

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

Returns:

  • (Boolean)


1526
1527
1528
# File 'ext/curb/curb_easy.c', line 1526

static VALUE ruby_curl_easy_use_netrc_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, use_netrc);
}

#use_sslFixnum

Get the desired level for using SSL on FTP connections.

Returns:

  • (Fixnum)


1359
1360
1361
# File 'ext/curb/curb_easy.c', line 1359

static VALUE ruby_curl_easy_use_ssl_get(VALUE self, VALUE use_ssl) {
  CURB_IMMED_GETTER(ruby_curl_easy, use_ssl, -1);
}

#use_ssl=(value) ⇒ Fixnum?

Ensure libcurl uses SSL for FTP connections. Valid options are Curl::CURL_USESSL_NONE, Curl::CURL_USESSL_TRY, Curl::CURL_USESSL_CONTROL, and Curl::CURL_USESSL_ALL.

Returns:

  • (Fixnum, nil)


1349
1350
1351
# File 'ext/curb/curb_easy.c', line 1349

static VALUE ruby_curl_easy_use_ssl_set(VALUE self, VALUE use_ssl) {
  CURB_IMMED_SETTER(ruby_curl_easy, use_ssl, -1);
}

#useragent"Ruby/Curb"

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

Returns:

  • ("Ruby/Curb")


689
690
691
# File 'ext/curb/curb_easy.c', line 689

static VALUE ruby_curl_easy_useragent_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, useragent);
}

#useragent=(useragent) ⇒ Object

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



679
680
681
# File 'ext/curb/curb_easy.c', line 679

static VALUE ruby_curl_easy_useragent_set(VALUE self, VALUE useragent) {
  CURB_OBJECT_HSETTER(ruby_curl_easy, useragent);
}

#usernameString

Get the current username

Returns:



1284
1285
1286
1287
1288
1289
1290
# File 'ext/curb/curb_easy.c', line 1284

static VALUE ruby_curl_easy_username_get(VALUE self, VALUE username) {
#if HAVE_CURLOPT_USERNAME
  CURB_OBJECT_HGETTER(ruby_curl_easy, username);
#else
  return Qnil;
#endif
}

#username=(string) ⇒ String

Set the HTTP Authentication username.

Returns:



1270
1271
1272
1273
1274
1275
1276
# File 'ext/curb/curb_easy.c', line 1270

static VALUE ruby_curl_easy_username_set(VALUE self, VALUE username) {
#if HAVE_CURLOPT_USERNAME
  CURB_OBJECT_HSETTER(ruby_curl_easy, username);
#else
  return Qnil;
#endif
}

#userpwdString

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

Returns:



507
508
509
# File 'ext/curb/curb_easy.c', line 507

static VALUE ruby_curl_easy_userpwd_get(VALUE self) {
  CURB_OBJECT_HGETTER(ruby_curl_easy, userpwd);
}

#userpwd=(value) ⇒ Object

<username>:<password>



68
69
70
# File 'lib/rhack/curl/easy.rb', line 68

def userpwd=(value)
  set :userpwd, value
end

#verbose=(boolean) ⇒ Boolean

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

Returns:

  • (Boolean)


1590
1591
1592
# File 'ext/curb/curb_easy.c', line 1590

static VALUE ruby_curl_easy_verbose_set(VALUE self, VALUE verbose) {
  CURB_BOOLEAN_SETTER(ruby_curl_easy, verbose);
}

#verbose?Boolean

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

Returns:

  • (Boolean)


1601
1602
1603
# File 'ext/curb/curb_easy.c', line 1601

static VALUE ruby_curl_easy_verbose_q(VALUE self) {
  CURB_BOOLEAN_GETTER(ruby_curl_easy, verbose);
}