patron 0.4.20 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +27 -13
- data/README.md +17 -0
- data/Rakefile +1 -8
- data/ext/patron/extconf.rb +3 -1
- data/ext/patron/session_ext.c +17 -5
- data/lib/patron/request.rb +3 -3
- data/lib/patron/response.rb +15 -13
- data/lib/patron/session.rb +23 -7
- data/lib/patron/version.rb +1 -1
- data/patron.gemspec +1 -1
- data/spec/patron_spec.rb +2 -2
- data/spec/request_spec.rb +11 -11
- data/spec/response_spec.rb +6 -6
- data/spec/session_spec.rb +138 -60
- data/spec/session_ssl_spec.rb +52 -53
- data/spec/spec_helper.rb +10 -0
- data/spec/util_spec.rb +20 -20
- metadata +21 -31
data/spec/session_ssl_spec.rb
CHANGED
@@ -38,197 +38,197 @@ describe Patron::Session do
|
|
38
38
|
it "should retrieve a url with :get" do
|
39
39
|
response = @session.get("/test")
|
40
40
|
body = YAML::load(response.body)
|
41
|
-
body.request_method.
|
41
|
+
expect(body.request_method).to be == "GET"
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should download content with :get and a file path" do
|
45
45
|
tmpfile = "/tmp/patron_test.yaml"
|
46
46
|
response = @session.get_file "/test", tmpfile
|
47
|
-
response.body.
|
47
|
+
expect(response.body).to be_nil
|
48
48
|
body = YAML::load_file(tmpfile)
|
49
|
-
body.request_method.
|
49
|
+
expect(body.request_method).to be == "GET"
|
50
50
|
FileUtils.rm tmpfile
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should download correctly(md5 ok) with get_file" do
|
54
54
|
tmpfile = "/tmp/picture"
|
55
55
|
response = @session.get_file "/picture", tmpfile
|
56
|
-
response.body.
|
57
|
-
File.size(File.join(File.dirname(__FILE__),"../pic.png")).
|
56
|
+
expect(response.body).to be_nil
|
57
|
+
expect(File.size(File.join(File.dirname(__FILE__),"../pic.png"))).to be == File.size(tmpfile)
|
58
58
|
FileUtils.rm tmpfile
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should include custom headers in a request" do
|
62
62
|
response = @session.get("/test", {"User-Agent" => "PatronTest"})
|
63
63
|
body = YAML::load(response.body)
|
64
|
-
body.header["user-agent"].
|
64
|
+
expect(body.header["user-agent"]).to be == ["PatronTest"]
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should merge custom headers with session headers" do
|
68
68
|
@session.headers["X-Test"] = "Testing"
|
69
69
|
response = @session.get("/test", {"User-Agent" => "PatronTest"})
|
70
70
|
body = YAML::load(response.body)
|
71
|
-
body.header["user-agent"].
|
72
|
-
body.header["x-test"].
|
71
|
+
expect(body.header["user-agent"]).to be == ["PatronTest"]
|
72
|
+
expect(body.header["x-test"]).to be == ["Testing"]
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should raise an exception on timeout" do
|
76
76
|
@session.timeout = 1
|
77
|
-
|
77
|
+
expect {@session.get("/timeout")}.to raise_error(Patron::TimeoutError)
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should follow redirects by default" do
|
81
81
|
@session.max_redirects = 1
|
82
82
|
response = @session.get("/redirect")
|
83
83
|
body = YAML::load(response.body)
|
84
|
-
response.status.
|
85
|
-
body.path.
|
84
|
+
expect(response.status).to be == 200
|
85
|
+
expect(body.path).to be == "/test"
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should include redirect count in response" do
|
89
89
|
@session.max_redirects = 1
|
90
90
|
response = @session.get("/redirect")
|
91
|
-
response.redirect_count.
|
91
|
+
expect(response.redirect_count).to be == 1
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should not follow redirects when configured to do so" do
|
95
95
|
@session.max_redirects = 0
|
96
96
|
response = @session.get("/redirect")
|
97
|
-
response.status.
|
98
|
-
response.body.
|
97
|
+
expect(response.status).to be == 301
|
98
|
+
expect(response.body).to be_empty
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should retrieve URL metadata with :head" do
|
102
102
|
response = @session.head("/test")
|
103
|
-
response.status.
|
104
|
-
response.body.
|
105
|
-
response.headers.
|
103
|
+
expect(response.status).to be == 200
|
104
|
+
expect(response.body).to be_empty
|
105
|
+
expect(response.headers).to_not be_empty
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should send a delete request with :delete" do
|
109
109
|
response = @session.delete("/test")
|
110
110
|
body = YAML::load(response.body)
|
111
|
-
body.request_method.
|
111
|
+
expect(body.request_method).to be == "DELETE"
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should send a COPY request with :copy" do
|
115
115
|
response = @session.copy("/test", "/test2")
|
116
116
|
body = YAML::load(response.body)
|
117
|
-
body.request_method.
|
117
|
+
expect(body.request_method).to be == "COPY"
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should include a Destination header in COPY requests" do
|
121
121
|
response = @session.copy("/test", "/test2")
|
122
122
|
body = YAML::load(response.body)
|
123
|
-
body.header['destination'].first.
|
123
|
+
expect(body.header['destination'].first).to be == "/test2"
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should upload data with :get" do
|
127
127
|
data = "upload data"
|
128
128
|
response = @session.request(:get, "/test", {}, :data => data)
|
129
129
|
body = YAML::load(response.body)
|
130
|
-
body.request_method.
|
131
|
-
body.header['content-length'].
|
130
|
+
expect(body.request_method).to be == "GET"
|
131
|
+
expect(body.header['content-length']).to be == [data.size.to_s]
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should upload data with :put" do
|
135
135
|
data = "upload data"
|
136
136
|
response = @session.put("/test", data)
|
137
137
|
body = YAML::load(response.body)
|
138
|
-
body.request_method.
|
139
|
-
body.header['content-length'].
|
138
|
+
expect(body.request_method).to be == "PUT"
|
139
|
+
expect(body.header['content-length']).to be == [data.size.to_s]
|
140
140
|
end
|
141
141
|
|
142
142
|
it "should raise when no data is provided to :put" do
|
143
|
-
|
143
|
+
expect { @session.put("/test", nil) }.to raise_error(ArgumentError)
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should upload a file with :put" do
|
147
147
|
response = @session.put_file("/test", "LICENSE")
|
148
148
|
body = YAML::load(response.body)
|
149
|
-
body.request_method.
|
149
|
+
expect(body.request_method).to be == "PUT"
|
150
150
|
end
|
151
151
|
|
152
152
|
it "should raise when no file is provided to :put" do
|
153
|
-
|
153
|
+
expect { @session.put_file("/test", nil) }.to raise_error(ArgumentError)
|
154
154
|
end
|
155
155
|
|
156
156
|
it "should use chunked encoding when uploading a file with :put" do
|
157
157
|
response = @session.put_file("/test", "LICENSE")
|
158
158
|
body = YAML::load(response.body)
|
159
|
-
body.header['transfer-encoding'].first.
|
159
|
+
expect(body.header['transfer-encoding'].first).to be == "chunked"
|
160
160
|
end
|
161
161
|
|
162
162
|
it "should upload data with :post" do
|
163
163
|
data = "upload data"
|
164
164
|
response = @session.post("/test", data)
|
165
165
|
body = YAML::load(response.body)
|
166
|
-
body.request_method.
|
167
|
-
body.header['content-length'].
|
166
|
+
expect(body.request_method).to be == "POST"
|
167
|
+
expect(body.header['content-length']).to be == [data.size.to_s]
|
168
168
|
end
|
169
169
|
|
170
170
|
it "should post a hash of arguments as a urlencoded form" do
|
171
171
|
data = {:foo => 123, 'baz' => '++hello world++'}
|
172
172
|
response = @session.post("/testpost", data)
|
173
173
|
body = YAML::load(response.body)
|
174
|
-
body['content_type'].
|
175
|
-
body['body'].
|
176
|
-
body['body'].
|
174
|
+
expect(body['content_type']).to be == "application/x-www-form-urlencoded"
|
175
|
+
expect(body['body']).to match(/baz=%2B%2Bhello%20world%2B%2B/)
|
176
|
+
expect(body['body']).to match(/foo=123/)
|
177
177
|
end
|
178
178
|
|
179
179
|
it "should raise when no data is provided to :post" do
|
180
|
-
|
180
|
+
expect { @session.post("/test", nil) }.to raise_error(ArgumentError)
|
181
181
|
end
|
182
182
|
|
183
183
|
it "should upload a file with :post" do
|
184
184
|
response = @session.post_file("/test", "LICENSE")
|
185
185
|
body = YAML::load(response.body)
|
186
|
-
body.request_method.
|
186
|
+
expect(body.request_method).to be == "POST"
|
187
187
|
end
|
188
188
|
|
189
189
|
it "should upload a multipart with :post" do
|
190
190
|
response = @session.post_multipart("/test", { :test_data => "123" }, { :test_file => "LICENSE" } )
|
191
191
|
body = YAML::load(response.body)
|
192
|
-
body.request_method.
|
192
|
+
expect(body.request_method).to be == "POST"
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should raise when no file is provided to :post" do
|
196
|
-
|
196
|
+
expect { @session.post_file("/test", nil) }.to raise_error(ArgumentError)
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should use chunked encoding when uploading a file with :post" do
|
200
200
|
response = @session.post_file("/test", "LICENSE")
|
201
201
|
body = YAML::load(response.body)
|
202
|
-
body.header['transfer-encoding'].first.
|
202
|
+
expect(body.header['transfer-encoding'].first).to be == "chunked"
|
203
203
|
end
|
204
204
|
|
205
205
|
it "should handle cookies if set" do
|
206
206
|
@session.handle_cookies
|
207
207
|
response = @session.get("/setcookie").body
|
208
|
-
YAML::load(response).header['cookie'].first.
|
208
|
+
expect(YAML::load(response).header['cookie'].first).to be == "session_id=foo123"
|
209
209
|
end
|
210
210
|
|
211
211
|
it "should not handle cookies by default" do
|
212
212
|
response = @session.get("/setcookie").body
|
213
|
-
YAML::load(response).header.
|
213
|
+
expect(YAML::load(response).header).to_not include('cookie')
|
214
214
|
end
|
215
215
|
|
216
216
|
it "should ignore a wrong Content-Length when asked to" do
|
217
|
-
|
217
|
+
expect {
|
218
218
|
@session.ignore_content_length = true
|
219
219
|
@session.get("/wrongcontentlength")
|
220
|
-
}.
|
220
|
+
}.to_not raise_error
|
221
221
|
end
|
222
222
|
|
223
223
|
it "should fail by default with a Content-Length too high" do
|
224
|
-
|
224
|
+
expect {
|
225
225
|
@session.ignore_content_length = nil
|
226
226
|
@session.get("/wrongcontentlength")
|
227
|
-
}.
|
227
|
+
}.to raise_error(Patron::PartialFileError)
|
228
228
|
end
|
229
229
|
|
230
230
|
it "should raise exception if cookie store is not writable or readable" do
|
231
|
-
|
231
|
+
expect { @session.handle_cookies("/trash/clash/foo") }.to raise_error(ArgumentError)
|
232
232
|
end
|
233
233
|
|
234
234
|
it "should work with multiple threads" do
|
@@ -244,12 +244,11 @@ describe Patron::Session do
|
|
244
244
|
threads.each {|t| t.join }
|
245
245
|
end
|
246
246
|
|
247
|
-
|
248
|
-
|
249
|
-
lambda {
|
247
|
+
it "should fail when insecure mode is off" do
|
248
|
+
expect {
|
250
249
|
@session.insecure = nil
|
251
250
|
response = @session.get("/test")
|
252
|
-
}.
|
251
|
+
}.to raise_error(Patron::Error)
|
253
252
|
end
|
254
253
|
|
255
254
|
it "should work when insecure mode is off but certificate is supplied" do
|
@@ -257,14 +256,14 @@ describe Patron::Session do
|
|
257
256
|
@session.cacert = 'spec/certs/cacert.pem'
|
258
257
|
response = @session.get("/test")
|
259
258
|
body = YAML::load(response.body)
|
260
|
-
body.request_method.
|
259
|
+
expect(body.request_method).to be == "GET"
|
261
260
|
end
|
262
261
|
|
263
262
|
it "should work with different SSL versions" do
|
264
263
|
['SSLv3', 'TLSv1'].each do |version|
|
265
264
|
@session.ssl_version = version
|
266
265
|
response = @session.get("/test")
|
267
|
-
response.status.
|
266
|
+
expect(response.status).to be == 200
|
268
267
|
end
|
269
268
|
end
|
270
269
|
|
@@ -274,10 +273,10 @@ describe Patron::Session do
|
|
274
273
|
rdev = STDERR.stat.rdev
|
275
274
|
|
276
275
|
@session.enable_debug
|
277
|
-
STDERR.stat.rdev.
|
276
|
+
expect(STDERR.stat.rdev).to be == rdev
|
278
277
|
|
279
278
|
@session.enable_debug
|
280
|
-
STDERR.stat.rdev.
|
279
|
+
expect(STDERR.stat.rdev).to be == rdev
|
281
280
|
end
|
282
281
|
end
|
283
282
|
|
data/spec/spec_helper.rb
CHANGED
@@ -21,7 +21,17 @@
|
|
21
21
|
## THE SOFTWARE.
|
22
22
|
##
|
23
23
|
## -------------------------------------------------------------------
|
24
|
+
if ENV["COVERAGE"]
|
25
|
+
require 'simplecov'
|
26
|
+
SimpleCov.start do
|
27
|
+
add_filter "/spec/"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
24
31
|
require 'rspec'
|
32
|
+
# Kill warnings that not raising a specific exception still allows the method
|
33
|
+
# to fail with another exception
|
34
|
+
RSpec::Expectations.configuration.warn_about_potential_false_positives = false
|
25
35
|
|
26
36
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
27
37
|
$:.unshift(File.dirname(__FILE__) + '/../ext')
|
data/spec/util_spec.rb
CHANGED
@@ -24,14 +24,14 @@
|
|
24
24
|
require File.expand_path("./spec") + '/spec_helper.rb'
|
25
25
|
|
26
26
|
describe Patron::Util do
|
27
|
-
|
27
|
+
|
28
28
|
describe :build_query_pairs_from_hash do
|
29
29
|
it "correctly serializes a simple hash" do
|
30
30
|
hash = {:foo => "bar", "baz" => 42}
|
31
31
|
array = Patron::Util.build_query_pairs_from_hash(hash)
|
32
|
-
array.size.
|
33
|
-
array.
|
34
|
-
array.
|
32
|
+
expect(array.size).to be == 2
|
33
|
+
expect(array).to include("foo=bar")
|
34
|
+
expect(array).to include("baz=42")
|
35
35
|
end
|
36
36
|
it "correctly serializes a more complex hash" do
|
37
37
|
hash = {
|
@@ -49,21 +49,21 @@ describe Patron::Util do
|
|
49
49
|
}
|
50
50
|
}
|
51
51
|
array = Patron::Util.build_query_pairs_from_hash(hash)
|
52
|
-
array.size.
|
53
|
-
array.
|
54
|
-
array.
|
55
|
-
array.
|
56
|
-
array.
|
52
|
+
expect(array.size).to be == 4
|
53
|
+
expect(array).to include("foo=bar")
|
54
|
+
expect(array).to include("baz[quux][zing][ying]=42")
|
55
|
+
expect(array).to include("baz[blargh][spaz]=sox")
|
56
|
+
expect(array).to include("baz[blargh][razz]=matazz")
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
describe :build_query_string_from_hash do
|
61
61
|
it "correctly serializes a simple hash" do
|
62
62
|
hash = {:foo => "bar", "baz" => 42}
|
63
63
|
array = Patron::Util.build_query_string_from_hash(hash).split('&')
|
64
|
-
array.size.
|
65
|
-
array.
|
66
|
-
array.
|
64
|
+
expect(array.size).to be == 2
|
65
|
+
expect(array).to include("foo=bar")
|
66
|
+
expect(array).to include("baz=42")
|
67
67
|
end
|
68
68
|
it "correctly serializes a more complex hash" do
|
69
69
|
hash = {
|
@@ -81,12 +81,12 @@ describe Patron::Util do
|
|
81
81
|
}
|
82
82
|
}
|
83
83
|
array = Patron::Util.build_query_string_from_hash(hash).split('&')
|
84
|
-
array.size.
|
85
|
-
array.
|
86
|
-
array.
|
87
|
-
array.
|
88
|
-
array.
|
84
|
+
expect(array.size).to be == 4
|
85
|
+
expect(array).to include("foo=bar")
|
86
|
+
expect(array).to include("baz[quux][zing][ying]=42")
|
87
|
+
expect(array).to include("baz[blargh][spaz]=sox")
|
88
|
+
expect(array).to include("baz[blargh][razz]=matazz")
|
89
89
|
end
|
90
90
|
end
|
91
|
-
|
92
|
-
end
|
91
|
+
|
92
|
+
end
|
metadata
CHANGED
@@ -1,80 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: patron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Phillip Toland
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2015-
|
11
|
+
date: 2015-09-08 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 1.0.0
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 1.0.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake-compiler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 0.7.5
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 0.7.5
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: 2.3.0
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: 2.3.0
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
56
|
+
name: simplecov
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.
|
61
|
+
version: 0.10.0
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
|
-
version: 0.
|
68
|
+
version: 0.10.0
|
78
69
|
description: Ruby HTTP client library based on libcurl
|
79
70
|
email:
|
80
71
|
- phil.toland@gmail.com
|
@@ -83,9 +74,9 @@ extensions:
|
|
83
74
|
- ext/patron/extconf.rb
|
84
75
|
extra_rdoc_files: []
|
85
76
|
files:
|
86
|
-
- .autotest
|
87
|
-
- .gitignore
|
88
|
-
- .rspec
|
77
|
+
- ".autotest"
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
89
80
|
- Gemfile
|
90
81
|
- Gemfile.lock
|
91
82
|
- LICENSE
|
@@ -121,27 +112,26 @@ files:
|
|
121
112
|
- spec/util_spec.rb
|
122
113
|
homepage: https://github.com/toland/patron
|
123
114
|
licenses: []
|
115
|
+
metadata: {}
|
124
116
|
post_install_message:
|
125
117
|
rdoc_options: []
|
126
118
|
require_paths:
|
127
119
|
- lib
|
128
120
|
- ext
|
129
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
122
|
requirements:
|
132
|
-
- -
|
123
|
+
- - ">="
|
133
124
|
- !ruby/object:Gem::Version
|
134
125
|
version: '0'
|
135
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
-
none: false
|
137
127
|
requirements:
|
138
|
-
- -
|
128
|
+
- - ">="
|
139
129
|
- !ruby/object:Gem::Version
|
140
130
|
version: 1.2.0
|
141
131
|
requirements: []
|
142
132
|
rubyforge_project: patron
|
143
|
-
rubygems_version:
|
133
|
+
rubygems_version: 2.4.5.1
|
144
134
|
signing_key:
|
145
|
-
specification_version:
|
135
|
+
specification_version: 4
|
146
136
|
summary: Patron HTTP Client
|
147
137
|
test_files: []
|