patron 0.12.1 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/ext/patron/session_ext.c +8 -2
- data/lib/patron/request.rb +10 -8
- data/lib/patron/version.rb +1 -1
- data/patron.gemspec +2 -2
- data/spec/request_spec.rb +0 -4
- data/spec/session_spec.rb +6 -1
- data/spec/session_ssl_spec.rb +3 -1
- data/spec/support/config.ru +3 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdaf7a10ef1cf673746f7f87ae77a9d939b461fc
|
4
|
+
data.tar.gz: 772139466802595a3906e24f297da437de3df880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94787a3fd98f9253862432e8069c5088dfc703f3bb6e69ebb2e60f86d70a489a8cb2c72d2134e690649d0e908ff08068631e0cc148f41b331fca5cf4f95dc6cb
|
7
|
+
data.tar.gz: 19496dff4f0687cbcd664c3aa81969c5b1a810aba28f87ab9f918a05771a5567d348acdc8b862c2b430e9304854796e034fc9d68361aa2d5b16e2cd0b17bd63b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
### 0.13.0
|
2
|
+
|
3
|
+
* Permit timeouts to be set as a Float of seconds and use `CURLOPT_(CONNECT)TIMEOUT_MS` instead of `CURLOPT_(CONNECT)TIMEOUT` so that
|
4
|
+
sub-second timeouts can be configured, which is useful for performant services using accelerated DNS resolution.
|
5
|
+
* Remove the restriction that `Session#timeout` should be non-zero - a timeout set to 0 means "no timeout" in libCURL
|
6
|
+
|
1
7
|
### 0.12.1
|
2
8
|
|
3
9
|
* Ensure HTTP2 response headers/status lines are correctly handled
|
data/ext/patron/session_ext.c
CHANGED
@@ -401,6 +401,12 @@ static void set_request_body_file(struct patron_curl_state* state, VALUE r_path_
|
|
401
401
|
#endif
|
402
402
|
}
|
403
403
|
|
404
|
+
static long floating_rb_seconds_to_milliseconds(VALUE r_seconds) {
|
405
|
+
double seconds_f = NUM2DBL(r_seconds);
|
406
|
+
long millis = seconds_f * (double)1000.0;
|
407
|
+
return millis;
|
408
|
+
}
|
409
|
+
|
404
410
|
static void set_request_body(struct patron_curl_state* state, VALUE stringable_or_file) {
|
405
411
|
CURL* curl = state->handle;
|
406
412
|
if(rb_respond_to(stringable_or_file, rb_intern("to_path"))) {
|
@@ -580,12 +586,12 @@ static void set_options_from_request(VALUE self, VALUE request) {
|
|
580
586
|
|
581
587
|
timeout = rb_funcall(request, rb_intern("timeout"), 0);
|
582
588
|
if (RTEST(timeout)) {
|
583
|
-
curl_easy_setopt(curl,
|
589
|
+
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, floating_rb_seconds_to_milliseconds(timeout));
|
584
590
|
}
|
585
591
|
|
586
592
|
timeout = rb_funcall(request, rb_intern("connect_timeout"), 0);
|
587
593
|
if (RTEST(timeout)) {
|
588
|
-
curl_easy_setopt(curl,
|
594
|
+
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, floating_rb_seconds_to_milliseconds(timeout));
|
589
595
|
}
|
590
596
|
|
591
597
|
timeout = rb_funcall(request, rb_intern("dns_cache_timeout"), 0);
|
data/lib/patron/request.rb
CHANGED
@@ -88,26 +88,28 @@ module Patron
|
|
88
88
|
@action = action.downcase.to_sym
|
89
89
|
end
|
90
90
|
|
91
|
-
# Sets the read timeout for the CURL request, in seconds
|
91
|
+
# Sets the read timeout for the CURL request, in seconds.
|
92
|
+
# Can be set to less than a second using a floating-point value.
|
93
|
+
# Setting the value to 0 will disable the timeout.
|
92
94
|
#
|
93
95
|
# @param new_timeout[Integer] the number of seconds to wait before raising a timeout error
|
94
96
|
def timeout=(new_timeout)
|
95
|
-
if new_timeout && new_timeout.
|
96
|
-
raise ArgumentError, "Timeout must be a positive
|
97
|
+
if new_timeout && new_timeout.to_f < 0
|
98
|
+
raise ArgumentError, "Timeout must be a positive number"
|
97
99
|
end
|
98
|
-
|
99
|
-
@timeout = new_timeout.to_i
|
100
|
+
@timeout = new_timeout.to_f
|
100
101
|
end
|
101
102
|
|
102
103
|
# Sets the connect timeout for the CURL request, in seconds.
|
104
|
+
# Can be set to less than a second using a floating-point value.
|
103
105
|
#
|
104
106
|
# @param new_timeout[Integer] the number of seconds to wait before raising a timeout error
|
105
107
|
def connect_timeout=(new_timeout)
|
106
|
-
if new_timeout && new_timeout.
|
107
|
-
raise ArgumentError, "Timeout must be a positive
|
108
|
+
if new_timeout && new_timeout.to_f < 0
|
109
|
+
raise ArgumentError, "Timeout must be a positive number"
|
108
110
|
end
|
109
111
|
|
110
|
-
@connect_timeout = new_timeout.
|
112
|
+
@connect_timeout = new_timeout.to_f
|
111
113
|
end
|
112
114
|
|
113
115
|
# Sets the maximum number of redirects that are going to be followed.
|
data/lib/patron/version.rb
CHANGED
data/patron.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
else
|
21
21
|
raise "RubyGems 2.0 or newer is required to protect against public gem pushespec."
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
spec.required_rubygems_version = ">= 1.2.0"
|
25
25
|
spec.rubyforge_project = "patron"
|
26
26
|
|
@@ -39,7 +39,7 @@ For more info see https://github.com/curl/curl/issues/788
|
|
39
39
|
spec.add_development_dependency "bundler", ">= 1"
|
40
40
|
spec.add_development_dependency "rspec", ">= 2.3.0"
|
41
41
|
spec.add_development_dependency "simplecov", "~> 0.10"
|
42
|
-
spec.add_development_dependency "yard", "~> 0.
|
42
|
+
spec.add_development_dependency "yard", "~> 0.9.11"
|
43
43
|
spec.add_development_dependency "rack", "~> 1"
|
44
44
|
spec.add_development_dependency "puma", '~> 3.11'
|
45
45
|
spec.add_development_dependency "rake-compiler"
|
data/spec/request_spec.rb
CHANGED
@@ -27,10 +27,6 @@ describe Patron::Request do
|
|
27
27
|
expect {@request.timeout = -1}.to raise_error(ArgumentError)
|
28
28
|
end
|
29
29
|
|
30
|
-
it "should raise an exception when assigned 0" do
|
31
|
-
expect {@request.timeout = 0}.to raise_error(ArgumentError)
|
32
|
-
end
|
33
|
-
|
34
30
|
end
|
35
31
|
|
36
32
|
describe :max_redirects do
|
data/spec/session_spec.rb
CHANGED
@@ -173,7 +173,12 @@ describe Patron::Session do
|
|
173
173
|
|
174
174
|
it "should raise an exception on timeout" do
|
175
175
|
@session.timeout = 1
|
176
|
-
expect {@session.get("/timeout")}.to raise_error(Patron::TimeoutError)
|
176
|
+
expect {@session.get("/timeout?millis=1100")}.to raise_error(Patron::TimeoutError)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should raise an exception on a sub-second timeout" do
|
180
|
+
@session.timeout = 0.3
|
181
|
+
expect {@session.get("/timeout?millis=400")}.to raise_error(Patron::TimeoutError)
|
177
182
|
end
|
178
183
|
|
179
184
|
it "should raise an exception on timeout when reading from a slow resource" do
|
data/spec/session_ssl_spec.rb
CHANGED
@@ -73,7 +73,9 @@ describe Patron::Session do
|
|
73
73
|
|
74
74
|
it "should raise an exception on timeout" do
|
75
75
|
@session.timeout = 1
|
76
|
-
expect {
|
76
|
+
expect {
|
77
|
+
@session.get("/timeout?millis=1100")
|
78
|
+
}.to raise_error(Patron::TimeoutError)
|
77
79
|
end
|
78
80
|
|
79
81
|
it "should follow redirects by default" do
|
data/spec/support/config.ru
CHANGED
@@ -51,7 +51,9 @@ GzipServlet = Proc.new {|env|
|
|
51
51
|
}
|
52
52
|
|
53
53
|
TimeoutServlet = Proc.new {|env|
|
54
|
-
|
54
|
+
query_vars = Rack::Utils.parse_nested_query(env.fetch('QUERY_STRING'))
|
55
|
+
query_millis = query_vars.fetch('millis').to_i
|
56
|
+
sleep(query_millis / 1000.0)
|
55
57
|
[200, {'Content-Type' => 'text/plain'}, ['That took a while']]
|
56
58
|
}
|
57
59
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: patron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phillip Toland
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.9.11
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.9.11
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rack
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -204,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
204
|
version: 1.2.0
|
205
205
|
requirements: []
|
206
206
|
rubyforge_project: patron
|
207
|
-
rubygems_version: 2.
|
207
|
+
rubygems_version: 2.5.2
|
208
208
|
signing_key:
|
209
209
|
specification_version: 4
|
210
210
|
summary: Patron HTTP Client
|