httpi 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +10 -10
- data/README.md +40 -9
- data/lib/httpi.rb +9 -0
- data/lib/httpi/adapter/curb.rb +15 -6
- data/lib/httpi/adapter/httpclient.rb +20 -11
- data/lib/httpi/adapter/net_http.rb +14 -10
- data/lib/httpi/auth/config.rb +68 -0
- data/lib/httpi/auth/ssl.rb +76 -0
- data/lib/httpi/request.rb +32 -48
- data/lib/httpi/version.rb +1 -1
- data/spec/fixtures/client_cert.pem +16 -0
- data/spec/fixtures/client_key.pem +15 -0
- data/spec/httpi/adapter/curb_spec.rb +136 -10
- data/spec/httpi/adapter/httpclient_spec.rb +99 -33
- data/spec/httpi/adapter/net_http_spec.rb +99 -28
- data/spec/httpi/auth/config_spec.rb +117 -0
- data/spec/httpi/auth/ssl_spec.rb +112 -0
- data/spec/httpi/httpi_spec.rb +45 -37
- data/spec/httpi/request_spec.rb +38 -73
- data/spec/integration/request_spec.rb +3 -3
- metadata +14 -10
data/spec/httpi/request_spec.rb
CHANGED
@@ -5,15 +5,15 @@ describe HTTPI::Request do
|
|
5
5
|
let(:request) { HTTPI::Request.new }
|
6
6
|
|
7
7
|
describe ".new" do
|
8
|
-
it "
|
9
|
-
request = HTTPI::Request.new
|
8
|
+
it "should accept just a url" do
|
9
|
+
request = HTTPI::Request.new "http://example.com"
|
10
10
|
request.url.should == URI("http://example.com")
|
11
|
-
request.open_timeout.should == 30
|
12
11
|
end
|
13
12
|
|
14
|
-
it "
|
15
|
-
request = HTTPI::Request.new :
|
16
|
-
request.
|
13
|
+
it "should accept a Hash of accessors to set" do
|
14
|
+
request = HTTPI::Request.new :url => "http://example.com", :open_timeout => 30
|
15
|
+
request.url.should == URI("http://example.com")
|
16
|
+
request.open_timeout.should == 30
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -49,6 +49,29 @@ describe HTTPI::Request do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
describe "#ssl" do
|
53
|
+
it "should return false if no request url was specified" do
|
54
|
+
request.should_not be_ssl
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return false if the request url does not start with https" do
|
58
|
+
request.url = "http://example.com"
|
59
|
+
request.should_not be_ssl
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return true if the request url starts with https" do
|
63
|
+
request.url = "https://example.com"
|
64
|
+
request.should be_ssl
|
65
|
+
end
|
66
|
+
|
67
|
+
context "with an explicit value" do
|
68
|
+
it "should return the value" do
|
69
|
+
request.ssl = true
|
70
|
+
request.should be_ssl
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
52
75
|
describe "#headers" do
|
53
76
|
it "lets you specify a Hash of HTTP request headers" do
|
54
77
|
request.headers = { "Accept-Encoding" => "gzip" }
|
@@ -88,83 +111,25 @@ describe HTTPI::Request do
|
|
88
111
|
end
|
89
112
|
end
|
90
113
|
|
91
|
-
describe "#
|
92
|
-
it "
|
93
|
-
request.
|
94
|
-
request.basic_auth.should == ["username", "password"]
|
95
|
-
end
|
96
|
-
|
97
|
-
it "also accepts an Array of credentials" do
|
98
|
-
request.basic_auth ["username", "password"]
|
99
|
-
request.basic_auth.should == ["username", "password"]
|
100
|
-
end
|
101
|
-
|
102
|
-
it "lets you reset the credentials" do
|
103
|
-
request.basic_auth "username", "password"
|
104
|
-
request.basic_auth.should == ["username", "password"]
|
105
|
-
|
106
|
-
request.basic_auth nil
|
107
|
-
request.basic_auth.should be_nil
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "#digest_auth" do
|
112
|
-
it "lets you specify the digest auth credentials" do
|
113
|
-
request.digest_auth "username", "password"
|
114
|
-
request.digest_auth.should == ["username", "password"]
|
114
|
+
describe "#auth" do
|
115
|
+
it "should return the authentication object" do
|
116
|
+
request.auth.should be_an(HTTPI::Auth::Config)
|
115
117
|
end
|
116
|
-
|
117
|
-
it "also accepts an Array of credentials" do
|
118
|
-
request.digest_auth ["username", "password"]
|
119
|
-
request.digest_auth.should == ["username", "password"]
|
120
|
-
end
|
121
|
-
|
122
|
-
it "lets you reset the credentials" do
|
123
|
-
request.digest_auth "username", "password"
|
124
|
-
request.digest_auth.should == ["username", "password"]
|
125
118
|
|
126
|
-
|
127
|
-
request.
|
119
|
+
it "should memoize the authentication object" do
|
120
|
+
request.auth.should equal(request.auth)
|
128
121
|
end
|
129
122
|
end
|
130
123
|
|
131
124
|
describe "#auth?" do
|
132
|
-
it "should return
|
133
|
-
request.auth
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should return true if HTTP basic auth authentication credentials were specified" do
|
137
|
-
request.basic_auth "username", "password"
|
125
|
+
it "should return true when auth credentials are specified" do
|
126
|
+
request.auth.basic "username", "password"
|
138
127
|
request.auth?.should be_true
|
139
128
|
end
|
140
129
|
|
141
|
-
it "should return
|
142
|
-
request.
|
143
|
-
request.auth?.should be_true
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "#credentials" do
|
148
|
-
it "return the credentials for HTTP basic auth" do
|
149
|
-
request.basic_auth "username", "basic"
|
150
|
-
request.credentials.should == ["username", "basic"]
|
151
|
-
end
|
152
|
-
|
153
|
-
it "return the credentials for HTTP digest auth" do
|
154
|
-
request.digest_auth "username", "digest"
|
155
|
-
request.credentials.should == ["username", "digest"]
|
130
|
+
it "should return false otherwise" do
|
131
|
+
request.auth?.should be_false
|
156
132
|
end
|
157
133
|
end
|
158
134
|
|
159
|
-
describe "#auth_type" do
|
160
|
-
it "should return :basic for HTTP basic auth" do
|
161
|
-
request.basic_auth "username", "password"
|
162
|
-
request.auth_type.should == :basic
|
163
|
-
end
|
164
|
-
|
165
|
-
it "should return :digest for HTTP basic auth" do
|
166
|
-
request.digest_auth "username", "password"
|
167
|
-
request.auth_type.should == :digest
|
168
|
-
end
|
169
|
-
end
|
170
135
|
end
|
@@ -48,7 +48,7 @@ describe HTTPI do
|
|
48
48
|
shared_examples_for "it works with HTTP basic auth" do
|
49
49
|
it "and access a secured page" do
|
50
50
|
request = HTTPI::Request.new :url => "http://test.webdav.org/auth-basic/"
|
51
|
-
request.
|
51
|
+
request.auth.basic @username, @password
|
52
52
|
|
53
53
|
response = HTTPI.get request, adapter
|
54
54
|
response.body.should_not include(@error_message)
|
@@ -56,9 +56,9 @@ describe HTTPI do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
shared_examples_for "it works with HTTP digest auth" do
|
59
|
-
it "
|
59
|
+
it "and access a secured page" do
|
60
60
|
request = HTTPI::Request.new :url => "http://test.webdav.org/auth-digest/"
|
61
|
-
request.
|
61
|
+
request.auth.digest @username, @password
|
62
62
|
|
63
63
|
response = HTTPI.get request, adapter
|
64
64
|
response.body.should_not include(@error_message)
|
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: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 6
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.6.0
|
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-10-
|
19
|
+
date: 2010-10-15 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -57,16 +57,14 @@ dependencies:
|
|
57
57
|
requirement: &id003 !ruby/object:Gem::Requirement
|
58
58
|
none: false
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ~>
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
hash:
|
62
|
+
hash: 15
|
63
63
|
segments:
|
64
64
|
- 2
|
65
65
|
- 0
|
66
66
|
- 0
|
67
|
-
|
68
|
-
- 22
|
69
|
-
version: 2.0.0.beta.22
|
67
|
+
version: 2.0.0
|
70
68
|
type: :development
|
71
69
|
version_requirements: *id003
|
72
70
|
- !ruby/object:Gem::Dependency
|
@@ -101,7 +99,7 @@ dependencies:
|
|
101
99
|
version: 1.3.5
|
102
100
|
type: :development
|
103
101
|
version_requirements: *id005
|
104
|
-
description: HTTPI provides a common interface for
|
102
|
+
description: HTTPI provides a common interface for Ruby HTTP libraries.
|
105
103
|
email: me@rubiii.com
|
106
104
|
executables: []
|
107
105
|
|
@@ -122,16 +120,22 @@ files:
|
|
122
120
|
- lib/httpi/adapter/httpclient.rb
|
123
121
|
- lib/httpi/adapter/net_http.rb
|
124
122
|
- lib/httpi/adapter.rb
|
123
|
+
- lib/httpi/auth/config.rb
|
124
|
+
- lib/httpi/auth/ssl.rb
|
125
125
|
- lib/httpi/request.rb
|
126
126
|
- lib/httpi/response.rb
|
127
127
|
- lib/httpi/version.rb
|
128
128
|
- lib/httpi.rb
|
129
|
+
- spec/fixtures/client_cert.pem
|
130
|
+
- spec/fixtures/client_key.pem
|
129
131
|
- spec/fixtures/xml.gz
|
130
132
|
- spec/fixtures/xml.xml
|
131
133
|
- spec/httpi/adapter/curb_spec.rb
|
132
134
|
- spec/httpi/adapter/httpclient_spec.rb
|
133
135
|
- spec/httpi/adapter/net_http_spec.rb
|
134
136
|
- spec/httpi/adapter_spec.rb
|
137
|
+
- spec/httpi/auth/config_spec.rb
|
138
|
+
- spec/httpi/auth/ssl_spec.rb
|
135
139
|
- spec/httpi/httpi_spec.rb
|
136
140
|
- spec/httpi/request_spec.rb
|
137
141
|
- spec/httpi/response_spec.rb
|