nethttputils 0.2.0.0 → 0.2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71be1aac2cdebb5316afe367b7b7bd2eb8b5b60d
4
- data.tar.gz: 4026ab5f4299bc880b3f8c13881114f4e49c67fd
3
+ metadata.gz: b121e7caf98fdda077b6a6ce67ef2e1277829f7c
4
+ data.tar.gz: 07e674c4a0871c31dd395a16708c36f6ad49d823
5
5
  SHA512:
6
- metadata.gz: 7fe70ebe65005756f847deb19f318d77ae8c46298420f869caa5d4a2cb75de826b0634f758048f8190188b7704469fa73a84435572dd585e325d62b30e26290e
7
- data.tar.gz: 58debad4370c8c99abbbd149fcb02c553e674d79dcd89cd294d306f59429c7ede3e58518c4b20127107dfeb7fed5476aa25a5e8ffadc4eeabd54d9870ed44233
6
+ metadata.gz: 20ef4802fb7b8f94cd368a9dba376de344d095143e7fc42c9bc9dbca22218ec52e20b0c203f2feabd3d1475e9ee214328df1082bef532810ba3579e65dcab59b
7
+ data.tar.gz: c584c61a2dcede5c3b503c45a32aa97b946c2362862edec6fd225be5b98bb8b0aa6907874835f1633376942304110992bb7df42775d4352c19e4527ec034cafa
@@ -0,0 +1,22 @@
1
+ ---
2
+ language: ruby
3
+
4
+ script: "ruby lib/nethttputils.rb"
5
+
6
+ os:
7
+ - linux
8
+ - osx
9
+ rvm:
10
+ - ruby-head
11
+ - 2.5
12
+ - 2.4
13
+ - 2.3
14
+ - 2.2
15
+ - 2.1
16
+ - 2.0
17
+ - jruby-head
18
+ matrix:
19
+ allow_failures:
20
+ # something with `NetHTTPUtils.request_data("http://localhost:8000/?1=2&3=4", form: {1=>3})` test
21
+ - rvm: jruby-head
22
+ os: linux
@@ -29,7 +29,7 @@ module NetHTTPUtils
29
29
  end
30
30
 
31
31
  # TODO: make it private?
32
- def get_response url, mtd = :GET, type = :form, form: {}, header: {}, auth: nil, timeout: 30, max_timeout_retry_delay: 3600, max_sslerror_retry_delay: 3600, max_read_retry_delay: 3600, max_econnrefused_retry_delay: 3600, patch_request: nil, &block
32
+ def get_response url, mtd = :GET, type = :form, form: {}, header: {}, auth: nil, timeout: 30, max_timeout_retry_delay: 3600, max_sslerror_retry_delay: 3600, max_read_retry_delay: 3600, max_econnrefused_retry_delay: 3600, max_socketerror_retry_delay: 3600, patch_request: nil, &block
33
33
  uri = URI.parse URI.escape url
34
34
 
35
35
  logger.warn "Warning: query params included `url` are discarded because `:form` isn't empty" if uri.query && !form.empty?
@@ -89,22 +89,25 @@ module NetHTTPUtils
89
89
  http
90
90
  end
91
91
  rescue Errno::ECONNREFUSED => e
92
- e.message.concat " to #{uri}"
93
- raise if max_econnrefused_retry_delay < delay *= 2
92
+ if max_econnrefused_retry_delay < delay *= 2
93
+ e.message.concat " to #{uri}"
94
+ raise
95
+ end
94
96
  logger.warn "retrying in #{delay} seconds because of #{e.class} '#{e.message}'"
95
97
  sleep delay
96
98
  retry
97
- rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ECONNRESET, SocketError => e
98
- if e.is_a?(SocketError) && e.message["getaddrinfo: "]
99
- e.message.concat ": #{uri.host}"
100
- raise e
101
- # logger.warn "retrying in 60 seconds because of #{e.class} '#{e.message}'"
102
- # sleep 60
103
- # retry
104
- end
99
+ rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ECONNRESET => e
105
100
  logger.warn "retrying in 5 seconds because of #{e.class} '#{e.message}'"
106
101
  sleep 5
107
102
  retry
103
+ rescue SocketError => e
104
+ if max_socketerror_retry_delay < delay *= 2
105
+ e.message.concat " to #{uri}"
106
+ raise e
107
+ end
108
+ logger.warn "retrying in #{delay} seconds because of #{e.class} '#{e.message}' at: #{uri}"
109
+ sleep delay
110
+ retry
108
111
  rescue Errno::ETIMEDOUT, Net::OpenTimeout => e
109
112
  raise if max_timeout_retry_delay < delay *= 2
110
113
  logger.warn "retrying in #{delay} seconds because of #{e.class} '#{e.message}' at: #{uri}"
@@ -119,7 +122,7 @@ module NetHTTPUtils
119
122
  end
120
123
  http = start_http[uri]
121
124
  do_request = lambda do |request|
122
- delay = 1
125
+ delay = 5
123
126
  response = begin
124
127
  http.request request, &block
125
128
  rescue Errno::ECONNREFUSED, Net::ReadTimeout, Net::OpenTimeout, Zlib::BufError, Errno::ECONNRESET, OpenSSL::SSL::SSLError => e
@@ -267,11 +270,19 @@ if $0 == __FILE__
267
270
  http://www.cutehalloweencostumeideas.org/wp-content/uploads/2017/10/Niagara-Falls_04.jpg
268
271
  }.each do |url|
269
272
  begin
270
- fail NetHTTPUtils.request_data url
273
+ fail NetHTTPUtils.request_data url, max_socketerror_retry_delay: -1
271
274
  rescue SocketError => e
272
275
  raise unless e.message["getaddrinfo: "]
273
276
  end
274
277
  end
278
+ %w{
279
+ http://www.aeronautica.difesa.it/organizzazione/REPARTI/divolo/PublishingImages/6%C2%B0%20Stormo/2013-decollo%20al%20tramonto%20REX%201280.jpg
280
+ }.each do |url| # TODO: test that setting user-agent header fixes this timeout
281
+ begin
282
+ fail NetHTTPUtils.request_data url, max_read_retry_delay: -1
283
+ rescue Net::ReadTimeout
284
+ end
285
+ end
275
286
 
276
287
  begin
277
288
  fail NetHTTPUtils.request_data "https://oi64.tinypic.com/29z7oxs.jpg?", timeout: 5, max_timeout_retry_delay: -1
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "nethttputils"
3
- spec.version = "0.2.0.0"
3
+ spec.version = "0.2.1.1"
4
4
  spec.summary = "this tool is like a pet that I adopted young and now I depend on, sorry"
5
5
  spec.description = <<-EOF
6
6
  Back in 2015 I was a guy automating things at my job and two scripts had a common need --
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nethttputils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.0
4
+ version: 0.2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov aka Nakilon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-03 00:00:00.000000000 Z
11
+ date: 2018-05-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Back in 2015 I was a guy automating things at my job and two scripts had a common need --
@@ -26,6 +26,7 @@ executables: []
26
26
  extensions: []
27
27
  extra_rdoc_files: []
28
28
  files:
29
+ - ".travis.yml"
29
30
  - LICENSE
30
31
  - Rakefile
31
32
  - lib/nethttputils.rb