httpi 2.0.2 → 2.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3d93398828eb1001de0ffda175e251a037fb4f4
4
+ data.tar.gz: 581d420ec8ca101e584d841a47e02e5e7fb5b58e
5
+ SHA512:
6
+ metadata.gz: 37348af815f82aff80b024c08eb191b0ce4a2d9e6d05a5be22a8570dbe1c74683a37ff79e70d91cdc3c68fdabead56b7004871d261054f1fb2adb427b548ffb2
7
+ data.tar.gz: 2a41f0b5b86595280e23dbce2524d7badb438ec00e7fa1e11ea0b46c7bde52801cde382e9f49691a55cca260b55b2a255285e9af8d7ef778476ab289ecea8828
data/CHANGELOG.md CHANGED
@@ -1,14 +1,40 @@
1
- ## 2.0.2 (2013-01-26)
1
+ ### 2.1.0 (2013-07-22)
2
+
3
+ * Feature: [#75](https://github.com/savonrb/httpi/pull/75) Rack adapter.
4
+
5
+ * Feature: [#91](https://github.com/savonrb/httpi/pull/91) New excon adapter.
6
+
7
+ * Feature: [#92](https://github.com/savonrb/httpi/pull/92) New net-http-persistent adapter.
8
+
9
+ * Feature: [#87](https://github.com/savonrb/httpi/pull/87) NTLM support with full domain and server authentication.
10
+
11
+ * Feature: [#71](https://github.com/savonrb/httpi/pull/71) chunked responses.
12
+
13
+ * Fix: [#81](https://github.com/savonrb/httpi/issues/81) send SSL client certificate
14
+ even when `:ssl_verify_mode` is set to `:none`.
15
+
16
+ * Fix: [#69](https://github.com/savonrb/httpi/issues/69) truncating response headers.
17
+
18
+ * Fix: [#88](https://github.com/savonrb/httpi/issues/88) timeout and proxy options
19
+ are now properly passed to the EM-HTTP-Request client.
20
+
21
+ * Fix: [#69](https://github.com/savonrb/httpi/issues/69) Fixes a problem where the response headers were truncated.
22
+
23
+ * Fix: [#90](https://github.com/savonrb/httpi/issues/90) we now raise an error if
24
+ you try to use Net::HTTP with HTTP digest authentication, because Net::HTTP does
25
+ not support digest authentication.
26
+
27
+ ### 2.0.2 (2013-01-26)
2
28
 
3
29
  * Feature: Changed `HTTPI::Request#set_cookies` to accept an Array of `HTTPI::Cookie`
4
30
  objects as well as any object that responds to `cookies` (like an `HTTPI::Response`).
5
31
 
6
- ## 2.0.1 (2013-01-25)
32
+ ### 2.0.1 (2013-01-25)
7
33
 
8
34
  * Fix: [#72](https://github.com/savonrb/httpi/pull/72) standardized response
9
35
  headers from all adapters.
10
36
 
11
- ## 2.0.0 (2012-12-16)
37
+ ### 2.0.0 (2012-12-16)
12
38
 
13
39
  * Feature: [#66](https://github.com/savonrb/httpi/pull/66) adds a `query` method
14
40
  to the request.
@@ -16,7 +42,7 @@
16
42
  * Fix: [#68](https://github.com/savonrb/httpi/issues/68) request does not yield
17
43
  adapter client.
18
44
 
19
- ## 2.0.0.rc1 (2012-11-10)
45
+ ### 2.0.0.rc1 (2012-11-10)
20
46
 
21
47
  * Feature: [#63](https://github.com/savonrb/httpi/pull/63) adds support for
22
48
  EventMachine::HttpRequest. Additional information at [#40](https://github.com/savonrb/httpi/pull/40).
@@ -41,17 +67,17 @@
41
67
 
42
68
  * Refactoring: Simplified the adapter interface.
43
69
 
44
- ## 1.1.1 (2012-07-01)
70
+ ### 1.1.1 (2012-07-01)
45
71
 
46
72
  * Fix: [#56](https://github.com/savonrb/httpi/pull/56) ensures that the "Cookie"
47
73
  header is not set to nil.
48
74
 
49
- ## 1.1.0 (2012-06-26)
75
+ ### 1.1.0 (2012-06-26)
50
76
 
51
77
  * Refactoring: Moved code that sets the cookies from the last response for the
52
78
  next request from Savon to `HTTPI::Request#set_cookies`.
53
79
 
54
- ## 1.0.0 (2012-06-07)
80
+ ### 1.0.0 (2012-06-07)
55
81
 
56
82
  * Feature: [#48](https://github.com/savonrb/httpi/pull/48) @jheiss added support
57
83
  for HTTP Negotiate/SPNEGO authentication (curb-specific).
@@ -59,7 +85,7 @@
59
85
  * Fix: [#53](https://github.com/savonrb/httpi/issues/53) fixed an issue where
60
86
  `HTTPI.log_level` did not do anything at all.
61
87
 
62
- ## 0.9.7 (2012-04-26)
88
+ ### 0.9.7 (2012-04-26)
63
89
 
64
90
  * Fix: Merged [pull request 49](https://github.com/savonrb/httpi/pull/49) so that cert
65
91
  and cert_key can be manually set.
@@ -67,7 +93,7 @@
67
93
  * Fix: Stop auto-detecting gzipped responses by inspecting the response body to allow
68
94
  response compression only.
69
95
 
70
- ## 0.9.6 (2012-02-23)
96
+ ### 0.9.6 (2012-02-23)
71
97
 
72
98
  * Feature: Merged [pull request 46](https://github.com/savonrb/httpi/pull/46) to support
73
99
  request body Hashes. Fixes [issue 45](https://github.com/savonrb/httpi/issues/45).
@@ -86,13 +112,13 @@
86
112
  [issue 26](https://github.com/savonrb/httpi/issues/26) and probably also
87
113
  [issue 32](https://github.com/savonrb/httpi/issues/32) - SSL client authentication.
88
114
 
89
- ## 0.9.5 (2011-06-30)
115
+ ### 0.9.5 (2011-06-30)
90
116
 
91
117
  * Improvement: Moved support for NTLM authentication into a separate gem.
92
118
  Since NTLM support caused quite some problems for people who didn't even
93
119
  need it, I decided to move it into httpi-ntlm until it's stable.
94
120
 
95
- ## 0.9.4 (2011-05-15)
121
+ ### 0.9.4 (2011-05-15)
96
122
 
97
123
  * Fix: issues [34](https://github.com/savonrb/httpi/issues/34) and
98
124
  [29](https://github.com/savonrb/httpi/issues/29) - replaced the dependency
@@ -105,22 +131,22 @@
105
131
 
106
132
  HTTPI.adapter = :net_http
107
133
 
108
- ## 0.9.3 (2011-04-28)
134
+ ### 0.9.3 (2011-04-28)
109
135
 
110
136
  * Fix: [issue 31](https://github.com/savonrb/httpi/issues/31) missing headers when using httpclient.
111
137
 
112
138
  * Fix: [issue 30](https://github.com/savonrb/httpi/issues/30) fix for using SSL with Net::HTTP.
113
139
 
114
- ## 0.9.2 (2011-04-05)
140
+ ### 0.9.2 (2011-04-05)
115
141
 
116
142
  * Fix: issues [161](https://github.com/savonrb/savon/issues/161) and [165](https://github.com/savonrb/savon/issues/165)
117
143
  reported at [savonrb/savon](https://github.com/savonrb/savon).
118
144
 
119
- ## 0.9.1 (2011-04-04)
145
+ ### 0.9.1 (2011-04-04)
120
146
 
121
147
  * Fix: [issue 25](https://github.com/savonrb/httpi/issues/22) problem with HTTPI using the Net::HTTP adapter [hakanensari].
122
148
 
123
- ## 0.9.0 (2011-03-08)
149
+ ### 0.9.0 (2011-03-08)
124
150
 
125
151
  * Feature: improved the adapter loading process ([d4a091](https://github.com/savonrb/httpi/commit/d4a091)) [rubiii].
126
152
 
@@ -138,7 +164,7 @@
138
164
 
139
165
  * Fix: [issue 23](https://github.com/savonrb/httpi/issues/23) the HTTPI.log method now works as expected [rubiii].
140
166
 
141
- ## 0.8.0 (2011-03-07)
167
+ ### 0.8.0 (2011-03-07)
142
168
 
143
169
  * Feature: added support for NTLM authentication ([96ceb1](https://github.com/savonrb/httpi/commit/96ceb1)) [MattHall].
144
170
 
data/Gemfile CHANGED
@@ -1,10 +1,16 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
- gem "jruby-openssl", :platforms => :jruby
4
+ gem 'jruby-openssl', :platforms => :jruby
5
5
 
6
6
  # http clients
7
- gem "httpclient", "~> 2.3", :require => false
8
- gem "curb", "~> 0.8", :require => false, :platforms => :ruby
9
- gem 'em-http-request', :require => false, :platforms => [:ruby, :jruby]
10
- gem 'em-synchrony', :require => false, :platforms => [:ruby, :jruby]
7
+ gem 'httpclient', '~> 2.3', :require => false
8
+ gem 'curb', '~> 0.8', :require => false, :platforms => :ruby
9
+ gem 'em-http-request', :require => false, :platforms => [:ruby, :jruby]
10
+ gem 'em-synchrony', :require => false, :platforms => [:ruby, :jruby]
11
+ gem 'excon', '~> 0.21.0', :require => false, :platforms => [:ruby, :jruby]
12
+ gem 'net-http-persistent', '~> 2.8', :require => false
13
+
14
+ # coverage
15
+ gem 'simplecov', :require => false
16
+ gem 'coveralls', :require => false
data/README.md CHANGED
@@ -1,13 +1,17 @@
1
- HTTPI [![Build Status](https://secure.travis-ci.org/savonrb/httpi.png)](http://travis-ci.org/savonrb/httpi)
2
- =====
1
+ # HTTPI
3
2
 
4
- HTTPI provides a common interface for Ruby's HTTP libraries.
3
+ A common interface for Ruby's HTTP libraries.
5
4
 
6
5
  [Documentation](http://httpirb.com) | [RDoc](http://rubydoc.info/gems/httpi) |
7
6
  [Mailing list](https://groups.google.com/forum/#!forum/httpirb)
8
7
 
9
- Installation
10
- ------------
8
+ [![Build Status](https://secure.travis-ci.org/savonrb/httpi.png?branch=master)](http://travis-ci.org/savonrb/httpi)
9
+ [![Gem Version](https://badge.fury.io/rb/httpi.png)](http://badge.fury.io/rb/httpi)
10
+ [![Code Climate](https://codeclimate.com/github/savonrb/httpi.png)](https://codeclimate.com/github/savonrb/httpi)
11
+ [![Coverage Status](https://coveralls.io/repos/savonrb/httpi/badge.png?branch=master)](https://coveralls.io/r/savonrb/httpi)
12
+
13
+
14
+ ## Installation
11
15
 
12
16
  HTTPI is available through [Rubygems](http://rubygems.org/gems/httpi) and can be installed via:
13
17
 
@@ -15,9 +19,15 @@ HTTPI is available through [Rubygems](http://rubygems.org/gems/httpi) and can be
15
19
  $ gem install httpi
16
20
  ```
17
21
 
22
+ or add it to your Gemfile like this:
23
+
24
+ ```
25
+ gem 'httpi', '~> 2.1.0'
26
+ ```
27
+
28
+
29
+ ## Usage example
18
30
 
19
- Introduction
20
- ------------
21
31
 
22
32
  ``` ruby
23
33
  require "httpi"
@@ -39,7 +49,7 @@ HTTPI.adapter = :httpclient
39
49
  HTTPI.request(:custom, request)
40
50
  ```
41
51
 
42
- Documentation
43
- -------------
52
+
53
+ ## Documentation
44
54
 
45
55
  Continue reading at [httpirb.com](http://httpirb.com)
data/httpi.gemspec CHANGED
@@ -15,11 +15,12 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = s.name
16
16
 
17
17
  s.add_dependency "rack"
18
+ s.add_dependency "rubyntlm", "~> 0.3.2"
18
19
 
19
20
  s.add_development_dependency "rake", "~> 10.0"
20
21
  s.add_development_dependency "rspec", "~> 2.12"
21
22
  s.add_development_dependency "mocha", "~> 0.13"
22
- s.add_development_dependency "puma", ">= 2.0.0.b3"
23
+ s.add_development_dependency "puma", "~> 2.3.2"
23
24
 
24
25
  s.files = `git ls-files`.split("\n")
25
26
  s.require_path = "lib"
data/lib/httpi.rb CHANGED
@@ -5,8 +5,11 @@ require "httpi/request"
5
5
 
6
6
  require "httpi/adapter/httpclient"
7
7
  require "httpi/adapter/curb"
8
+ require "httpi/adapter/excon"
8
9
  require "httpi/adapter/net_http"
10
+ require "httpi/adapter/net_http_persistent"
9
11
  require "httpi/adapter/em_http"
12
+ require "httpi/adapter/rack"
10
13
 
11
14
  # = HTTPI
12
15
  #
data/lib/httpi/adapter.rb CHANGED
@@ -13,7 +13,7 @@ module HTTPI
13
13
  ADAPTERS = {}
14
14
  ADAPTER_CLASS_MAP = {}
15
15
 
16
- LOAD_ORDER = [:httpclient, :curb, :em_http, :net_http]
16
+ LOAD_ORDER = [:httpclient, :curb, :em_http, :excon, :net_http, :net_http_persistent]
17
17
 
18
18
  class << self
19
19
 
@@ -29,6 +29,8 @@ module HTTPI
29
29
  arguments << (@request.body || "")
30
30
  end
31
31
 
32
+ client.on_body(&@request.on_body) if @request.on_body
33
+
32
34
  do_request { |client| client.send(*arguments) }
33
35
  rescue Curl::Err::SSLCACertificateError
34
36
  raise SSLError
@@ -49,6 +51,11 @@ module HTTPI
49
51
 
50
52
  def setup_client
51
53
  basic_setup
54
+
55
+ if @request.auth.ntlm?
56
+ raise NotSupportedError, "curb does not support NTLM authentication"
57
+ end
58
+
52
59
  setup_http_auth if @request.auth.http?
53
60
  setup_gssnegotiate_auth if @request.auth.gssnegotiate?
54
61
  setup_ssl_auth if @request.auth.ssl?
@@ -80,12 +87,14 @@ module HTTPI
80
87
  ssl = @request.auth.ssl
81
88
 
82
89
  unless ssl.verify_mode == :none
83
- @client.cert_key = ssl.cert_key_file
84
- @client.cert = ssl.cert_file
85
90
  @client.cacert = ssl.ca_cert_file if ssl.ca_cert_file
86
91
  @client.certtype = ssl.cert_type.to_s.upcase
87
92
  end
88
93
 
94
+ # Send client-side certificate regardless of state of SSL verify mode
95
+ @client.cert_key = ssl.cert_key_file
96
+ @client.cert = ssl.cert_file
97
+
89
98
  @client.ssl_verify_peer = ssl.verify_mode == :peer
90
99
  @client.ssl_version = case ssl.ssl_version
91
100
  when :TLSv1 then 1
@@ -33,7 +33,7 @@ module HTTPI
33
33
 
34
34
  def initialize(request)
35
35
  @request = request
36
- @client = EventMachine::HttpRequest.new build_request_url(request.url)
36
+ @client = EventMachine::HttpRequest.new build_request_url(request.url), connection_options
37
37
  end
38
38
 
39
39
  attr_reader :client
@@ -54,29 +54,41 @@ module HTTPI
54
54
 
55
55
  def _request
56
56
  options = client_options
57
- setup_proxy(options) if @request.proxy
58
57
  setup_http_auth(options) if @request.auth.http?
59
58
 
60
59
  if @request.auth.ssl?
61
60
  raise NotSupportedError, "EM-HTTP-Request does not support SSL client auth"
62
61
  end
63
62
 
63
+ if @request.on_body
64
+ raise NotSupportedError, "EM-HTTP-Request does not support response streaming"
65
+ end
66
+
64
67
  start_time = Time.now
65
68
  respond_with yield(options), start_time
66
69
  end
67
70
 
71
+ def connection_options
72
+ options = {
73
+ :connect_timeout => @request.open_timeout,
74
+ :inactivity_timeout => @request.read_timeout
75
+ }
76
+
77
+ options[:proxy] = proxy_options if @request.proxy
78
+
79
+ options
80
+ end
81
+
68
82
  def client_options
69
83
  {
70
- :query => @request.url.query,
71
- :connect_timeout => @request.open_timeout,
72
- :inactivity_timeout => @request.read_timeout,
73
- :head => @request.headers.to_hash,
74
- :body => @request.body
84
+ :query => @request.url.query,
85
+ :head => @request.headers.to_hash,
86
+ :body => @request.body
75
87
  }
76
88
  end
77
89
 
78
- def setup_proxy(options)
79
- options[:proxy] = {
90
+ def proxy_options
91
+ {
80
92
  :host => @request.proxy.host,
81
93
  :port => @request.proxy.port,
82
94
  :authorization => [@request.proxy.user, @request.proxy.password]
@@ -0,0 +1,80 @@
1
+ require "httpi/adapter/base"
2
+ require "httpi/response"
3
+
4
+ module HTTPI
5
+ module Adapter
6
+
7
+ # = HTTPI::Adapter::Excon
8
+ #
9
+ # Adapter for the Excon client.
10
+ # https://github.com/geemus/excon
11
+ class Excon < Base
12
+
13
+ register :excon, :deps => %w(excon)
14
+
15
+ def initialize(request)
16
+ @request = request
17
+ @client = ::Excon::Connection.new client_opts
18
+ end
19
+
20
+ attr_reader :client
21
+
22
+ # Executes arbitrary HTTP requests.
23
+ # @see HTTPI.request
24
+ def request(method)
25
+ respond_with @client.send(method)
26
+ rescue ::Excon::Errors::SocketError => e
27
+ case e.message
28
+ when /verify certificate/
29
+ raise SSLError
30
+ else
31
+ $!.extend ConnectionError
32
+ end
33
+ raise
34
+ end
35
+
36
+ private
37
+
38
+ def client_opts
39
+ url = @request.url
40
+ ssl = @request.auth.ssl
41
+
42
+ opts = {
43
+ :host => url.host,
44
+ :path => url.path,
45
+ :port => url.port.to_s,
46
+ :query => url.query,
47
+ :scheme => url.scheme,
48
+ :headers => @request.headers,
49
+ :body => @request.body
50
+ }
51
+
52
+ if @request.auth.digest?
53
+ raise NotSupportedError, "excon does not support HTTP digest authentication"
54
+ elsif @request.auth.ntlm?
55
+ raise NotSupportedError, "excon does not support NTLM authentication"
56
+ end
57
+
58
+ opts[:user], opts[:password] = *@request.auth.credentials if @request.auth.basic?
59
+ opts[:connect_timeout] = @request.open_timeout if @request.open_timeout
60
+ opts[:read_timeout] = @request.read_timeout if @request.read_timeout
61
+ opts[:response_block] = @request.on_body if @request.on_body
62
+ opts[:proxy] = @request.proxy if @request.proxy
63
+
64
+ if ssl.verify_mode == :peer
65
+ opts[:ssl_verify_peer] = true
66
+ opts[:ssl_ca_file] = ssl.ca_cert_file if ssl.ca_cert_file
67
+ opts[:client_cert] = ssl.cert if ssl.cert
68
+ opts[:client_key] = ssl.cert_key if ssl.cert_key
69
+ end
70
+
71
+ opts
72
+ end
73
+
74
+ def respond_with(response)
75
+ Response.new response.status, response.headers, response.body
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -23,7 +23,7 @@ module HTTPI
23
23
  # @see HTTPI.request
24
24
  def request(method)
25
25
  setup_client
26
- respond_with @client.request(method, @request.url, nil, @request.body, @request.headers)
26
+ respond_with @client.request(method, @request.url, nil, @request.body, @request.headers, &@request.on_body)
27
27
  rescue OpenSSL::SSL::SSLError
28
28
  raise SSLError
29
29
  rescue Errno::ECONNREFUSED # connection refused
@@ -35,6 +35,11 @@ module HTTPI
35
35
 
36
36
  def setup_client
37
37
  basic_setup
38
+
39
+ if @request.auth.ntlm?
40
+ raise NotSupportedError, "HTTPClient adapter does not support NTLM authentication"
41
+ end
42
+
38
43
  setup_auth if @request.auth.http?
39
44
  setup_ssl_auth if @request.auth.ssl?
40
45
  end
@@ -52,14 +57,16 @@ module HTTPI
52
57
  def setup_ssl_auth
53
58
  ssl = @request.auth.ssl
54
59
 
55
- unless ssl.verify_mode == :none
56
- @client.ssl_config.client_cert = ssl.cert
57
- @client.ssl_config.client_key = ssl.cert_key
58
- @client.ssl_config.add_trust_ca(ssl.ca_cert_file) if ssl.ca_cert_file
60
+ if ssl.ca_cert_file && ssl.verify_mode != :none
61
+ @client.ssl_config.add_trust_ca(ssl.ca_cert_file)
59
62
  end
60
63
 
64
+ # Send client-side certificate regardless of state of SSL verify mode
65
+ @client.ssl_config.client_cert = ssl.cert
66
+ @client.ssl_config.client_key = ssl.cert_key
67
+
61
68
  @client.ssl_config.verify_mode = ssl.openssl_verify_mode
62
- @client.ssl_config.ssl_version = ssl.ssl_version if ssl.ssl_version
69
+ @client.ssl_config.ssl_version = ssl.ssl_version.to_s if ssl.ssl_version
63
70
  end
64
71
 
65
72
  def respond_with(response)