httpi 1.1.1 → 2.0.0.rc1
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/.gitignore +2 -0
- data/.rvmrc +1 -0
- data/CHANGELOG.md +51 -26
- data/Gemfile +6 -4
- data/README.md +19 -205
- data/httpi.gemspec +7 -10
- data/lib/httpi.rb +54 -56
- data/lib/httpi/adapter.rb +25 -18
- data/lib/httpi/adapter/base.rb +35 -0
- data/lib/httpi/adapter/curb.rb +59 -60
- data/lib/httpi/adapter/em_http.rb +126 -0
- data/lib/httpi/adapter/httpclient.rb +33 -63
- data/lib/httpi/adapter/net_http.rb +44 -62
- data/lib/httpi/auth/ssl.rb +26 -2
- data/lib/httpi/dime.rb +45 -29
- data/lib/httpi/request.rb +1 -1
- data/lib/httpi/response.rb +6 -4
- data/lib/httpi/version.rb +1 -1
- data/spec/httpi/adapter/base_spec.rb +23 -0
- data/spec/httpi/adapter/curb_spec.rb +107 -67
- data/spec/httpi/adapter/em_http_spec.rb +168 -0
- data/spec/httpi/adapter/httpclient_spec.rb +67 -56
- data/spec/httpi/adapter/net_http_spec.rb +62 -47
- data/spec/httpi/adapter_spec.rb +15 -2
- data/spec/httpi/auth/ssl_spec.rb +34 -1
- data/spec/httpi/httpi_spec.rb +80 -115
- data/spec/integration/fixtures/ca.pem +23 -0
- data/spec/integration/fixtures/ca_all.pem +44 -0
- data/spec/integration/fixtures/htdigest +1 -0
- data/spec/integration/fixtures/htpasswd +2 -0
- data/spec/integration/fixtures/server.cert +19 -0
- data/spec/integration/fixtures/server.key +15 -0
- data/spec/integration/fixtures/subca.pem +21 -0
- data/spec/integration/request_spec.rb +15 -2
- data/spec/integration/ssl_server.rb +70 -0
- data/spec/integration/ssl_spec.rb +102 -0
- data/spec/support/fixture.rb +1 -1
- metadata +60 -73
data/.gitignore
CHANGED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.3@httpi --create
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,31 @@
|
|
1
|
+
## 2.0.0.rc1
|
2
|
+
|
3
|
+
* Feature: [#63](https://github.com/savonrb/httpi/pull/63) adds support for
|
4
|
+
EventMachine::HttpRequest. Additional information at [#40](https://github.com/savonrb/httpi/pull/40).
|
5
|
+
|
6
|
+
* Feature: Added support for custom HTTP methods to clients supporting this feature.
|
7
|
+
It's limited to the `:httpclient` and `:em_http` adapter.
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
HTTPI.request(:custom, request)
|
11
|
+
```
|
12
|
+
|
13
|
+
* Improvement: [#64](https://github.com/savonrb/httpi/pull/64) adds support for
|
14
|
+
specifying the SSL version to use.
|
15
|
+
|
16
|
+
* Improvement: Log to `$stdout` (instead of `STDOUT`) using a default log level of
|
17
|
+
`:debug` (instead of `:warn`).
|
18
|
+
|
19
|
+
* Improvement: In case an adapter doesn't support a general feature, we now raise
|
20
|
+
an `HTTPI::NotSupportedError`.
|
21
|
+
|
22
|
+
* Improvement: Added support for adding custom adapters.
|
23
|
+
|
24
|
+
* Refactoring: Simplified the adapter interface.
|
25
|
+
|
1
26
|
## 1.1.1 (2012-07-01)
|
2
27
|
|
3
|
-
* Fix: [#56](https://github.com/
|
28
|
+
* Fix: [#56](https://github.com/savonrb/httpi/pull/56) ensures that the "Cookie"
|
4
29
|
header is not set to nil.
|
5
30
|
|
6
31
|
## 1.1.0 (2012-06-26)
|
@@ -10,15 +35,15 @@
|
|
10
35
|
|
11
36
|
## 1.0.0 (2012-06-07)
|
12
37
|
|
13
|
-
* Feature: [#48](https://github.com/
|
38
|
+
* Feature: [#48](https://github.com/savonrb/httpi/pull/48) @jheiss added support
|
14
39
|
for HTTP Negotiate/SPNEGO authentication (curb-specific).
|
15
40
|
|
16
|
-
* Fix: [#53](https://github.com/
|
41
|
+
* Fix: [#53](https://github.com/savonrb/httpi/issues/53) fixed an issue where
|
17
42
|
`HTTPI.log_level` did not do anything at all.
|
18
43
|
|
19
44
|
## 0.9.7 (2012-04-26)
|
20
45
|
|
21
|
-
* Fix: Merged [pull request 49](https://github.com/
|
46
|
+
* Fix: Merged [pull request 49](https://github.com/savonrb/httpi/pull/49) so that cert
|
22
47
|
and cert_key can be manually set.
|
23
48
|
|
24
49
|
* Fix: Stop auto-detecting gzipped responses by inspecting the response body to allow
|
@@ -26,22 +51,22 @@
|
|
26
51
|
|
27
52
|
## 0.9.6 (2012-02-23)
|
28
53
|
|
29
|
-
* Feature: Merged [pull request 46](https://github.com/
|
30
|
-
request body Hashes. Fixes [issue 45](https://github.com/
|
54
|
+
* Feature: Merged [pull request 46](https://github.com/savonrb/httpi/pull/46) to support
|
55
|
+
request body Hashes. Fixes [issue 45](https://github.com/savonrb/httpi/issues/45).
|
31
56
|
|
32
57
|
``` ruby
|
33
58
|
request.body = { :foo => :bar, :baz => :foo } # => "foo=bar&baz=foo"
|
34
59
|
```
|
35
60
|
|
36
|
-
* Feature: Merged [pull request 43](https://github.com/
|
61
|
+
* Feature: Merged [pull request 43](https://github.com/savonrb/httpi/pull/43) to allow
|
37
62
|
proxy authentication with net/http.
|
38
63
|
|
39
|
-
* Feature: Merged [pull request 42](https://github.com/
|
64
|
+
* Feature: Merged [pull request 42](https://github.com/savonrb/httpi/pull/42) which sets up
|
40
65
|
HTTP basic authentication if user information is present in the URL.
|
41
66
|
|
42
|
-
* Fix: Merged [pull request 44](https://github.com/
|
43
|
-
[issue 26](https://github.com/
|
44
|
-
[issue 32](https://github.com/
|
67
|
+
* Fix: Merged [pull request 44](https://github.com/savonrb/httpi/pull/44) to fix
|
68
|
+
[issue 26](https://github.com/savonrb/httpi/issues/26) and probably also
|
69
|
+
[issue 32](https://github.com/savonrb/httpi/issues/32) - SSL client authentication.
|
45
70
|
|
46
71
|
## 0.9.5 (2011-06-30)
|
47
72
|
|
@@ -51,8 +76,8 @@
|
|
51
76
|
|
52
77
|
## 0.9.4 (2011-05-15)
|
53
78
|
|
54
|
-
* Fix: issues [34](https://github.com/
|
55
|
-
[29](https://github.com/
|
79
|
+
* Fix: issues [34](https://github.com/savonrb/httpi/issues/34) and
|
80
|
+
[29](https://github.com/savonrb/httpi/issues/29) - replaced the dependency
|
56
81
|
on `ntlm-http` with a dependency on `pyu-ntlm-http` which comes with quite
|
57
82
|
a few bugfixes.
|
58
83
|
|
@@ -64,22 +89,22 @@
|
|
64
89
|
|
65
90
|
## 0.9.3 (2011-04-28)
|
66
91
|
|
67
|
-
* Fix: [issue 31](https://github.com/
|
92
|
+
* Fix: [issue 31](https://github.com/savonrb/httpi/issues/31) missing headers when using httpclient.
|
68
93
|
|
69
|
-
* Fix: [issue 30](https://github.com/
|
94
|
+
* Fix: [issue 30](https://github.com/savonrb/httpi/issues/30) fix for using SSL with Net::HTTP.
|
70
95
|
|
71
96
|
## 0.9.2 (2011-04-05)
|
72
97
|
|
73
|
-
* Fix: issues [161](https://github.com/
|
74
|
-
reported at [
|
98
|
+
* Fix: issues [161](https://github.com/savonrb/savon/issues/161) and [165](https://github.com/savonrb/savon/issues/165)
|
99
|
+
reported at [savonrb/savon](https://github.com/savonrb/savon).
|
75
100
|
|
76
101
|
## 0.9.1 (2011-04-04)
|
77
102
|
|
78
|
-
* Fix: [issue 25](https://github.com/
|
103
|
+
* Fix: [issue 25](https://github.com/savonrb/httpi/issues/22) problem with HTTPI using the Net::HTTP adapter [hakanensari].
|
79
104
|
|
80
105
|
## 0.9.0 (2011-03-08)
|
81
106
|
|
82
|
-
* Feature: improved the adapter loading process ([d4a091](https://github.com/
|
107
|
+
* Feature: improved the adapter loading process ([d4a091](https://github.com/savonrb/httpi/commit/d4a091)) [rubiii].
|
83
108
|
|
84
109
|
Instead of using HTTPClient as the default and falling back to NetHTTP, the loading process now does the following:
|
85
110
|
|
@@ -91,21 +116,21 @@
|
|
91
116
|
|
92
117
|
Of course you can still manually specify the adapter to use.
|
93
118
|
|
94
|
-
* Fix: [issue 22](https://github.com/
|
119
|
+
* Fix: [issue 22](https://github.com/savonrb/httpi/issues/22) argument error on logging adapter warning [rubiii].
|
95
120
|
|
96
|
-
* Fix: [issue 23](https://github.com/
|
121
|
+
* Fix: [issue 23](https://github.com/savonrb/httpi/issues/23) the HTTPI.log method now works as expected [rubiii].
|
97
122
|
|
98
123
|
## 0.8.0 (2011-03-07)
|
99
124
|
|
100
|
-
* Feature: added support for NTLM authentication ([96ceb1](https://github.com/
|
125
|
+
* Feature: added support for NTLM authentication ([96ceb1](https://github.com/savonrb/httpi/commit/96ceb1)) [MattHall].
|
101
126
|
|
102
127
|
You should now be able to use NTLM authentication by specifying your credentials via `HTTPI::Auth::Config#ntlm`:
|
103
128
|
|
104
129
|
request = HTTPI::Request.new
|
105
130
|
request.auth.ntlm "username", "password"
|
106
131
|
|
107
|
-
* Improvement: changed the default log level to :warn ([d01591](https://github.com/
|
108
|
-
and log at appropriate levels ([21ee1b](https://github.com/
|
132
|
+
* Improvement: changed the default log level to :warn ([d01591](https://github.com/savonrb/httpi/commit/d01591))
|
133
|
+
and log at appropriate levels ([21ee1b](https://github.com/savonrb/httpi/commit/21ee1b)) [ichverstehe].
|
109
134
|
|
110
|
-
* Fix: [issue 18](https://github.com/
|
111
|
-
([f3811b](https://github.com/
|
135
|
+
* Fix: [issue 18](https://github.com/savonrb/httpi/issues/18) don't mask exceptions in decoded_gzip_body
|
136
|
+
([f3811b](https://github.com/savonrb/httpi/commit/f3811b)) [fj].
|
data/Gemfile
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
source :rubygems
|
2
2
|
gemspec
|
3
3
|
|
4
|
-
gem "jruby-openssl",
|
4
|
+
gem "jruby-openssl", :platforms => :jruby
|
5
5
|
|
6
6
|
# http clients
|
7
|
-
gem "
|
8
|
-
gem "
|
9
|
-
gem "
|
7
|
+
gem "mock-server", :git => "https://github.com/djanowski/mock-server.git"
|
8
|
+
gem "httpclient", "~> 2.3", :require => false
|
9
|
+
gem "curb", "~> 0.8", :require => false, :platforms => :ruby
|
10
|
+
gem 'em-http-request', :require => false, :platforms => [:ruby, :jruby]
|
11
|
+
gem 'em-synchrony', :require => false, :platforms => [:ruby, :jruby]
|
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
HTTPI [](http://travis-ci.org/savonrb/httpi)
|
2
2
|
=====
|
3
3
|
|
4
|
-
HTTPI provides a common interface for Ruby HTTP libraries.
|
4
|
+
HTTPI provides a common interface for Ruby's HTTP libraries.
|
5
5
|
|
6
|
-
[
|
6
|
+
[Documentation](http://httpirb.com) | [RDoc](http://rubydoc.info/gems/httpi) |
|
7
|
+
[Mailing list](https://groups.google.com/forum/#!forum/httpirb)
|
7
8
|
|
8
9
|
Installation
|
9
10
|
------------
|
@@ -15,217 +16,30 @@ $ gem install httpi
|
|
15
16
|
```
|
16
17
|
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
In order to provide a common interface, HTTPI provides the `HTTPI::Request` object for you to
|
22
|
-
configure your request. Here's a very simple GET request.
|
19
|
+
Introduction
|
20
|
+
------------
|
23
21
|
|
24
22
|
``` ruby
|
25
|
-
|
26
|
-
HTTPI.get request
|
27
|
-
```
|
28
|
-
|
29
|
-
To execute a POST request, you may want to specify a payload.
|
23
|
+
require "httpi"
|
30
24
|
|
31
|
-
|
25
|
+
# create a request object
|
32
26
|
request = HTTPI::Request.new
|
33
|
-
request.url = "http://post.example.com"
|
34
|
-
request.body = "some data"
|
35
|
-
|
36
|
-
HTTPI.post request
|
37
|
-
```
|
38
|
-
|
39
|
-
|
40
|
-
HTTPI
|
41
|
-
-----
|
42
|
-
|
43
|
-
The `HTTPI` module uses one of the available adapters to execute HTTP requests.
|
44
|
-
|
45
|
-
#### GET
|
46
|
-
|
47
|
-
``` ruby
|
48
|
-
HTTPI.get(request, adapter = nil)
|
49
|
-
HTTPI.get(url, adapter = nil)
|
50
|
-
```
|
51
|
-
|
52
|
-
#### POST
|
53
|
-
|
54
|
-
``` ruby
|
55
|
-
HTTPI.post(request, adapter = nil)
|
56
|
-
HTTPI.post(url, body, adapter = nil)
|
57
|
-
```
|
58
|
-
|
59
|
-
#### HEAD
|
60
|
-
|
61
|
-
``` ruby
|
62
|
-
HTTPI.head(request, adapter = nil)
|
63
|
-
HTTPI.head(url, adapter = nil)
|
64
|
-
```
|
65
|
-
|
66
|
-
#### PUT
|
67
|
-
|
68
|
-
``` ruby
|
69
|
-
HTTPI.put(request, adapter = nil)
|
70
|
-
HTTPI.put(url, body, adapter = nil)
|
71
|
-
```
|
72
|
-
|
73
|
-
#### DELETE
|
74
|
-
|
75
|
-
``` ruby
|
76
|
-
HTTPI.delete(request, adapter = nil)
|
77
|
-
HTTPI.delete(url, adapter = nil)
|
78
|
-
```
|
79
|
-
|
80
|
-
#### Notice
|
81
|
-
|
82
|
-
* You can specify the adapter to use per request
|
83
|
-
* And request methods always return an `HTTPI::Response`
|
84
|
-
|
85
|
-
#### More control
|
86
|
-
|
87
|
-
If you need more control over the request, you can access the HTTP client instance
|
88
|
-
represented by your adapter in a block:
|
89
|
-
|
90
|
-
``` ruby
|
91
|
-
HTTPI.post request do |http|
|
92
|
-
http.use_ssl = true # Curb example
|
93
|
-
end
|
94
|
-
```
|
95
|
-
|
96
|
-
|
97
|
-
HTTPI::Adapter
|
98
|
-
--------------
|
99
|
-
|
100
|
-
HTTPI uses adapters to support multiple HTTP libraries.
|
101
|
-
It currently contains adapters for:
|
102
|
-
|
103
|
-
* [httpclient](http://rubygems.org/gems/httpclient) ~> 2.1.5
|
104
|
-
* [curb](http://rubygems.org/gems/curb) ~> 0.7.8
|
105
|
-
* [net/http](http://ruby-doc.org/stdlib/libdoc/net/http/rdoc)
|
106
|
-
|
107
|
-
You can manually specify the adapter to use via:
|
108
|
-
|
109
|
-
``` ruby
|
110
|
-
HTTPI.adapter = :curb # or one of [:httpclient, :net_http]
|
111
|
-
```
|
112
|
-
|
113
|
-
If you don't specify which adapter to use, HTTPI will try to load HTTPClient, then Curb and finally NetHTTP.
|
114
|
-
|
115
|
-
#### Notice
|
116
|
-
|
117
|
-
HTTPI does not force you to install any of these libraries. If you'd like to use on of the more advanced
|
118
|
-
libraries (HTTPClient or Curb), you have to make sure they're in your LOAD_PATH. HTTPI will then load the
|
119
|
-
library when executing HTTP requests.
|
120
|
-
|
121
|
-
|
122
|
-
HTTPI::Request
|
123
|
-
--------------
|
124
|
-
|
125
|
-
#### URL
|
126
|
-
|
127
|
-
``` ruby
|
128
27
|
request.url = "http://example.com"
|
129
|
-
request.url # => #<URI::HTTP:0x101c1ab18 URL:http://example.com>
|
130
|
-
```
|
131
28
|
|
132
|
-
|
133
|
-
|
134
|
-
``` ruby
|
135
|
-
request.proxy = "http://example.com"
|
136
|
-
request.proxy # => #<URI::HTTP:0x101c1ab18 URL:http://example.com>
|
137
|
-
```
|
29
|
+
# and pass it to a request method
|
30
|
+
HTTPI.get(request)
|
138
31
|
|
139
|
-
|
32
|
+
# use a specific adapter per request
|
33
|
+
HTTPI.get(request, :curb)
|
140
34
|
|
141
|
-
|
142
|
-
|
143
|
-
request.headers = { "Accept-Charset" => "utf-8" }
|
144
|
-
request.headers # => { "Accept-Charset" => "utf-8" }
|
145
|
-
```
|
146
|
-
|
147
|
-
#### Body
|
148
|
-
|
149
|
-
``` ruby
|
150
|
-
request.body = "some data"
|
151
|
-
request.body # => "some data"
|
152
|
-
```
|
35
|
+
# or specify a global adapter to use
|
36
|
+
HTTPI.adapter = :httpclient
|
153
37
|
|
154
|
-
|
155
|
-
|
156
|
-
``` ruby
|
157
|
-
request.open_timeout = 30 # sec
|
158
|
-
```
|
159
|
-
|
160
|
-
#### Read timeout
|
161
|
-
|
162
|
-
``` ruby
|
163
|
-
request.read_timeout = 30 # sec
|
164
|
-
```
|
165
|
-
|
166
|
-
|
167
|
-
HTTPI::Auth
|
168
|
-
-----------
|
169
|
-
|
170
|
-
`HTTPI::Auth` supports HTTP basic, digest and Negotiate/SPNEGO authentication.
|
171
|
-
|
172
|
-
``` ruby
|
173
|
-
request.auth.basic("username", "password") # HTTP basic auth credentials
|
174
|
-
request.auth.digest("username", "password") # HTTP digest auth credentials
|
175
|
-
request.auth.gssnegotiate # HTTP Negotiate/SPNEGO (aka Kerberos)
|
38
|
+
# and execute arbitary requests
|
39
|
+
HTTPI.request(:custom, request)
|
176
40
|
```
|
177
41
|
|
178
|
-
|
42
|
+
Documentation
|
43
|
+
-------------
|
179
44
|
|
180
|
-
|
181
|
-
gem and provide feedback.
|
182
|
-
|
183
|
-
``` ruby
|
184
|
-
request.auth.ntlm("username", "password") # NTLM auth credentials
|
185
|
-
```
|
186
|
-
|
187
|
-
HTTPI::Auth::SSL
|
188
|
-
----------------
|
189
|
-
|
190
|
-
`HTTPI::Auth::SSL` manages SSL client authentication.
|
191
|
-
|
192
|
-
``` ruby
|
193
|
-
request.auth.ssl.cert_key_file = "client_key.pem" # the private key file to use
|
194
|
-
request.auth.ssl.cert_key_password = "C3rtP@ssw0rd" # the key file's password
|
195
|
-
request.auth.ssl.cert_file = "client_cert.pem" # the certificate file to use
|
196
|
-
request.auth.ssl.ca_cert_file = "ca_cert.pem" # the ca certificate file to use
|
197
|
-
request.auth.ssl.verify_mode = :none # or one of [:peer, :fail_if_no_peer_cert, :client_once]
|
198
|
-
```
|
199
|
-
|
200
|
-
|
201
|
-
HTTPI::Response
|
202
|
-
---------------
|
203
|
-
|
204
|
-
Every request returns an `HTTPI::Response`. It contains the response code, headers and body.
|
205
|
-
|
206
|
-
``` ruby
|
207
|
-
response = HTTPI.get request
|
208
|
-
|
209
|
-
response.code # => 200
|
210
|
-
response.headers # => { "Content-Encoding" => "gzip" }
|
211
|
-
response.body # => "<!DOCTYPE HTML PUBLIC ...>"
|
212
|
-
```
|
213
|
-
|
214
|
-
The `response.body` handles gzipped and [DIME](http://en.wikipedia.org/wiki/Direct_Internet_Message_Encapsulation) encoded responses.
|
215
|
-
|
216
|
-
#### TODO
|
217
|
-
|
218
|
-
* Return the original `HTTPI::Request` for debugging purposes
|
219
|
-
* Return the time it took to execute the request
|
220
|
-
|
221
|
-
|
222
|
-
Logging
|
223
|
-
-------
|
224
|
-
|
225
|
-
HTTPI by default logs each HTTP request to STDOUT using a log level of :debug.
|
226
|
-
|
227
|
-
``` ruby
|
228
|
-
HTTPI.log = false # disable logging
|
229
|
-
HTTPI.logger = MyLogger # change the logger
|
230
|
-
HTTPI.log_level = :info # change the log level
|
231
|
-
```
|
45
|
+
Continue reading at [httpirb.com](http://httpirb.com)
|
data/httpi.gemspec
CHANGED
@@ -8,21 +8,18 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.version = HTTPI::VERSION
|
9
9
|
s.authors = ["Daniel Harrington", "Martin Tepper"]
|
10
10
|
s.email = "me@rubiii.com"
|
11
|
-
s.homepage = "http://github.com/
|
12
|
-
s.summary = "
|
13
|
-
s.description = "HTTPI provides a common interface for Ruby HTTP libraries
|
11
|
+
s.homepage = "http://github.com/savonrb/#{s.name}"
|
12
|
+
s.summary = "Common interface for Ruby's HTTP libraries"
|
13
|
+
s.description = "HTTPI provides a common interface for Ruby's HTTP libraries"
|
14
14
|
|
15
15
|
s.rubyforge_project = s.name
|
16
16
|
|
17
17
|
s.add_dependency "rack"
|
18
18
|
|
19
|
-
s.add_development_dependency "rake", "~> 0.
|
20
|
-
s.add_development_dependency "rspec", "~> 2.
|
21
|
-
s.add_development_dependency "mocha", "~> 0.
|
22
|
-
s.add_development_dependency "webmock", "~> 1.
|
23
|
-
|
24
|
-
s.add_development_dependency "autotest"
|
25
|
-
s.add_development_dependency "ZenTest", "4.5.0"
|
19
|
+
s.add_development_dependency "rake", "~> 0.9"
|
20
|
+
s.add_development_dependency "rspec", "~> 2.11"
|
21
|
+
s.add_development_dependency "mocha", "~> 0.12"
|
22
|
+
s.add_development_dependency "webmock", "~> 1.8"
|
26
23
|
|
27
24
|
s.files = `git ls-files`.split("\n")
|
28
25
|
s.require_path = "lib"
|