nethttputils 0.3.2.9 → 0.4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -1
- data/Gemfile +3 -0
- data/lib/nethttputils.rb +49 -23
- data/nethttputils.gemspec +3 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff2b86fcc4b55f5f9ea7818eb61b47458da62fa0
|
4
|
+
data.tar.gz: 610d74457c21418c24b092a65ba47abfd5571b37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 819dc2799c568c4b4aa4d199d14e3f5a0b70253bc0eb6831205482274abb2bbe90f7fb8504d15f6e4561dfa2d1e7d464a4534943a2d6ebd188d7e345752cfc39
|
7
|
+
data.tar.gz: cde0231d2c7779642ecf68d052cc117178b9905ba8a1bf3427d7c901050f05b75d290624fda7c5a2e2a2f4ed5fc7114390aad00bcdcbc45bab8783d2ee844ff0
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
language: ruby
|
3
3
|
|
4
|
-
script: "ruby lib/nethttputils.rb"
|
4
|
+
script: "bundle install && bundle exec ruby lib/nethttputils.rb"
|
5
5
|
|
6
6
|
os:
|
7
7
|
- linux
|
@@ -19,3 +19,11 @@ matrix:
|
|
19
19
|
allow_failures:
|
20
20
|
# something with `NetHTTPUtils.request_data("http://localhost:8000/?1=2&3=4", form: {1=>3})` test
|
21
21
|
- rvm: jruby-head
|
22
|
+
- rvm: 2.3
|
23
|
+
os: osx
|
24
|
+
- rvm: 2.2
|
25
|
+
os: osx
|
26
|
+
- rvm: 2.1
|
27
|
+
os: osx
|
28
|
+
- rvm: 2.0
|
29
|
+
os: osx
|
data/Gemfile
ADDED
data/lib/nethttputils.rb
CHANGED
@@ -18,15 +18,18 @@ module NetHTTPUtils
|
|
18
18
|
attr_reader :code
|
19
19
|
def initialize body, code = nil
|
20
20
|
@code = code
|
21
|
-
|
21
|
+
body = body[0...997] + "..." if body.size > 1000
|
22
|
+
super "HTTP error ##{code.inspect} #{body}"
|
22
23
|
end
|
23
24
|
end
|
25
|
+
class EOFError_from_rbuf_fill < StandardError
|
26
|
+
end
|
24
27
|
|
25
28
|
class << self
|
26
29
|
|
27
30
|
def remove_tags str
|
28
|
-
str.gsub(/<script( [a-z]+="[^"]*")*>.*?<\/script>/m, "").
|
29
|
-
gsub(/<style( [a-z]+="[^"]*")*>.*?<\/style>/m, "").
|
31
|
+
str.gsub(/<script( [a-z-]+="[^"]*")*>.*?<\/script>/m, "").
|
32
|
+
gsub(/<style( [a-z-]+="[^"]*")*>.*?<\/style>/m, "").
|
30
33
|
gsub(/<[^>]*>/, "").split(?\n).map(&:strip).reject(&:empty?).join(?\n)
|
31
34
|
end
|
32
35
|
|
@@ -54,7 +57,7 @@ module NetHTTPUtils
|
|
54
57
|
def << msg
|
55
58
|
@@buffer ||= "[Net::HTTP debug] "
|
56
59
|
@@buffer.concat msg
|
57
|
-
@@buffer = @@buffer[0...997] + "..." if @@buffer.size >
|
60
|
+
@@buffer = @@buffer[0...997] + "..." if @@buffer.size > 1000
|
58
61
|
return unless @@buffer.end_with? ?\n
|
59
62
|
NetHTTPUtils.logger.debug @@buffer.sub ?\n, " "
|
60
63
|
@@buffer = nil
|
@@ -155,7 +158,7 @@ module NetHTTPUtils
|
|
155
158
|
request.each_header.map{ |k, v| "-H \"#{k}: #{v}\" " unless k == "host" }.join
|
156
159
|
}#{curl_form}'#{uri.scheme}://#{uri.host}#{uri.path}#{"?#{uri.query}" if uri.query && !uri.query.empty?}'"
|
157
160
|
logger.debug "> header: #{request.each_header.to_a}"
|
158
|
-
logger.debug "> body: #{request.body.inspect.tap{ |body| body[997
|
161
|
+
logger.debug "> body: #{request.body.inspect.tap{ |body| body.replace body[0...997] + "..." if body.size > 1000 }}"
|
159
162
|
# TODO this is buggy -- mixes lines from different files into one line
|
160
163
|
stack = caller.reverse.map do |level|
|
161
164
|
/((?:[^\/:]+\/)?[^\/:]+):([^:]+)/.match(level).captures
|
@@ -169,11 +172,16 @@ module NetHTTPUtils
|
|
169
172
|
delay = 5
|
170
173
|
response = begin
|
171
174
|
http.request request, &block
|
172
|
-
rescue Errno::ECONNREFUSED, Net::ReadTimeout, Net::OpenTimeout, Zlib::BufError, Errno::ECONNRESET, OpenSSL::SSL::SSLError => e
|
175
|
+
rescue Errno::ECONNREFUSED, Net::ReadTimeout, Net::OpenTimeout, Zlib::BufError, Errno::ECONNRESET, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT => e
|
173
176
|
raise if max_read_retry_delay < delay *= 2
|
174
177
|
logger.error "retrying in #{delay} seconds because of #{e.class} '#{e.message}' at: #{request.uri}"
|
175
178
|
sleep delay
|
176
179
|
retry
|
180
|
+
rescue EOFError => e
|
181
|
+
raise unless e.backtrace.empty?
|
182
|
+
# https://bugs.ruby-lang.org/issues/13018
|
183
|
+
# https://blog.kalina.tech/2019/04/exception-without-backtrace-in-ruby.html?spref=reddit
|
184
|
+
raise EOFError_from_rbuf_fill.new "probably the old Ruby empty backtrace EOFError exception from net/protocol.rb"
|
177
185
|
end
|
178
186
|
# response.instance_variable_set "@nethttputils_close", http.method(:finish)
|
179
187
|
# response.singleton_class.instance_eval{ attr_accessor :nethttputils_socket_to_close }
|
@@ -204,7 +212,7 @@ module NetHTTPUtils
|
|
204
212
|
# TODO: use WEBrick::Cookie
|
205
213
|
old_cookies = cookies.dup
|
206
214
|
response.to_hash.fetch("set-cookie", []).each do |c|
|
207
|
-
|
215
|
+
next logger.warn "bad cookie: #{c.inspect}" unless /\A([^\s=]+)=([^\s]*)\z/.match c.split(/\s*;\s*/).first
|
208
216
|
logger.debug "set-cookie: #{$1}=#{$2}"
|
209
217
|
old_cookies.delete $1
|
210
218
|
cookies.store $1, $2
|
@@ -217,13 +225,15 @@ module NetHTTPUtils
|
|
217
225
|
case response.code
|
218
226
|
when /\A30\d\z/
|
219
227
|
logger.info "redirect: #{response["location"]}"
|
220
|
-
|
228
|
+
require "addressable"
|
229
|
+
new_uri = URI.join request.uri.to_s, Addressable::URI.escape(response["location"])
|
221
230
|
new_host = new_uri.host
|
231
|
+
raise Error.new "redirected in place" if new_uri == http.instance_variable_get(:@uri)
|
222
232
|
if http.address != new_host ||
|
223
233
|
http.port != new_uri.port ||
|
224
234
|
http.use_ssl? != (new_uri.scheme == "https")
|
225
235
|
logger.debug "changing host from '#{http.address}' to '#{new_host}'"
|
226
|
-
# http.finish
|
236
|
+
# http.finish # why commented out?
|
227
237
|
http = NetHTTPUtils.start_http new_uri, http.instance_variable_get(:@max_start_http_retry_delay), timeout
|
228
238
|
end
|
229
239
|
if request.method == "POST"
|
@@ -349,24 +359,44 @@ if $0 == __FILE__
|
|
349
359
|
require "json"
|
350
360
|
Thread.abort_on_exception = true
|
351
361
|
|
362
|
+
server = WEBrick::HTTPServer.new Port: 8000
|
363
|
+
tt = false
|
364
|
+
server.mount_proc "/" do |req, res|
|
365
|
+
next unless "HEAD" == req.request_method
|
366
|
+
fail if tt
|
367
|
+
tt = true
|
368
|
+
res.status = 300
|
369
|
+
res["location"] = "/"
|
370
|
+
end
|
371
|
+
t = Thread.new{ server.start }
|
372
|
+
begin
|
373
|
+
NetHTTPUtils.request_data "http://localhost:8000/"
|
374
|
+
rescue NetHTTPUtils::Error => e
|
375
|
+
raise if e.code
|
376
|
+
end
|
377
|
+
server.shutdown
|
378
|
+
t.join
|
379
|
+
|
352
380
|
server = WEBrick::HTTPServer.new Port: 8000
|
353
381
|
server.mount_proc "/1" do |req, res|
|
354
382
|
next unless "GET" == req.request_method
|
355
|
-
res.cookies.push WEBrick::Cookie.new
|
356
|
-
res.cookies.push WEBrick::Cookie.new
|
357
|
-
res.cookies.push WEBrick::Cookie.new
|
358
|
-
res.cookies.push WEBrick::Cookie.new
|
359
|
-
res.cookies.push WEBrick::Cookie.new
|
383
|
+
res.cookies.push WEBrick::Cookie.new "1", "2"
|
384
|
+
res.cookies.push WEBrick::Cookie.new "3", "4"
|
385
|
+
res.cookies.push WEBrick::Cookie.new "8", "9"
|
386
|
+
res.cookies.push WEBrick::Cookie.new "a", "b"
|
387
|
+
res.cookies.push WEBrick::Cookie.new "1", "5"
|
388
|
+
res.cookies.push WEBrick::Cookie.new "f", "g h"
|
360
389
|
res.status = 300
|
361
390
|
res["location"] = "/2"
|
362
391
|
end
|
363
392
|
server.mount_proc "/2" do |req, res|
|
364
|
-
res.cookies.push WEBrick::Cookie.new
|
365
|
-
res.cookies.push WEBrick::Cookie.new
|
366
|
-
res.cookies.push WEBrick::Cookie.new
|
393
|
+
res.cookies.push WEBrick::Cookie.new "3", "6=c"
|
394
|
+
res.cookies.push WEBrick::Cookie.new "a", "d e"
|
395
|
+
res.cookies.push WEBrick::Cookie.new "8", ""
|
396
|
+
res.cookies.push WEBrick::Cookie.new "4", "7"
|
367
397
|
end
|
368
398
|
t = Thread.new{ server.start }
|
369
|
-
fail unless %w{ 3=6=c 8= 4=7 1=5 a=b } == p(NetHTTPUtils.request_data("http://localhost:8000/1").
|
399
|
+
fail unless %w{ 3=6=c a=d\ e 8= 4=7 1=5 a=b } == p(NetHTTPUtils.request_data("http://localhost:8000/1").
|
370
400
|
instance_variable_get(:@last_response).to_hash.fetch("set-cookie"))
|
371
401
|
server.shutdown
|
372
402
|
t.join
|
@@ -446,7 +476,7 @@ if $0 == __FILE__
|
|
446
476
|
fail unless NetHTTPUtils.method(:read).call(NetHTTPUtils.start_http("http://httpstat.us/400")) == "400 Bad Request"
|
447
477
|
fail unless NetHTTPUtils.method(:read).call(NetHTTPUtils.start_http("http://httpstat.us/404")) == "404 Not Found"
|
448
478
|
fail unless NetHTTPUtils.method(:read).call(NetHTTPUtils.start_http("http://httpstat.us/500")) == "500 Internal Server Error"
|
449
|
-
fail unless NetHTTPUtils.method(:read).call(NetHTTPUtils.start_http("http://httpstat.us/502"))
|
479
|
+
fail unless NetHTTPUtils.method(:read).call(NetHTTPUtils.start_http("http://httpstat.us/502")).start_with? "httpstat.us | 502: Bad gateway\nError\n502\n"
|
450
480
|
fail unless NetHTTPUtils.method(:read).call(NetHTTPUtils.start_http("http://httpstat.us/503")) == "503 Service Unavailable"
|
451
481
|
[
|
452
482
|
["https://imgur.com/a/cccccc"],
|
@@ -480,10 +510,6 @@ if $0 == __FILE__
|
|
480
510
|
end
|
481
511
|
end
|
482
512
|
|
483
|
-
begin
|
484
|
-
fail NetHTTPUtils.request_data "https://oi64.tinypic.com/29z7oxs.jpg?", timeout: 5, max_start_http_retry_delay: -1
|
485
|
-
rescue Net::OpenTimeout => e
|
486
|
-
end
|
487
513
|
## this stopped failing on High Sierra
|
488
514
|
# begin
|
489
515
|
# # https://www.virtualself.co/?
|
data/nethttputils.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "nethttputils"
|
3
|
-
spec.version = "0.
|
3
|
+
spec.version = "0.4.1.0"
|
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 --
|
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.require_path = "lib"
|
24
24
|
spec.files = `git ls-files -z`.split(?\0) - spec.test_files
|
25
|
+
|
26
|
+
spec.add_dependency "addressable"
|
25
27
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nethttputils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1.0
|
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:
|
12
|
-
dependencies:
|
11
|
+
date: 2020-08-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: |2
|
14
28
|
Back in 2015 I was a guy automating things at my job and two scripts had a common need --
|
15
29
|
they both had to pass the same credentials to Jenkins (via query params, I guess).
|
@@ -27,6 +41,7 @@ extensions: []
|
|
27
41
|
extra_rdoc_files: []
|
28
42
|
files:
|
29
43
|
- ".travis.yml"
|
44
|
+
- Gemfile
|
30
45
|
- LICENSE
|
31
46
|
- Rakefile
|
32
47
|
- lib/nethttputils.rb
|
@@ -51,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
66
|
version: '0'
|
52
67
|
requirements: []
|
53
68
|
rubyforge_project:
|
54
|
-
rubygems_version: 2.5.2
|
69
|
+
rubygems_version: 2.5.2.3
|
55
70
|
signing_key:
|
56
71
|
specification_version: 4
|
57
72
|
summary: this tool is like a pet that I adopted young and now I depend on, sorry
|