httpi 2.2.1 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/httpi.rb +9 -1
- data/lib/httpi/auth/ssl.rb +2 -2
- data/lib/httpi/request.rb +8 -1
- data/lib/httpi/version.rb +1 -1
- data/spec/httpi/httpi_spec.rb +16 -2
- data/spec/httpi/request_spec.rb +13 -2
- metadata +19 -5
- checksums.yaml +0 -15
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
### 2.2.2 (edge)
|
2
|
+
|
3
|
+
* Feature: [#118](https://github.com/savonrb/httpi/pull/118) Support for other SSL certificate keys, not only RSA. Thanks to [Novikov Andrey](https://github.com/Envek).
|
4
|
+
|
1
5
|
### 2.2.1 (2014-06-11)
|
2
6
|
|
3
7
|
* Fix: [#116](https://github.com/savonrb/httpi/pull/116) Fix NoMethodError when not using NTLM.
|
data/lib/httpi.rb
CHANGED
@@ -136,7 +136,15 @@ module HTTPI
|
|
136
136
|
yield adapter_class.client if block_given?
|
137
137
|
log_request(method, request, Adapter.identify(adapter_class.class))
|
138
138
|
|
139
|
-
adapter_class.request(method)
|
139
|
+
response = adapter_class.request(method)
|
140
|
+
|
141
|
+
if response and response.code == 302 and request.follow_redirect?
|
142
|
+
log('Following redirect...')
|
143
|
+
request.url = response.headers['location']
|
144
|
+
return request(method, request, adapter)
|
145
|
+
end
|
146
|
+
|
147
|
+
response
|
140
148
|
end
|
141
149
|
|
142
150
|
# Shortcut for setting the default adapter to use.
|
data/lib/httpi/auth/ssl.rb
CHANGED
@@ -92,9 +92,9 @@ module HTTPI
|
|
92
92
|
# Sets the +OpenSSL+ ca certificate.
|
93
93
|
attr_writer :ca_cert
|
94
94
|
|
95
|
-
# Returns an <tt>OpenSSL::PKey::RSA</tt> for the +cert_key_file+.
|
95
|
+
# Returns an <tt>OpenSSL::PKey</tt> subclass (usually <tt>OpenSSL::PKey::RSA</tt>) for the +cert_key_file+.
|
96
96
|
def cert_key
|
97
|
-
@cert_key ||= (OpenSSL::PKey
|
97
|
+
@cert_key ||= (OpenSSL::PKey.read(File.read(cert_key_file), cert_key_password) if cert_key_file)
|
98
98
|
end
|
99
99
|
|
100
100
|
# Sets the +OpenSSL+ certificate key.
|
data/lib/httpi/request.rb
CHANGED
@@ -11,7 +11,7 @@ module HTTPI
|
|
11
11
|
class Request
|
12
12
|
|
13
13
|
# Available attribute writers.
|
14
|
-
ATTRIBUTES = [:url, :proxy, :headers, :body, :open_timeout, :read_timeout]
|
14
|
+
ATTRIBUTES = [:url, :proxy, :headers, :body, :open_timeout, :read_timeout, :follow_redirect]
|
15
15
|
|
16
16
|
# Accepts a Hash of +args+ to mass assign attributes and authentication credentials.
|
17
17
|
def initialize(args = {})
|
@@ -123,6 +123,13 @@ module HTTPI
|
|
123
123
|
ATTRIBUTES.each { |key| send("#{key}=", args[key]) if args[key] }
|
124
124
|
end
|
125
125
|
|
126
|
+
attr_writer :follow_redirect
|
127
|
+
|
128
|
+
# Returns whether or not redirects should be followed - defaults to false if not set.
|
129
|
+
def follow_redirect?
|
130
|
+
@follow_redirect ||= false
|
131
|
+
end
|
132
|
+
|
126
133
|
private
|
127
134
|
|
128
135
|
# Stores the cookies from past requests.
|
data/lib/httpi/version.rb
CHANGED
data/spec/httpi/httpi_spec.rb
CHANGED
@@ -195,12 +195,26 @@ describe HTTPI do
|
|
195
195
|
end
|
196
196
|
|
197
197
|
describe ".request" do
|
198
|
+
let(:request) { HTTPI::Request.new('http://example.com') }
|
199
|
+
|
198
200
|
it "allows custom HTTP methods" do
|
199
|
-
request = HTTPI::Request.new("http://example.com")
|
200
201
|
httpclient.any_instance.expects(:request).with(:custom)
|
201
202
|
|
202
203
|
client.request(:custom, request, :httpclient)
|
203
204
|
end
|
205
|
+
|
206
|
+
it 'follows redirects' do
|
207
|
+
request.follow_redirect = true
|
208
|
+
redirect_location = 'http://foo.bar'
|
209
|
+
|
210
|
+
redirect = HTTPI::Response.new(302, {'location' => redirect_location}, 'Moved')
|
211
|
+
response = HTTPI::Response.new(200, {}, 'success')
|
212
|
+
|
213
|
+
httpclient.any_instance.expects(:request).twice.with(:custom).returns(redirect, response)
|
214
|
+
request.expects(:url=).with(redirect_location)
|
215
|
+
|
216
|
+
client.request(:custom, request, :httpclient)
|
217
|
+
end
|
204
218
|
end
|
205
219
|
|
206
220
|
HTTPI::REQUEST_METHODS.each do |method|
|
@@ -249,7 +263,7 @@ describe HTTPI do
|
|
249
263
|
|
250
264
|
describe ".log" do
|
251
265
|
it "defaults to true" do
|
252
|
-
expect(HTTPI.log?).to
|
266
|
+
expect(HTTPI.log?).to be_truthy
|
253
267
|
end
|
254
268
|
end
|
255
269
|
|
data/spec/httpi/request_spec.rb
CHANGED
@@ -206,11 +206,22 @@ describe HTTPI::Request do
|
|
206
206
|
describe "#auth?" do
|
207
207
|
it "returns true when auth credentials are specified" do
|
208
208
|
request.auth.basic "username", "password"
|
209
|
-
expect(request.auth?).to
|
209
|
+
expect(request.auth?).to be_truthy
|
210
210
|
end
|
211
211
|
|
212
212
|
it "returns false otherwise" do
|
213
|
-
expect(request.auth?).to
|
213
|
+
expect(request.auth?).to be_falsey
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe '#follow_redirect?' do
|
218
|
+
it 'returns true when follow_redirect is set to true' do
|
219
|
+
request.follow_redirect = true
|
220
|
+
expect(request.follow_redirect?).to be_truthy
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'returns false by default' do
|
224
|
+
expect(request.follow_redirect?).to be_falsey
|
214
225
|
end
|
215
226
|
end
|
216
227
|
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.3
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Daniel Harrington
|
@@ -9,11 +10,12 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
13
|
+
date: 2014-06-26 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rack
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
20
|
- - ! '>='
|
19
21
|
- !ruby/object:Gem::Version
|
@@ -21,6 +23,7 @@ dependencies:
|
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
28
|
- - ! '>='
|
26
29
|
- !ruby/object:Gem::Version
|
@@ -28,6 +31,7 @@ dependencies:
|
|
28
31
|
- !ruby/object:Gem::Dependency
|
29
32
|
name: rubyntlm
|
30
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
31
35
|
requirements:
|
32
36
|
- - ~>
|
33
37
|
- !ruby/object:Gem::Version
|
@@ -35,6 +39,7 @@ dependencies:
|
|
35
39
|
type: :development
|
36
40
|
prerelease: false
|
37
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
38
43
|
requirements:
|
39
44
|
- - ~>
|
40
45
|
- !ruby/object:Gem::Version
|
@@ -42,6 +47,7 @@ dependencies:
|
|
42
47
|
- !ruby/object:Gem::Dependency
|
43
48
|
name: rake
|
44
49
|
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
45
51
|
requirements:
|
46
52
|
- - ~>
|
47
53
|
- !ruby/object:Gem::Version
|
@@ -49,6 +55,7 @@ dependencies:
|
|
49
55
|
type: :development
|
50
56
|
prerelease: false
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
52
59
|
requirements:
|
53
60
|
- - ~>
|
54
61
|
- !ruby/object:Gem::Version
|
@@ -56,6 +63,7 @@ dependencies:
|
|
56
63
|
- !ruby/object:Gem::Dependency
|
57
64
|
name: rspec
|
58
65
|
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
59
67
|
requirements:
|
60
68
|
- - ~>
|
61
69
|
- !ruby/object:Gem::Version
|
@@ -63,6 +71,7 @@ dependencies:
|
|
63
71
|
type: :development
|
64
72
|
prerelease: false
|
65
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
66
75
|
requirements:
|
67
76
|
- - ~>
|
68
77
|
- !ruby/object:Gem::Version
|
@@ -70,6 +79,7 @@ dependencies:
|
|
70
79
|
- !ruby/object:Gem::Dependency
|
71
80
|
name: mocha
|
72
81
|
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
73
83
|
requirements:
|
74
84
|
- - ~>
|
75
85
|
- !ruby/object:Gem::Version
|
@@ -77,6 +87,7 @@ dependencies:
|
|
77
87
|
type: :development
|
78
88
|
prerelease: false
|
79
89
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
80
91
|
requirements:
|
81
92
|
- - ~>
|
82
93
|
- !ruby/object:Gem::Version
|
@@ -84,6 +95,7 @@ dependencies:
|
|
84
95
|
- !ruby/object:Gem::Dependency
|
85
96
|
name: puma
|
86
97
|
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
87
99
|
requirements:
|
88
100
|
- - ~>
|
89
101
|
- !ruby/object:Gem::Version
|
@@ -91,6 +103,7 @@ dependencies:
|
|
91
103
|
type: :development
|
92
104
|
prerelease: false
|
93
105
|
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
94
107
|
requirements:
|
95
108
|
- - ~>
|
96
109
|
- !ruby/object:Gem::Version
|
@@ -170,25 +183,26 @@ files:
|
|
170
183
|
homepage: http://github.com/savonrb/#{s.name}
|
171
184
|
licenses:
|
172
185
|
- MIT
|
173
|
-
metadata: {}
|
174
186
|
post_install_message:
|
175
187
|
rdoc_options: []
|
176
188
|
require_paths:
|
177
189
|
- lib
|
178
190
|
required_ruby_version: !ruby/object:Gem::Requirement
|
191
|
+
none: false
|
179
192
|
requirements:
|
180
193
|
- - ! '>='
|
181
194
|
- !ruby/object:Gem::Version
|
182
195
|
version: '0'
|
183
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
|
+
none: false
|
184
198
|
requirements:
|
185
199
|
- - ! '>='
|
186
200
|
- !ruby/object:Gem::Version
|
187
201
|
version: '0'
|
188
202
|
requirements: []
|
189
203
|
rubyforge_project: httpi
|
190
|
-
rubygems_version:
|
204
|
+
rubygems_version: 1.8.23
|
191
205
|
signing_key:
|
192
|
-
specification_version:
|
206
|
+
specification_version: 3
|
193
207
|
summary: Common interface for Ruby's HTTP libraries
|
194
208
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
ZDM4YmYwM2E3NWM1YzQ4OGQ3MWZkNWIxNGVhZTIwZDEzOWYyMmJiOA==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZTU1NmUxZDRlMjczZjRjMDFkNjZhZGM5Mjc5ZWFiZTJlNzQ5ZWQ3NQ==
|
7
|
-
SHA512:
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MWNiMjU5ZmQxYzRjODI2ZWZhNjAyNjBiZDkwMmUzMjY4NDY4ZDQyM2RiMDMx
|
10
|
-
NTlhOWRlMDdlM2Q1Y2E2ZjZlMDkzMGIwNWIyMjU2NTE1MzBjYTEwMzllOWE0
|
11
|
-
Y2FmNWUwZDY5OWFmODM2ZWEyYTc4MTI5MWNlMjdiZjhlMjI1NWE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NjU1MzY3YWQ1MWVjNzlmYWNjNjE3MWJjOGMzMTIyY2E5NmJlNzJjYjFjNGI0
|
14
|
-
NDc0NjcwZGY4OTIwYzQ2MTQ5OThjNzZmZjUzMGYzYzE0ZGE4NzIwNjU4OWJm
|
15
|
-
ZTI1Nzc1OGVkZTRjMDI2ZmM3YzZmMGQ1ZDUzNjA1MTRmZTZmZjc=
|