httpi 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/httpi.gemspec +1 -1
- data/lib/httpi/adapter/curb.rb +1 -1
- data/lib/httpi/version.rb +1 -1
- data/spec/integration/request_spec.rb +22 -16
- data/spec/integration/server.rb +39 -0
- metadata +9 -9
data/Gemfile
CHANGED
data/httpi.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_development_dependency "httpclient", "~> 2.1.5"
|
20
20
|
s.add_development_dependency "curb", "~> 0.7.8"
|
21
21
|
|
22
|
-
s.add_development_dependency "rspec", "2.
|
22
|
+
s.add_development_dependency "rspec", "~> 2.2"
|
23
23
|
s.add_development_dependency "mocha", "~> 0.9.9"
|
24
24
|
s.add_development_dependency "webmock", "~> 1.4.0"
|
25
25
|
|
data/lib/httpi/adapter/curb.rb
CHANGED
@@ -68,7 +68,7 @@ module HTTPI
|
|
68
68
|
client.proxy_url = request.proxy.to_s if request.proxy
|
69
69
|
client.timeout = request.read_timeout if request.read_timeout
|
70
70
|
client.connect_timeout = request.open_timeout if request.open_timeout
|
71
|
-
client.headers = request.headers
|
71
|
+
client.headers = request.headers.to_hash
|
72
72
|
client.verbose = false
|
73
73
|
end
|
74
74
|
|
data/lib/httpi/version.rb
CHANGED
@@ -1,51 +1,57 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "httpi"
|
3
|
+
require "integration/server"
|
4
|
+
|
5
|
+
MockServer.new(IntegrationServer, 4000).start
|
3
6
|
|
4
7
|
describe HTTPI do
|
5
8
|
let(:client) { HTTPI }
|
6
9
|
|
7
|
-
# Uses example.com for basic request methods and webdav.org
|
8
|
-
# for HTTP basic and digest authentication.
|
9
|
-
#
|
10
|
-
# http://example.com
|
11
|
-
# http://test.webdav.org
|
12
|
-
|
13
10
|
before :all do
|
14
11
|
WebMock.allow_net_connect!
|
15
12
|
|
16
|
-
@username =
|
13
|
+
@username = "admin"
|
14
|
+
@password = "pwd"
|
17
15
|
@error_message = "Authorization Required"
|
18
|
-
@example_web_page = "
|
19
|
-
@content_type = "text/
|
16
|
+
@example_web_page = "Hello"
|
17
|
+
@content_type = "text/plain"
|
20
18
|
end
|
21
19
|
|
22
20
|
shared_examples_for "an HTTP client" do
|
21
|
+
it "and send HTTP headers" do
|
22
|
+
request = HTTPI::Request.new :url => "http://localhost:4000/x-header"
|
23
|
+
request.headers["X-Header"] = "HTTPI"
|
24
|
+
|
25
|
+
response = HTTPI.get request, adapter
|
26
|
+
response.body.should include("X-Header is HTTPI")
|
27
|
+
end
|
28
|
+
|
23
29
|
it "and execute an HTTP GET request" do
|
24
|
-
response = HTTPI.get "http://
|
30
|
+
response = HTTPI.get "http://localhost:4000", adapter
|
25
31
|
response.body.should include(@example_web_page)
|
26
32
|
response.headers["Content-Type"].should include(@content_type)
|
27
33
|
end
|
28
34
|
|
29
35
|
it "and execute an HTTP POST request" do
|
30
|
-
response = HTTPI.post "http://
|
36
|
+
response = HTTPI.post "http://localhost:4000", "<some>xml</some>", adapter
|
31
37
|
response.body.should include(@example_web_page)
|
32
38
|
response.headers["Content-Type"].should include(@content_type)
|
33
39
|
end
|
34
40
|
|
35
41
|
it "and execute an HTTP HEAD request" do
|
36
|
-
response = HTTPI.head "http://
|
42
|
+
response = HTTPI.head "http://localhost:4000", adapter
|
37
43
|
response.code.should == 200
|
38
44
|
response.headers["Content-Type"].should include(@content_type)
|
39
45
|
end
|
40
46
|
|
41
47
|
it "and execute an HTTP PUT request" do
|
42
|
-
response = HTTPI.put "http://
|
48
|
+
response = HTTPI.put "http://localhost:4000", "<some>xml</some>", adapter
|
43
49
|
response.body.should include("PUT is not allowed")
|
44
50
|
response.headers["Content-Type"].should include(@content_type)
|
45
51
|
end
|
46
52
|
|
47
53
|
it "and execute an HTTP DELETE request" do
|
48
|
-
response = HTTPI.delete "http://
|
54
|
+
response = HTTPI.delete "http://localhost:4000", adapter
|
49
55
|
response.body.should include("DELETE is not allowed")
|
50
56
|
response.headers["Content-Type"].should include(@content_type)
|
51
57
|
end
|
@@ -53,7 +59,7 @@ describe HTTPI do
|
|
53
59
|
|
54
60
|
shared_examples_for "it works with HTTP basic auth" do
|
55
61
|
it "and access a secured page" do
|
56
|
-
request = HTTPI::Request.new :url => "http://
|
62
|
+
request = HTTPI::Request.new :url => "http://localhost:4000/auth/basic"
|
57
63
|
request.auth.basic @username, @password
|
58
64
|
|
59
65
|
response = HTTPI.get request, adapter
|
@@ -63,7 +69,7 @@ describe HTTPI do
|
|
63
69
|
|
64
70
|
shared_examples_for "it works with HTTP digest auth" do
|
65
71
|
it "and access a secured page" do
|
66
|
-
request = HTTPI::Request.new :url => "http://
|
72
|
+
request = HTTPI::Request.new :url => "http://localhost:4000/auth/digest"
|
67
73
|
request.auth.digest @username, @password
|
68
74
|
|
69
75
|
response = HTTPI.get request, adapter
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "mock_server"
|
3
|
+
|
4
|
+
IntegrationServer = Rack::Builder.new do
|
5
|
+
map "/" do
|
6
|
+
run lambda {|env|
|
7
|
+
case env["REQUEST_METHOD"]
|
8
|
+
when "HEAD" then
|
9
|
+
[200, {"Content-Type" => "text/plain", "Content-Length" => "5"}, []]
|
10
|
+
when "GET", "POST" then
|
11
|
+
[200, {"Content-Type" => "text/plain", "Content-Length" => "5"}, ["Hello"]]
|
12
|
+
when "PUT", "DELETE"
|
13
|
+
body = "#{env["REQUEST_METHOD"]} is not allowed"
|
14
|
+
[200, {"Content-Type" => "text/plain", "Content-Length" => body.size.to_s}, [body]]
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
map "/x-header" do
|
20
|
+
run lambda {|env|
|
21
|
+
body = "X-Header is #{env["HTTP_X_HEADER"]}"
|
22
|
+
[200, {"Content-Type" => "text/plain", "Content-Length" => body.size.to_s}, [body]]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
map "/auth" do
|
27
|
+
map "/basic" do
|
28
|
+
run Rack::Auth::Basic do |user, password|
|
29
|
+
user == "admin" && password == "secret"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
map "/digest" do
|
34
|
+
run Rack::Auth::Digest::MD5 do |username|
|
35
|
+
{"admin" => "pwd"}[username]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
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:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 4
|
10
|
+
version: 0.7.4
|
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: 2010-12-
|
19
|
+
date: 2010-12-20 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -71,14 +71,13 @@ dependencies:
|
|
71
71
|
requirement: &id004 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ~>
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
hash:
|
76
|
+
hash: 7
|
77
77
|
segments:
|
78
78
|
- 2
|
79
|
-
-
|
80
|
-
|
81
|
-
version: 2.0.0
|
79
|
+
- 2
|
80
|
+
version: "2.2"
|
82
81
|
type: :development
|
83
82
|
version_requirements: *id004
|
84
83
|
- !ruby/object:Gem::Dependency
|
@@ -159,6 +158,7 @@ files:
|
|
159
158
|
- spec/httpi/request_spec.rb
|
160
159
|
- spec/httpi/response_spec.rb
|
161
160
|
- spec/integration/request_spec.rb
|
161
|
+
- spec/integration/server.rb
|
162
162
|
- spec/spec_helper.rb
|
163
163
|
- spec/support/fixture.rb
|
164
164
|
- spec/support/matchers.rb
|