httpi 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 0.9.3 (2010-04-28)
2
+
3
+ * Fix: [issue 31](https://github.com/rubiii/httpi/issues/31) missing headers when using httpclient.
4
+
5
+ * Fix: [issue 30](https://github.com/rubiii/httpi/issues/30) fix for using SSL with Net::HTTP.
6
+
7
+ ## 0.9.2 (2011-04-05)
8
+
9
+ * Fix: issues [161](https://github.com/rubiii/savon/issues/161) and [165](https://github.com/rubiii/savon/issues/165)
10
+ reported at [rubiii/savon](https://github.com/rubiii/savon).
11
+
1
12
  ## 0.9.1 (2011-04-04)
2
13
 
3
14
  * Fix: [issue 25](https://github.com/rubiii/httpi/issues/22) problem with HTTPI using the Net::HTTP adapter [hakanensari].
data/httpi.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.add_dependency "rack"
18
18
  s.add_dependency "ntlm-http", ">= 0.1.1"
19
19
 
20
- s.add_development_dependency "httpclient", "~> 2.1.5"
20
+ s.add_development_dependency "httpclient", "~> 2.1.7"
21
21
  s.add_development_dependency "curb", "~> 0.7.8"
22
22
 
23
23
  s.add_development_dependency "rspec", "~> 2.2"
data/lib/httpi/adapter.rb CHANGED
@@ -48,10 +48,6 @@ module HTTPI
48
48
  end
49
49
 
50
50
  def default_adapter
51
- return :httpclient if defined?(::HTTPClient)
52
- return :curb if defined?(::Curl::Easy)
53
- return :net_http if defined?(::Net::HTTP)
54
-
55
51
  DEPENDENCIES.each do |(adapter, dependencies)|
56
52
  begin
57
53
  dependencies.each { |dependency| require dependency }
@@ -90,7 +90,7 @@ module HTTPI
90
90
  end
91
91
 
92
92
  def respond_with(response)
93
- Response.new response.code, Hash[response.header.all.flatten], response.content
93
+ Response.new response.code, Hash[*response.header.all.flatten], response.content
94
94
  end
95
95
 
96
96
  end
@@ -9,7 +9,7 @@ module HTTPI
9
9
  # Adapter for the Net::HTTP client.
10
10
  # http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/
11
11
  class NetHTTP
12
-
12
+
13
13
  def initialize(request)
14
14
  self.client = new_client request
15
15
  end
@@ -70,7 +70,7 @@ module HTTPI
70
70
  def do_request(type, request)
71
71
  setup_client request
72
72
  setup_ssl_auth request.auth.ssl if request.auth.ssl?
73
-
73
+
74
74
  respond_with(client.start do |http|
75
75
  yield http, request_client(type, request)
76
76
  end)
@@ -88,7 +88,6 @@ module HTTPI
88
88
  client.ca_file = ssl.ca_cert_file if ssl.ca_cert_file
89
89
  client.verify_mode = ssl.openssl_verify_mode
90
90
  end
91
-
92
91
 
93
92
  def request_client(type, request)
94
93
  request_class = case type
@@ -98,20 +97,21 @@ module HTTPI
98
97
  when :put then Net::HTTP::Put
99
98
  when :delete then Net::HTTP::Delete
100
99
  end
101
-
100
+
102
101
  request_client = request_class.new request.url.request_uri, request.headers
103
-
102
+
104
103
  request_client.basic_auth *request.auth.credentials if request.auth.basic?
105
104
  request_client.ntlm_auth *request.auth.credentials if request.auth.ntlm?
106
-
105
+
107
106
  request_client
108
107
  end
109
108
 
110
109
  def respond_with(response)
111
110
  headers = response.to_hash
112
- headers.each {|k,v| headers[k] = v[0]}
111
+ headers.each { |key, value| headers[key] = value[0] }
113
112
  Response.new response.code, headers, response.body
114
113
  end
114
+
115
115
  end
116
116
  end
117
117
  end
data/lib/httpi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module HTTPI
2
2
 
3
- VERSION = "0.9.2"
3
+ VERSION = "0.9.3"
4
4
 
5
5
  end
@@ -12,7 +12,7 @@ describe HTTPI::Adapter::Curb do
12
12
  before do
13
13
  curb.expects(:http_get)
14
14
  curb.expects(:response_code).returns(200)
15
- curb.expects(:header_str).returns("")
15
+ curb.expects(:header_str).returns("Accept-encoding: utf-8")
16
16
  curb.expects(:body_str).returns(Fixture.xml)
17
17
  end
18
18
 
@@ -25,7 +25,7 @@ describe HTTPI::Adapter::Curb do
25
25
  before do
26
26
  curb.expects(:http_post)
27
27
  curb.expects(:response_code).returns(200)
28
- curb.expects(:header_str).returns("")
28
+ curb.expects(:header_str).returns("Accept-encoding: utf-8")
29
29
  curb.expects(:body_str).returns(Fixture.xml)
30
30
  end
31
31
 
@@ -45,7 +45,7 @@ describe HTTPI::Adapter::Curb do
45
45
  before do
46
46
  curb.expects(:http_head)
47
47
  curb.expects(:response_code).returns(200)
48
- curb.expects(:header_str).returns("")
48
+ curb.expects(:header_str).returns("Accept-encoding: utf-8")
49
49
  curb.expects(:body_str).returns(Fixture.xml)
50
50
  end
51
51
 
@@ -58,7 +58,7 @@ describe HTTPI::Adapter::Curb do
58
58
  before do
59
59
  curb.expects(:http_put)
60
60
  curb.expects(:response_code).returns(200)
61
- curb.expects(:header_str).returns("")
61
+ curb.expects(:header_str).returns("Accept-encoding: utf-8")
62
62
  curb.expects(:body_str).returns(Fixture.xml)
63
63
  end
64
64
 
@@ -78,7 +78,7 @@ describe HTTPI::Adapter::Curb do
78
78
  before do
79
79
  curb.expects(:http_delete)
80
80
  curb.expects(:response_code).returns(200)
81
- curb.expects(:header_str).returns("")
81
+ curb.expects(:header_str).returns("Accept-encoding: utf-8")
82
82
  curb.expects(:body_str).returns("")
83
83
  end
84
84
 
@@ -105,7 +105,7 @@ describe HTTPI::Adapter::Curb do
105
105
 
106
106
  it "should be set if specified" do
107
107
  request = basic_request { |request| request.proxy = "http://proxy.example.com" }
108
-
108
+
109
109
  curb.expects(:proxy_url=).with(request.proxy.to_s)
110
110
  adapter.get(request)
111
111
  end
@@ -156,14 +156,14 @@ describe HTTPI::Adapter::Curb do
156
156
  describe "http_auth_types" do
157
157
  it "should be set to :basic for HTTP basic auth" do
158
158
  request = basic_request { |request| request.auth.basic "username", "password" }
159
-
159
+
160
160
  curb.expects(:http_auth_types=).with(:basic)
161
161
  adapter.get(request)
162
162
  end
163
163
 
164
164
  it "should be set to :digest for HTTP digest auth" do
165
165
  request = basic_request { |request| request.auth.digest "username", "password" }
166
-
166
+
167
167
  curb.expects(:http_auth_types=).with(:digest)
168
168
  adapter.get(request)
169
169
  end
@@ -172,7 +172,7 @@ describe HTTPI::Adapter::Curb do
172
172
  describe "username and password" do
173
173
  it "should be set for HTTP basic auth" do
174
174
  request = basic_request { |request| request.auth.basic "username", "password" }
175
-
175
+
176
176
  curb.expects(:username=).with("username")
177
177
  curb.expects(:password=).with("password")
178
178
  adapter.get(request)
@@ -180,7 +180,7 @@ describe HTTPI::Adapter::Curb do
180
180
 
181
181
  it "should be set for HTTP digest auth" do
182
182
  request = basic_request { |request| request.auth.digest "username", "password" }
183
-
183
+
184
184
  curb.expects(:username=).with("username")
185
185
  curb.expects(:password=).with("password")
186
186
  adapter.get(request)
@@ -200,21 +200,21 @@ describe HTTPI::Adapter::Curb do
200
200
  curb.expects(:cert=).with(ssl_auth_request.auth.ssl.cert_file)
201
201
  curb.expects(:ssl_verify_peer=).with(true)
202
202
  curb.expects(:certtype=).with(ssl_auth_request.auth.ssl.cert_type.to_s.upcase)
203
-
203
+
204
204
  adapter.get(ssl_auth_request)
205
205
  end
206
-
206
+
207
207
  it "should set the cert_type to DER if specified" do
208
208
  ssl_auth_request.auth.ssl.cert_type = :der
209
209
  curb.expects(:certtype=).with(:der.to_s.upcase)
210
-
210
+
211
211
  adapter.get(ssl_auth_request)
212
212
  end
213
213
 
214
214
  it "should set the cacert if specified" do
215
215
  ssl_auth_request.auth.ssl.ca_cert_file = "spec/fixtures/client_cert.pem"
216
216
  curb.expects(:cacert=).with(ssl_auth_request.auth.ssl.ca_cert_file)
217
-
217
+
218
218
  adapter.get(ssl_auth_request)
219
219
  end
220
220
  end
@@ -150,7 +150,9 @@ describe HTTPI::Adapter::HTTPClient do
150
150
  end
151
151
 
152
152
  def http_message(body = Fixture.xml)
153
- HTTP::Message.new_response body
153
+ message = HTTP::Message.new_response body
154
+ message.header.set "Accept-encoding", "utf-8"
155
+ message
154
156
  end
155
157
 
156
158
  def basic_request
@@ -4,6 +4,7 @@ require "httpi/request"
4
4
 
5
5
  describe HTTPI::Adapter::NetHTTP do
6
6
  let(:net_http) { Net::HTTP.any_instance }
7
+ let(:basic_response) { { :body => Fixture.xml, :headers => { "Accept-encoding" => "utf-8" } } }
7
8
 
8
9
  def adapter(request)
9
10
  @adapter ||= HTTPI::Adapter::NetHTTP.new request
@@ -11,7 +12,7 @@ describe HTTPI::Adapter::NetHTTP do
11
12
 
12
13
  describe "#get" do
13
14
  it "should return a valid HTTPI::Response" do
14
- stub_request(:get, basic_request.url.to_s).to_return(:body => Fixture.xml)
15
+ stub_request(:get, basic_request.url.to_s).to_return(basic_response)
15
16
  adapter(basic_request).get(basic_request).should match_response(:body => Fixture.xml)
16
17
  end
17
18
  end
@@ -19,32 +20,36 @@ describe HTTPI::Adapter::NetHTTP do
19
20
  describe "#post" do
20
21
  it "should return a valid HTTPI::Response" do
21
22
  request = HTTPI::Request.new :url => "http://example.com", :body => Fixture.xml
22
- stub_request(:post, request.url.to_s).with(:body => request.body).to_return(:body => Fixture.xml)
23
-
23
+ stub_request(:post, request.url.to_s).with(:body => request.body).to_return(basic_response)
24
+
24
25
  adapter(request).post(request).should match_response(:body => Fixture.xml)
25
26
  end
26
27
  end
27
28
 
28
29
  describe "#head" do
29
30
  it "should return a valid HTTPI::Response" do
30
- stub_request(:head, basic_request.url.to_s).to_return(:body => Fixture.xml)
31
+ stub_request(:head, basic_request.url.to_s).to_return(basic_response)
31
32
  adapter(basic_request).head(basic_request).should match_response(:body => Fixture.xml)
32
33
  end
33
34
  end
34
35
 
35
36
  describe "#put" do
36
37
  it "should return a valid HTTPI::Response" do
37
- request = HTTPI::Request.new :url => "http://example.com", :body => Fixture.xml
38
- stub_request(:put, request.url.to_s).with(:body => request.body).to_return(:body => Fixture.xml)
39
-
38
+ request = HTTPI::Request.new(
39
+ :url => "http://example.com",
40
+ :headers => { "Accept-encoding" => "utf-8" },
41
+ :body => Fixture.xml
42
+ )
43
+ stub_request(:put, request.url.to_s).with(:body => request.body).to_return(basic_response)
44
+
40
45
  adapter(request).put(request).should match_response(:body => Fixture.xml)
41
46
  end
42
47
  end
43
48
 
44
49
  describe "#delete" do
45
50
  it "should return a valid HTTPI::Response" do
46
- stub_request(:delete, basic_request.url.to_s)
47
- adapter(basic_request).delete(basic_request).should match_response(:body => "")
51
+ stub_request(:delete, basic_request.url.to_s).to_return(basic_response)
52
+ adapter(basic_request).delete(basic_request).should match_response(:body => Fixture.xml)
48
53
  end
49
54
  end
50
55
 
@@ -59,7 +64,7 @@ describe HTTPI::Adapter::NetHTTP do
59
64
 
60
65
  it "should be set to true for SSL requests" do
61
66
  request = basic_request { |request| request.ssl = true }
62
-
67
+
63
68
  net_http.expects(:use_ssl=).with(true)
64
69
  adapter(request).get(request)
65
70
  end
@@ -73,7 +78,7 @@ describe HTTPI::Adapter::NetHTTP do
73
78
 
74
79
  it "should be set if specified" do
75
80
  request = basic_request { |request| request.open_timeout = 30 }
76
-
81
+
77
82
  net_http.expects(:open_timeout=).with(30)
78
83
  adapter(request).get(request)
79
84
  end
@@ -87,7 +92,7 @@ describe HTTPI::Adapter::NetHTTP do
87
92
 
88
93
  it "should be set if specified" do
89
94
  request = basic_request { |request| request.read_timeout = 30 }
90
-
95
+
91
96
  net_http.expects(:read_timeout=).with(30)
92
97
  adapter(request).get(request)
93
98
  end
@@ -96,7 +101,7 @@ describe HTTPI::Adapter::NetHTTP do
96
101
  describe "basic_auth" do
97
102
  it "should be set for HTTP basic auth" do
98
103
  request = basic_request { |request| request.auth.basic "username", "password" }
99
-
104
+
100
105
  stub_request(:get, "http://username:password@example.com")
101
106
  Net::HTTP::Get.any_instance.expects(:basic_auth).with(*request.auth.credentials)
102
107
  adapter(request).get(request)
@@ -115,14 +120,14 @@ describe HTTPI::Adapter::NetHTTP do
115
120
  net_http.expects(:cert=).with(ssl_auth_request.auth.ssl.cert)
116
121
  net_http.expects(:key=).with(ssl_auth_request.auth.ssl.cert_key)
117
122
  net_http.expects(:verify_mode=).with(ssl_auth_request.auth.ssl.openssl_verify_mode)
118
-
123
+
119
124
  adapter(ssl_auth_request).get(ssl_auth_request)
120
125
  end
121
126
 
122
127
  it "should set the client_ca if specified" do
123
128
  ssl_auth_request.auth.ssl.ca_cert_file = "spec/fixtures/client_cert.pem"
124
129
  net_http.expects(:ca_file=).with(ssl_auth_request.auth.ssl.ca_cert_file)
125
-
130
+
126
131
  adapter(ssl_auth_request).get(ssl_auth_request)
127
132
  end
128
133
  end
@@ -1,11 +1,19 @@
1
1
  RSpec::Matchers.define :match_response do |options|
2
- defaults = { :code => 200, :headers => {}, :body => "" }
2
+ defaults = { :code => 200, :headers => { "Accept-encoding" => "utf-8" }, :body => "" }
3
3
  response = defaults.merge options
4
-
4
+
5
5
  match do |actual|
6
6
  actual.should be_an(HTTPI::Response)
7
7
  actual.code.should == response[:code]
8
- actual.headers.should == response[:headers]
8
+ downcase(actual.headers).should == downcase(response[:headers])
9
9
  actual.body.should == response[:body]
10
10
  end
11
+
12
+ def downcase(hash)
13
+ hash.inject({}) do |memo, (key, value)|
14
+ memo[key.downcase] = value.downcase
15
+ memo
16
+ end
17
+ end
18
+
11
19
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 2
10
- version: 0.9.2
9
+ - 3
10
+ version: 0.9.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Harrington
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-05 00:00:00 +02:00
19
+ date: 2011-04-28 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -57,12 +57,12 @@ dependencies:
57
57
  requirements:
58
58
  - - ~>
59
59
  - !ruby/object:Gem::Version
60
- hash: 1
60
+ hash: 5
61
61
  segments:
62
62
  - 2
63
63
  - 1
64
- - 5
65
- version: 2.1.5
64
+ - 7
65
+ version: 2.1.7
66
66
  type: :development
67
67
  version_requirements: *id003
68
68
  - !ruby/object:Gem::Dependency
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
224
  requirements: []
225
225
 
226
226
  rubyforge_project: httpi
227
- rubygems_version: 1.4.2
227
+ rubygems_version: 1.4.1
228
228
  signing_key:
229
229
  specification_version: 3
230
230
  summary: Interface for Ruby HTTP libraries