typhoeus 0.1.27 → 0.1.28
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +9 -0
- data/README.textile +23 -0
- data/VERSION +1 -1
- data/lib/typhoeus/easy.rb +69 -6
- data/lib/typhoeus/hydra.rb +7 -0
- data/lib/typhoeus/multi.rb +4 -3
- data/lib/typhoeus/request.rb +34 -1
- data/spec/typhoeus/easy_spec.rb +10 -2
- data/spec/typhoeus/remote_spec.rb +1 -1
- data/typhoeus.gemspec +3 -2
- metadata +4 -3
data/CHANGELOG.markdown
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
0.1.28
|
2
|
+
----------------
|
3
|
+
* Added SSL cert options for Typhoeus::Easy [GH-25, gravis]
|
4
|
+
* Ported SSL cert options to Typhoeus::Request interface [gravis]
|
5
|
+
* Added support for any HTTP method (purge for Varnish) [ryana]
|
6
|
+
|
7
|
+
0.1.27
|
8
|
+
------
|
9
|
+
* Added rack as dependency, added dev dependencies to Rakefile [GH-21]
|
data/README.textile
CHANGED
@@ -204,6 +204,29 @@ Typhoeus::Request.get("https://mail.google.com/mail", :disable_ssl_peer_verifica
|
|
204
204
|
*LibCurl*
|
205
205
|
Typhoeus also has a more raw libcurl interface. These are the Easy and Multi objects. If you're into accessing just the raw libcurl style, those are your best bet.
|
206
206
|
|
207
|
+
SSL Certs can be provided to the Easy interface :
|
208
|
+
|
209
|
+
<pre>
|
210
|
+
e = Typhoeus::Easy.new
|
211
|
+
e.url = "https://example.com/action"
|
212
|
+
s.ssl_cacert = "ca_file.cer"
|
213
|
+
e.ssl_cert = "acert.crt"
|
214
|
+
e.ssl_key = "akey.key"
|
215
|
+
[...]
|
216
|
+
e.perform
|
217
|
+
</pre>
|
218
|
+
|
219
|
+
or directly to a Typhoeus::Request :
|
220
|
+
|
221
|
+
<pre>
|
222
|
+
e = Typhoeus::Request.get("https://example.com/action",
|
223
|
+
:ssl_cacert => "ca_file.cer",
|
224
|
+
:ssl_cert => "acert.crt",
|
225
|
+
:ssl_key => "akey.key",
|
226
|
+
[...]
|
227
|
+
end
|
228
|
+
</pre>
|
229
|
+
|
207
230
|
h2. NTLM authentication
|
208
231
|
|
209
232
|
Thanks for the authentication piece and this description go to Oleg Ivanov (morhekil). The major reason to start this fork was the need to perform NTLM authentication in Ruby. Now you can do it via Typhoeus::Easy interface using the following API.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.28
|
data/lib/typhoeus/easy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Typhoeus
|
2
2
|
class Easy
|
3
|
-
attr_reader :response_body, :response_header, :method, :headers, :url
|
3
|
+
attr_reader :response_body, :response_header, :method, :headers, :url, :params
|
4
4
|
attr_accessor :start_time
|
5
5
|
|
6
6
|
# These integer codes are available in curl/curl.h
|
@@ -25,7 +25,14 @@ module Typhoeus
|
|
25
25
|
:CURLOPT_PROXY => 10004,
|
26
26
|
:CURLOPT_VERIFYPEER => 64,
|
27
27
|
:CURLOPT_NOBODY => 44,
|
28
|
-
:CURLOPT_ENCODING => 102
|
28
|
+
:CURLOPT_ENCODING => 102,
|
29
|
+
:CURLOPT_SSLCERT => 10025,
|
30
|
+
:CURLOPT_SSLCERTTYPE => 10086,
|
31
|
+
:CURLOPT_SSLKEY => 10087,
|
32
|
+
:CURLOPT_SSLKEYTYPE => 10088,
|
33
|
+
:CURLOPT_KEYPASSWD => 10026,
|
34
|
+
:CURLOPT_CAINFO => 10065,
|
35
|
+
:CURLOPT_CAPATH => 10097
|
29
36
|
}
|
30
37
|
INFO_VALUES = {
|
31
38
|
:CURLINFO_RESPONSE_CODE => 2097154,
|
@@ -105,7 +112,7 @@ module Typhoeus
|
|
105
112
|
end
|
106
113
|
|
107
114
|
def supports_zlib?
|
108
|
-
|
115
|
+
!!(curl_version.match(/zlib/))
|
109
116
|
end
|
110
117
|
|
111
118
|
def request_body=(request_body)
|
@@ -145,7 +152,7 @@ module Typhoeus
|
|
145
152
|
elsif method == :head
|
146
153
|
set_option(OPTION_VALUES[:CURLOPT_NOBODY], 1)
|
147
154
|
else
|
148
|
-
set_option(OPTION_VALUES[:CURLOPT_CUSTOMREQUEST],
|
155
|
+
set_option(OPTION_VALUES[:CURLOPT_CUSTOMREQUEST], method.to_s.upcase)
|
149
156
|
end
|
150
157
|
end
|
151
158
|
|
@@ -156,6 +163,7 @@ module Typhoeus
|
|
156
163
|
end
|
157
164
|
|
158
165
|
def params=(params)
|
166
|
+
@params = params
|
159
167
|
params_string = params.keys.collect do |k|
|
160
168
|
value = params[k]
|
161
169
|
if value.is_a? Hash
|
@@ -175,10 +183,58 @@ module Typhoeus
|
|
175
183
|
end
|
176
184
|
end
|
177
185
|
|
186
|
+
# Set SSL certificate
|
187
|
+
# " The string should be the file name of your certificate. "
|
188
|
+
# The default format is "PEM" and can be changed with ssl_cert_type=
|
189
|
+
def ssl_cert=(cert)
|
190
|
+
set_option(OPTION_VALUES[:CURLOPT_SSLCERT], cert)
|
191
|
+
end
|
192
|
+
|
193
|
+
# Set SSL certificate type
|
194
|
+
# " The string should be the format of your certificate. Supported formats are "PEM" and "DER" "
|
195
|
+
def ssl_cert_type=(cert_type)
|
196
|
+
raise "Invalid ssl cert type : '#{cert_type}'..." if cert_type and !%w(PEM DER).include?(cert_type)
|
197
|
+
set_option(OPTION_VALUES[:CURLOPT_SSLCERTTYPE], cert_type)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Set SSL Key file
|
201
|
+
# " The string should be the file name of your private key. "
|
202
|
+
# The default format is "PEM" and can be changed with ssl_key_type=
|
203
|
+
#
|
204
|
+
def ssl_key=(key)
|
205
|
+
set_option(OPTION_VALUES[:CURLOPT_SSLKEY], key)
|
206
|
+
end
|
207
|
+
|
208
|
+
# Set SSL Key type
|
209
|
+
# " The string should be the format of your private key. Supported formats are "PEM", "DER" and "ENG". "
|
210
|
+
#
|
211
|
+
def ssl_key_type=(key_type)
|
212
|
+
raise "Invalid ssl key type : '#{key_type}'..." if key_type and !%w(PEM DER ENG).include?(key_type)
|
213
|
+
set_option(OPTION_VALUES[:CURLOPT_SSLKEYTYPE], key_type)
|
214
|
+
end
|
215
|
+
|
216
|
+
def ssl_key_password=(key_password)
|
217
|
+
set_option(OPTION_VALUES[:CURLOPT_KEYPASSWD], key_password)
|
218
|
+
end
|
219
|
+
|
220
|
+
# Set SSL CACERT
|
221
|
+
# " File holding one or more certificates to verify the peer with. "
|
222
|
+
#
|
223
|
+
def ssl_cacert=(cacert)
|
224
|
+
set_option(OPTION_VALUES[:CURLOPT_CAINFO], cacert)
|
225
|
+
end
|
226
|
+
|
227
|
+
# Set CAPATH
|
228
|
+
# " directory holding multiple CA certificates to verify the peer with. The certificate directory must be prepared using the openssl c_rehash utility. "
|
229
|
+
#
|
230
|
+
def ssl_capath=(capath)
|
231
|
+
set_option(OPTION_VALUES[:CURLOPT_CAPATH], capath)
|
232
|
+
end
|
233
|
+
|
178
234
|
def set_option(option, value)
|
179
235
|
if value.class == String
|
180
236
|
easy_setopt_string(option, value)
|
181
|
-
|
237
|
+
elsif value
|
182
238
|
easy_setopt_long(option, value)
|
183
239
|
end
|
184
240
|
end
|
@@ -186,7 +242,13 @@ module Typhoeus
|
|
186
242
|
def perform
|
187
243
|
set_headers()
|
188
244
|
easy_perform()
|
189
|
-
response_code()
|
245
|
+
resp_code = response_code()
|
246
|
+
if resp_code >= 200 && resp_code <= 299
|
247
|
+
success
|
248
|
+
else
|
249
|
+
failure
|
250
|
+
end
|
251
|
+
resp_code
|
190
252
|
end
|
191
253
|
|
192
254
|
def set_headers
|
@@ -262,5 +324,6 @@ module Typhoeus
|
|
262
324
|
def curl_version
|
263
325
|
version
|
264
326
|
end
|
327
|
+
|
265
328
|
end
|
266
329
|
end
|
data/lib/typhoeus/hydra.rb
CHANGED
@@ -142,6 +142,13 @@ module Typhoeus
|
|
142
142
|
easy.max_redirects = request.max_redirects if request.max_redirects
|
143
143
|
easy.proxy = request.proxy if request.proxy
|
144
144
|
easy.disable_ssl_peer_verification if request.disable_ssl_peer_verification
|
145
|
+
easy.ssl_cert = request.ssl_cert
|
146
|
+
easy.ssl_cert_type = request.ssl_cert_type
|
147
|
+
easy.ssl_key = request.ssl_key
|
148
|
+
easy.ssl_key_type = request.ssl_key_type
|
149
|
+
easy.ssl_key_password = request.ssl_key_password
|
150
|
+
easy.ssl_cacert = request.ssl_cacert
|
151
|
+
easy.ssl_capath = request.ssl_capath
|
145
152
|
|
146
153
|
easy.on_success do |easy|
|
147
154
|
queue_next
|
data/lib/typhoeus/multi.rb
CHANGED
@@ -9,19 +9,20 @@ module Typhoeus
|
|
9
9
|
def remove(easy)
|
10
10
|
multi_remove_handle(easy)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def add(easy)
|
14
|
+
easy.set_headers()
|
14
15
|
@easy_handles << easy
|
15
16
|
multi_add_handle(easy)
|
16
17
|
end
|
17
|
-
|
18
|
+
|
18
19
|
def perform()
|
19
20
|
while active_handle_count > 0 do
|
20
21
|
multi_perform
|
21
22
|
end
|
22
23
|
reset_easy_handles
|
23
24
|
end
|
24
|
-
|
25
|
+
|
25
26
|
def cleanup()
|
26
27
|
multi_cleanup
|
27
28
|
end
|
data/lib/typhoeus/request.rb
CHANGED
@@ -1,8 +1,34 @@
|
|
1
1
|
module Typhoeus
|
2
2
|
class Request
|
3
|
-
attr_accessor :method, :params, :body, :headers, :timeout, :user_agent, :response, :cache_timeout, :follow_location, :max_redirects, :proxy, :disable_ssl_peer_verification
|
3
|
+
attr_accessor :method, :params, :body, :headers, :timeout, :user_agent, :response, :cache_timeout, :follow_location, :max_redirects, :proxy, :disable_ssl_peer_verification, :ssl_cert, :ssl_cert_type, :ssl_key, :ssl_key_type, :ssl_key_password, :ssl_cacert, :ssl_capath
|
4
|
+
|
5
|
+
|
4
6
|
attr_reader :url
|
5
7
|
|
8
|
+
# Initialize a new Request
|
9
|
+
#
|
10
|
+
# Options:
|
11
|
+
# * +url+ : Endpoint (URL) of the request
|
12
|
+
# * +options+ : A hash containing options among :
|
13
|
+
# ** +:method+ : :get (default) / :post / :put
|
14
|
+
# ** +:params+ : params as a Hash
|
15
|
+
# ** +:body+
|
16
|
+
# ** +:timeout+ : timeout (ms)
|
17
|
+
# ** +:headers+ : headers as Hash
|
18
|
+
# ** +:user_agent+ : user agent (string)
|
19
|
+
# ** +:cache_timeout+ : cache timeout (ms)
|
20
|
+
# ** +:follow_location
|
21
|
+
# ** +:max_redirects
|
22
|
+
# ** +:proxy
|
23
|
+
# ** +:disable_ssl_peer_verification
|
24
|
+
# ** +:ssl_cert
|
25
|
+
# ** +:ssl_cert_type
|
26
|
+
# ** +:ssl_key
|
27
|
+
# ** +:ssl_key_type
|
28
|
+
# ** +:ssl_key_password
|
29
|
+
# ** +:ssl_cacert
|
30
|
+
# ** +:ssl_capath
|
31
|
+
#
|
6
32
|
def initialize(url, options = {})
|
7
33
|
@method = options[:method] || :get
|
8
34
|
@params = options[:params]
|
@@ -15,6 +41,13 @@ module Typhoeus
|
|
15
41
|
@max_redirects = options[:max_redirects]
|
16
42
|
@proxy = options[:proxy]
|
17
43
|
@disable_ssl_peer_verification = options[:disable_ssl_peer_verification]
|
44
|
+
@ssl_cert = options[:ssl_cert]
|
45
|
+
@ssl_cert_type = options[:ssl_cert_type]
|
46
|
+
@ssl_key = options[:ssl_key]
|
47
|
+
@ssl_key_type = options[:ssl_key_type]
|
48
|
+
@ssl_key_password = options[:ssl_key_password]
|
49
|
+
@ssl_cacert = options[:ssl_cacert]
|
50
|
+
@ssl_capath = options[:ssl_capath]
|
18
51
|
|
19
52
|
if @method == :post
|
20
53
|
@url = url
|
data/spec/typhoeus/easy_spec.rb
CHANGED
@@ -7,12 +7,12 @@ describe Typhoeus::Easy do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should return true if the version string has zlib" do
|
10
|
-
@easy.stub!(:
|
10
|
+
@easy.stub!(:curl_version).and_return("libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3 libidn/1.16")
|
11
11
|
@easy.supports_zlib?.should be_true
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should return false if the version string doesn't have zlib" do
|
15
|
-
@easy.stub!(:
|
15
|
+
@easy.stub!(:curl_version).and_return("libcurl/7.20.0 OpenSSL/0.9.8l libidn/1.16")
|
16
16
|
@easy.supports_zlib?.should be_false
|
17
17
|
end
|
18
18
|
end
|
@@ -117,6 +117,14 @@ describe Typhoeus::Easy do
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
+
describe "purge" do
|
121
|
+
it "should set custom request to purge" do
|
122
|
+
easy = Typhoeus::Easy.new
|
123
|
+
easy.should_receive(:set_option).with(Typhoeus::Easy::OPTION_VALUES[:CURLOPT_CUSTOMREQUEST], "PURGE").once
|
124
|
+
easy.method = :purge
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
120
128
|
describe "head" do
|
121
129
|
it "should perform a head" do
|
122
130
|
easy = Typhoeus::Easy.new
|
data/typhoeus.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{typhoeus}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.28"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Paul Dix"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-06-29}
|
13
13
|
s.description = %q{Like a modern code version of the mythical beast with 100 serpent heads, Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.}
|
14
14
|
s.email = %q{paul@pauldix.net}
|
15
15
|
s.extensions = ["ext/typhoeus/extconf.rb"]
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".gitignore",
|
21
|
+
"CHANGELOG.markdown",
|
21
22
|
"README.textile",
|
22
23
|
"Rakefile",
|
23
24
|
"VERSION",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 28
|
9
|
+
version: 0.1.28
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Paul Dix
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-06-29 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -99,6 +99,7 @@ extra_rdoc_files:
|
|
99
99
|
- README.textile
|
100
100
|
files:
|
101
101
|
- .gitignore
|
102
|
+
- CHANGELOG.markdown
|
102
103
|
- README.textile
|
103
104
|
- Rakefile
|
104
105
|
- VERSION
|