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.
- data/ext/typhoeus/typhoeus_easy.c +7 -7
- data/lib/typhoeus/easy.rb +10 -2
- data/lib/typhoeus/remote.rb +3 -4
- data/lib/typhoeus.rb +1 -1
- metadata +1 -1
@@ -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
|
-
|
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,
|
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
|
data/lib/typhoeus/remote.rb
CHANGED
@@ -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?
|
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