patron 0.12.1 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d150d662006fa9751021e94126b0ef52432fb45
4
- data.tar.gz: 240cfef423d0c4aec7c363da618bbd8966d9d8a0
3
+ metadata.gz: cdaf7a10ef1cf673746f7f87ae77a9d939b461fc
4
+ data.tar.gz: 772139466802595a3906e24f297da437de3df880
5
5
  SHA512:
6
- metadata.gz: 75e5e3b6c0c4df36c763ee3a84efdd0771599aae2eed85fb0c8f91596d9304a06e2a209f1b06283b1a461d88dfe6a3eebd34f594e18f7b57bb44d119a256fbed
7
- data.tar.gz: d5ae239b30d06e0c143d2fe821bf5110f17aa811b83c69ccabb02e1d2b4a96a954e3eb9fc5509fdd88adc4fc765db0ce53f537e788c6873e769b494005536e94
6
+ metadata.gz: 94787a3fd98f9253862432e8069c5088dfc703f3bb6e69ebb2e60f86d70a489a8cb2c72d2134e690649d0e908ff08068631e0cc148f41b331fca5cf4f95dc6cb
7
+ data.tar.gz: 19496dff4f0687cbcd664c3aa81969c5b1a810aba28f87ab9f918a05771a5567d348acdc8b862c2b430e9304854796e034fc9d68361aa2d5b16e2cd0b17bd63b
@@ -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
@@ -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, CURLOPT_TIMEOUT, FIX2INT(timeout));
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, CURLOPT_CONNECTTIMEOUT, FIX2INT(timeout));
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);
@@ -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.to_i < 1
96
- raise ArgumentError, "Timeout must be a positive integer greater than 0"
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.to_i < 1
107
- raise ArgumentError, "Timeout must be a positive integer greater than 0"
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.to_i
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.
@@ -1,3 +1,3 @@
1
1
  module Patron
2
- VERSION = "0.12.1"
2
+ VERSION = "0.13.1"
3
3
  end
@@ -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.8"
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"
@@ -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
@@ -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
@@ -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 {@session.get("/timeout")}.to raise_error(Patron::TimeoutError)
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
@@ -51,7 +51,9 @@ GzipServlet = Proc.new {|env|
51
51
  }
52
52
 
53
53
  TimeoutServlet = Proc.new {|env|
54
- sleep 1.1
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.12.1
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-02-20 00:00:00.000000000 Z
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: '0.8'
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: '0.8'
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.6.11
207
+ rubygems_version: 2.5.2
208
208
  signing_key:
209
209
  specification_version: 4
210
210
  summary: Patron HTTP Client