pauldix-typhoeus 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -105,34 +105,34 @@ static void set_response_handlers(VALUE easy, CURL *curl) {
105
105
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, rb_iv_get(easy, "@response_body"));
106
106
  curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, (curl_write_callback)&write_data_handler);
107
107
  curl_easy_setopt(curl, CURLOPT_HEADERDATA, rb_iv_get(easy, "@response_header"));
108
-
109
- return NULL;
110
108
  }
111
109
 
112
110
  static VALUE easy_reset(VALUE self) {
113
111
  CurlEasy *curl_easy;
114
112
  Data_Get_Struct(self, CurlEasy, curl_easy);
115
113
 
116
- curl_easy_reset(curl_easy->curl);
117
-
118
114
  if (curl_easy->request_chunk != NULL) {
119
115
  free(curl_easy->request_chunk);
116
+ curl_easy->request_chunk = NULL;
120
117
  }
121
118
 
122
119
  if (curl_easy->headers != NULL) {
123
120
  curl_slist_free_all(curl_easy->headers);
121
+ curl_easy->headers = NULL;
124
122
  }
125
123
 
126
- set_response_handlers(self, curl_easy->curl);
124
+ curl_easy_reset(curl_easy->curl);
127
125
 
126
+ set_response_handlers(self, curl_easy->curl);
127
+
128
128
  return Qnil;
129
129
  }
130
130
 
131
131
  static VALUE easy_add_header(VALUE self, VALUE header) {
132
132
  CurlEasy *curl_easy;
133
133
  Data_Get_Struct(self, CurlEasy, curl_easy);
134
-
135
- curl_easy->headers = curl_slist_append(curl_easy->headers, StringValuePtr(header));
134
+
135
+ curl_easy->headers = curl_slist_append(curl_easy->headers, strdup(RSTRING_PTR(header)));
136
136
  return header;
137
137
  }
138
138
 
data/lib/typhoeus/easy.rb CHANGED
@@ -27,6 +27,10 @@ module Typhoeus
27
27
  @headers = {}
28
28
  end
29
29
 
30
+ def headers=(hash)
31
+ @headers = hash
32
+ end
33
+
30
34
  def total_time_taken
31
35
  get_info_double(INFO_VALUES[:CURLINFO_TOTAL_TIME])
32
36
  end
@@ -119,12 +123,16 @@ module Typhoeus
119
123
  end
120
124
 
121
125
  def perform
126
+ set_headers()
127
+ easy_perform()
128
+ response_code()
129
+ end
130
+
131
+ def set_headers
122
132
  headers.each_pair do |key, value|
123
133
  easy_add_header("#{key}: #{value}")
124
134
  end
125
135
  easy_set_headers() unless headers.empty?
126
- easy_perform()
127
- response_code()
128
136
  end
129
137
 
130
138
  # gets called when finished and response code is 200-299
@@ -80,13 +80,12 @@ module Typhoeus
80
80
 
81
81
  easy.url = url
82
82
  easy.method = method
83
- easy.headers = options[:headers] if options.has_key? :headers
83
+ easy.headers = options[:headers] if options.has_key?(:headers)
84
84
  easy.headers["User-Agent"] = (options[:user_agent] || Typhoeus::USER_AGENT)
85
85
  easy.params = options[:params] if options[:params]
86
86
  easy.request_body = options[:body] if options[:body]
87
87
  easy.timeout = options[:timeout] if options[:timeout]
88
-
89
- easy
88
+ easy.set_headers
90
89
 
91
90
  proxy = Typhoeus::RemoteProxyObject.new(clear_memoized_proxy_objects, easy, options)
92
91
  set_memoized_proxy_object(method, url, options, proxy)
@@ -122,7 +121,7 @@ module Typhoeus
122
121
  # return object
123
122
  # end
124
123
  # end
125
-
124
+
126
125
  proxy = memoized_proxy_object(http_method, url, options)
127
126
  unless proxy
128
127
  if m.cache_responses?
data/lib/typhoeus.rb CHANGED
@@ -12,7 +12,7 @@ require 'typhoeus/remote_proxy_object'
12
12
  require 'typhoeus/response'
13
13
 
14
14
  module Typhoeus
15
- VERSION = "0.0.11"
15
+ VERSION = "0.0.12"
16
16
 
17
17
  def self.easy_object_pool
18
18
  @easy_objects ||= []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pauldix-typhoeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix