httpi 2.4.0 → 2.4.1
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -0
- data/lib/httpi.rb +1 -0
- data/lib/httpi/adapter.rb +1 -1
- data/lib/httpi/adapter/curb.rb +11 -3
- data/lib/httpi/adapter/http.rb +76 -0
- data/lib/httpi/version.rb +1 -1
- data/spec/httpi/adapter/curb_spec.rb +28 -9
- data/spec/httpi/adapter/http_spec.rb +101 -0
- data/spec/httpi/httpi_spec.rb +3 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6ca1f335780f0839e9e5316c9ecf1a6d3753bea
|
4
|
+
data.tar.gz: f5e52a1dde48d6c783c2bc66b691df4cb4e1f4cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7e7e5d0cf5c2a2f59ad4b8bf331c4917cfcef503c0e905b6613b08ad03a8a23e20727668b51a3e27762167905b5a3c1a526a9fb987cd1d528dd6429090ee98c
|
7
|
+
data.tar.gz: ffe4093b24fc493cda6c8b7e266a5abcdc97785759e59024a6f02ef984f15b9c6707e70dfbd76e7f29bd91ed5077af219bd5c593d99bc675f720024e467193c6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
### 2.4.1
|
2
|
+
|
3
|
+
* Fix: [#147](https://github.com/savonrb/httpi/pull/147) Fix call Curb client "SSL peer certificate or SSH remote key was not OK" bug
|
4
|
+
* Feature: [#145](https://github.com/savonrb/httpi/pull/145) Add support to http.rb adapter
|
5
|
+
* Feature: [#144](https://github.com/savonrb/httpi/pull/144) Add NTLM support for CURB
|
6
|
+
|
1
7
|
### 2.4.0
|
2
8
|
|
3
9
|
* Formally drop support for ruby 1.8.7
|
data/Gemfile
CHANGED
@@ -10,6 +10,7 @@ gem 'em-http-request', :require => false, :platforms => [:ruby,
|
|
10
10
|
gem 'em-synchrony', :require => false, :platforms => [:ruby, :jruby]
|
11
11
|
gem 'excon', '~> 0.21.0', :require => false, :platforms => [:ruby, :jruby]
|
12
12
|
gem 'net-http-persistent', '~> 2.8', :require => false
|
13
|
+
gem 'http', :require => false
|
13
14
|
|
14
15
|
# coverage
|
15
16
|
gem 'simplecov', :require => false
|
data/lib/httpi.rb
CHANGED
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, :excon, :net_http, :net_http_persistent]
|
16
|
+
LOAD_ORDER = [:httpclient, :curb, :em_http, :excon, :http, :net_http, :net_http_persistent]
|
17
17
|
|
18
18
|
class << self
|
19
19
|
|
data/lib/httpi/adapter/curb.rb
CHANGED
@@ -59,10 +59,11 @@ module HTTPI
|
|
59
59
|
def setup_client
|
60
60
|
basic_setup
|
61
61
|
|
62
|
-
if @request.auth.ntlm?
|
63
|
-
raise NotSupportedError, "
|
62
|
+
if @request.auth.ntlm? && !Curl.ntlm?
|
63
|
+
raise NotSupportedError, "installed version of libcurl does not support NTLM authentication"
|
64
64
|
end
|
65
65
|
|
66
|
+
setup_ntlm_auth if @request.auth.ntlm?
|
66
67
|
setup_http_auth if @request.auth.http?
|
67
68
|
setup_gssnegotiate_auth if @request.auth.gssnegotiate?
|
68
69
|
setup_ssl_auth if @request.auth.ssl? || @request.ssl?
|
@@ -81,6 +82,11 @@ module HTTPI
|
|
81
82
|
@client.set(:NOSIGNAL, true)
|
82
83
|
end
|
83
84
|
|
85
|
+
def setup_ntlm_auth
|
86
|
+
@client.http_auth_types = @request.auth.type
|
87
|
+
@client.username, @client.password = *@request.auth.credentials
|
88
|
+
end
|
89
|
+
|
84
90
|
def setup_http_auth
|
85
91
|
@client.http_auth_types = @request.auth.type
|
86
92
|
@client.username, @client.password = *@request.auth.credentials
|
@@ -98,7 +104,9 @@ module HTTPI
|
|
98
104
|
ssl = @request.auth.ssl
|
99
105
|
|
100
106
|
if @request.auth.ssl?
|
101
|
-
|
107
|
+
if ssl.verify_mode == :none
|
108
|
+
@client.ssl_verify_host = 0
|
109
|
+
else
|
102
110
|
@client.cacert = ssl.ca_cert_file if ssl.ca_cert_file
|
103
111
|
@client.certtype = ssl.cert_type.to_s.upcase
|
104
112
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "httpi/adapter/base"
|
2
|
+
require "httpi/response"
|
3
|
+
|
4
|
+
module HTTPI
|
5
|
+
module Adapter
|
6
|
+
|
7
|
+
# = HTTPI::Adapter::HTTP
|
8
|
+
#
|
9
|
+
# Adapter for the http.rb client.
|
10
|
+
# https://github.com/httprb/http.rb
|
11
|
+
class HTTP < Base
|
12
|
+
|
13
|
+
register :http, :deps => %w(http)
|
14
|
+
|
15
|
+
def initialize(request)
|
16
|
+
if request.auth.digest?
|
17
|
+
raise NotSupportedError, "http.rb does not support HTTP digest authentication"
|
18
|
+
end
|
19
|
+
if request.auth.ntlm?
|
20
|
+
raise NotSupportedError, "http.rb does not support NTLM digest authentication"
|
21
|
+
end
|
22
|
+
|
23
|
+
@request = request
|
24
|
+
@client = create_client
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :client
|
28
|
+
|
29
|
+
# Executes arbitrary HTTP requests.
|
30
|
+
# @see HTTPI.request
|
31
|
+
def request(method)
|
32
|
+
unless ::HTTP::Request::METHODS.include? method
|
33
|
+
raise NotSupportedError, "http.rb does not support custom HTTP methods"
|
34
|
+
end
|
35
|
+
response = @client.send(method, @request.url, :body => @request.body)
|
36
|
+
|
37
|
+
Response.new(response.code, response.headers, response.body.to_s)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def create_client
|
43
|
+
if @request.ssl?
|
44
|
+
context = OpenSSL::SSL::SSLContext.new
|
45
|
+
|
46
|
+
context.options = OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:options]
|
47
|
+
|
48
|
+
if @request.auth.ssl.ca_cert_file != nil
|
49
|
+
context.ca_file = @request.auth.ssl.ca_cert_file
|
50
|
+
else
|
51
|
+
context.cert_store = OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE
|
52
|
+
end
|
53
|
+
|
54
|
+
context.cert = @request.auth.ssl.cert
|
55
|
+
context.key = @request.auth.ssl.cert_key
|
56
|
+
context.ssl_version = @request.auth.ssl.ssl_version if @request.auth.ssl.ssl_version != nil
|
57
|
+
context.verify_mode = @request.auth.ssl.openssl_verify_mode
|
58
|
+
|
59
|
+
client = ::HTTP::Client.new(:ssl_context => context)
|
60
|
+
else
|
61
|
+
client = ::HTTP
|
62
|
+
end
|
63
|
+
|
64
|
+
if @request.auth.basic?
|
65
|
+
client = client.basic_auth(:user => @request.auth.credentials[0], :pass => @request.auth.credentials[1])
|
66
|
+
end
|
67
|
+
|
68
|
+
if @request.proxy != nil
|
69
|
+
client = client.via(@request.proxy.host, @request.proxy.port, @request.proxy.user, @request.proxy.password)
|
70
|
+
end
|
71
|
+
|
72
|
+
client.headers(@request.headers)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/httpi/version.rb
CHANGED
@@ -2,10 +2,30 @@ require "spec_helper"
|
|
2
2
|
require "httpi/adapter/curb"
|
3
3
|
require "httpi/request"
|
4
4
|
|
5
|
+
require "integration/support/server"
|
6
|
+
|
5
7
|
# curb does not run on jruby
|
6
8
|
unless RUBY_PLATFORM =~ /java/
|
7
9
|
HTTPI::Adapter.load_adapter(:curb)
|
8
10
|
|
11
|
+
describe "NTLM authentication" do
|
12
|
+
before :all do
|
13
|
+
@server = IntegrationServer.run
|
14
|
+
end
|
15
|
+
|
16
|
+
after :all do
|
17
|
+
@server.stop
|
18
|
+
end
|
19
|
+
|
20
|
+
it "supports ntlm authentication" do
|
21
|
+
request = HTTPI::Request.new(@server.url + "ntlm-auth")
|
22
|
+
adapter = HTTPI::Adapter::Curb.new(request)
|
23
|
+
|
24
|
+
request.auth.ntlm("tester", "vReqSoafRe5O")
|
25
|
+
expect(adapter.request(:get).body).to eq("ntlm-auth")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
9
29
|
describe HTTPI::Adapter::Curb do
|
10
30
|
|
11
31
|
let(:adapter) { HTTPI::Adapter::Curb.new(request) }
|
@@ -168,15 +188,6 @@ unless RUBY_PLATFORM =~ /java/
|
|
168
188
|
end
|
169
189
|
end
|
170
190
|
|
171
|
-
describe "NTLM authentication" do
|
172
|
-
it "is not supported" do
|
173
|
-
request.auth.ntlm("tester", "vReqSoafRe5O")
|
174
|
-
|
175
|
-
expect { adapter.request(:get) }.
|
176
|
-
to raise_error(HTTPI::NotSupportedError, /does not support NTLM authentication/)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
191
|
describe "http_auth_types" do
|
181
192
|
it "is set to :basic for HTTP basic auth" do
|
182
193
|
request.auth.basic "username", "password"
|
@@ -198,6 +209,13 @@ unless RUBY_PLATFORM =~ /java/
|
|
198
209
|
|
199
210
|
adapter.request(:get)
|
200
211
|
end
|
212
|
+
|
213
|
+
it "is set to :ntlm for HTTP NTLM auth" do
|
214
|
+
request.auth.ntlm("tester", "vReqSoafRe5O")
|
215
|
+
curb.expects(:http_auth_types=).with(:ntlm)
|
216
|
+
|
217
|
+
adapter.request(:get)
|
218
|
+
end
|
201
219
|
end
|
202
220
|
|
203
221
|
describe "username and password" do
|
@@ -266,6 +284,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
266
284
|
|
267
285
|
it "send certificate regardless of state of SSL verify mode" do
|
268
286
|
request.auth.ssl.verify_mode = :none
|
287
|
+
curb.expects(:ssl_verify_host=).with(0) # avoid "SSL peer certificate" error
|
269
288
|
curb.expects(:cert_key=).with(request.auth.ssl.cert_key_file)
|
270
289
|
curb.expects(:cert=).with(request.auth.ssl.cert_file)
|
271
290
|
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "integration/support/server"
|
3
|
+
|
4
|
+
describe HTTPI::Adapter::HTTP do
|
5
|
+
|
6
|
+
subject(:adapter) { :http }
|
7
|
+
|
8
|
+
context "http requests" do
|
9
|
+
before :all do
|
10
|
+
@server = IntegrationServer.run
|
11
|
+
end
|
12
|
+
|
13
|
+
after :all do
|
14
|
+
@server.stop
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sends and receives HTTP headers" do
|
18
|
+
request = HTTPI::Request.new(@server.url + "x-header")
|
19
|
+
request.headers["X-Header"] = "HTTPI"
|
20
|
+
|
21
|
+
response = HTTPI.get(request, adapter)
|
22
|
+
expect(response.body).to include("HTTPI")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "executes GET requests" do
|
26
|
+
response = HTTPI.get(@server.url, adapter)
|
27
|
+
expect(response.body).to eq("get")
|
28
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "executes POST requests" do
|
32
|
+
response = HTTPI.post(@server.url, "<some>xml</some>", adapter)
|
33
|
+
expect(response.body).to eq("post")
|
34
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "executes HEAD requests" do
|
38
|
+
response = HTTPI.head(@server.url, adapter)
|
39
|
+
expect(response.code).to eq(200)
|
40
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "executes PUT requests" do
|
44
|
+
response = HTTPI.put(@server.url, "<some>xml</some>", adapter)
|
45
|
+
expect(response.body).to eq("put")
|
46
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "executes DELETE requests" do
|
50
|
+
response = HTTPI.delete(@server.url, adapter)
|
51
|
+
expect(response.body).to eq("delete")
|
52
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "supports basic authentication" do
|
56
|
+
request = HTTPI::Request.new(@server.url + "basic-auth")
|
57
|
+
request.auth.basic("admin", "secret")
|
58
|
+
|
59
|
+
response = HTTPI.get(request, adapter)
|
60
|
+
expect(response.body).to eq("basic-auth")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "does not support digest authentication" do
|
64
|
+
request = HTTPI::Request.new(@server.url + "digest-auth")
|
65
|
+
request.auth.digest("admin", "secret")
|
66
|
+
|
67
|
+
expect { HTTPI.get(request, adapter) }.
|
68
|
+
to raise_error(HTTPI::NotSupportedError, /does not support HTTP digest authentication/)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "does not support ntlm authentication" do
|
72
|
+
request = HTTPI::Request.new(@server.url + "ntlm-auth")
|
73
|
+
request.auth.ntlm("tester", "vReqSoafRe5O")
|
74
|
+
|
75
|
+
expect { HTTPI.get(request, adapter) }.
|
76
|
+
to raise_error(HTTPI::NotSupportedError, /does not support NTLM digest authentication/)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
if RUBY_PLATFORM =~ /java/
|
81
|
+
pending "Puma Server complains: SSL not supported on JRuby"
|
82
|
+
else
|
83
|
+
context "https requests" do
|
84
|
+
before :all do
|
85
|
+
@server = IntegrationServer.run(:ssl => true)
|
86
|
+
end
|
87
|
+
after :all do
|
88
|
+
@server.stop
|
89
|
+
end
|
90
|
+
|
91
|
+
it "works when set up properly" do
|
92
|
+
request = HTTPI::Request.new(@server.url)
|
93
|
+
request.auth.ssl.ca_cert_file = IntegrationServer.ssl_ca_file
|
94
|
+
|
95
|
+
response = HTTPI.get(request, adapter)
|
96
|
+
expect(response.body).to eq("get")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
data/spec/httpi/httpi_spec.rb
CHANGED
@@ -4,6 +4,7 @@ require "integration/support/server"
|
|
4
4
|
# find out why httpi doesn't load these automatically. [dh, 2012-12-15]
|
5
5
|
require "excon"
|
6
6
|
require "net/http/persistent"
|
7
|
+
require "http"
|
7
8
|
|
8
9
|
unless RUBY_VERSION < "1.9"
|
9
10
|
require "em-synchrony"
|
@@ -287,7 +288,8 @@ describe HTTPI do
|
|
287
288
|
:net_http_persistent => lambda { Net::HTTP::Persistent },
|
288
289
|
:em_http => lambda { EventMachine::HttpConnection },
|
289
290
|
:rack => lambda { Rack::MockRequest },
|
290
|
-
:excon => lambda { Excon::Connection }
|
291
|
+
:excon => lambda { Excon::Connection },
|
292
|
+
:http => lambda { ::HTTP::Client }
|
291
293
|
}
|
292
294
|
|
293
295
|
context "using #{adapter}" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Harrington
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/httpi/adapter/curb.rb
|
117
117
|
- lib/httpi/adapter/em_http.rb
|
118
118
|
- lib/httpi/adapter/excon.rb
|
119
|
+
- lib/httpi/adapter/http.rb
|
119
120
|
- lib/httpi/adapter/httpclient.rb
|
120
121
|
- lib/httpi/adapter/net_http.rb
|
121
122
|
- lib/httpi/adapter/net_http_persistent.rb
|
@@ -141,6 +142,7 @@ files:
|
|
141
142
|
- spec/httpi/adapter/curb_spec.rb
|
142
143
|
- spec/httpi/adapter/em_http_spec.rb
|
143
144
|
- spec/httpi/adapter/excon_spec.rb
|
145
|
+
- spec/httpi/adapter/http_spec.rb
|
144
146
|
- spec/httpi/adapter/httpclient_spec.rb
|
145
147
|
- spec/httpi/adapter/net_http_persistent_spec.rb
|
146
148
|
- spec/httpi/adapter/net_http_spec.rb
|
@@ -188,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
190
|
version: '0'
|
189
191
|
requirements: []
|
190
192
|
rubyforge_project: httpi
|
191
|
-
rubygems_version: 2.
|
193
|
+
rubygems_version: 2.4.8
|
192
194
|
signing_key:
|
193
195
|
specification_version: 4
|
194
196
|
summary: Common interface for Ruby's HTTP libraries
|