nethttputils 0.3.2.4 → 0.3.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nethttputils.rb +34 -7
- data/nethttputils.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd8f869b3617b0ac419185dad8c2a63a17843e0b
|
4
|
+
data.tar.gz: 202eae3aaf1b2cc53eca758adcc4a103fe45f450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b6e931944769ed28ed65cfd1d5864137e98cece14c151c1aafbb2b5550591f51768d30a97e0a7b66de8f8894cb4008da89cd1f5963745554e6244da6e0f3d0c
|
7
|
+
data.tar.gz: 41afb56a5ccb929d975bc019930dab804bc1ed4e103867ba1763ac1e63275e1cabd93c2355feecb306f1161ba4fa70e56d30b1a7f232b1a2e07af4b0f9c4d801
|
data/lib/nethttputils.rb
CHANGED
@@ -289,7 +289,7 @@ module NetHTTPUtils
|
|
289
289
|
else
|
290
290
|
ct = body.instance_variable_get(:@last_response).to_hash["content-type"]
|
291
291
|
raise Error.new(
|
292
|
-
(ct == ["image/png"] ? ct.first : body),
|
292
|
+
(ct == ["image/png"] ? "<#{ct.first}>" : body),
|
293
293
|
code.to_i
|
294
294
|
)
|
295
295
|
end
|
@@ -297,10 +297,14 @@ module NetHTTPUtils
|
|
297
297
|
require "set"
|
298
298
|
@@_405 ||= Set.new
|
299
299
|
if mtd == :GET && !@@_405.include?(http.address)
|
300
|
-
body =
|
301
|
-
|
302
|
-
|
303
|
-
|
300
|
+
body = begin
|
301
|
+
request_data http, :HEAD, form: form, header: header, auth: auth,
|
302
|
+
max_start_http_retry_delay: max_start_http_retry_delay,
|
303
|
+
max_read_retry_delay: max_read_retry_delay
|
304
|
+
rescue NetHTTPUtils::Error => e
|
305
|
+
raise unless e.code == 400
|
306
|
+
end
|
307
|
+
if !body || "405" == body.instance_variable_get(:@last_response).code
|
304
308
|
@@_405.add http.address
|
305
309
|
else
|
306
310
|
check_code.call body
|
@@ -332,12 +336,32 @@ if $0 == __FILE__
|
|
332
336
|
NetHTTPUtils.logger.level = Logger::DEBUG
|
333
337
|
require "pp"
|
334
338
|
|
335
|
-
NetHTTPUtils.request_data
|
339
|
+
NetHTTPUtils.request_data "https://goo.gl/ySqUb5" # this will fail if domain redirects are broken
|
336
340
|
|
337
341
|
require "webrick"
|
338
342
|
require "json"
|
339
343
|
Thread.abort_on_exception = true
|
340
344
|
|
345
|
+
[
|
346
|
+
[WEBrick::HTTPStatus::NotFound, 404],
|
347
|
+
[WEBrick::HTTPStatus::BadRequest],
|
348
|
+
[WEBrick::HTTPStatus::MethodNotAllowed],
|
349
|
+
].each do |webrick_exception, should_raise|
|
350
|
+
server = WEBrick::HTTPServer.new Port: 8000
|
351
|
+
server.mount_proc ?/ do |req, res|
|
352
|
+
res.set_error webrick_exception.new if "HEAD" == req.request_method
|
353
|
+
end
|
354
|
+
t = Thread.new{ server.start }
|
355
|
+
begin
|
356
|
+
NetHTTPUtils.request_data "http://localhost:8000/"
|
357
|
+
NetHTTPUtils.class_variable_get(:@@_405).clear
|
358
|
+
fail if should_raise
|
359
|
+
rescue NetHTTPUtils::Error => e
|
360
|
+
fail unless 404 == e.code
|
361
|
+
end
|
362
|
+
server.shutdown
|
363
|
+
end
|
364
|
+
|
341
365
|
server = WEBrick::HTTPServer.new Port: 8000
|
342
366
|
stack = []
|
343
367
|
server.mount_proc ?/ do |req, res|
|
@@ -350,6 +374,9 @@ if $0 == __FILE__
|
|
350
374
|
NetHTTPUtils.start_http("http://localhost:8000/").head("/")
|
351
375
|
fail stack.inspect unless stack == %w{ HEAD }
|
352
376
|
stack.clear
|
377
|
+
NetHTTPUtils.request_data("http://localhost:8000/", :head)
|
378
|
+
fail stack.inspect unless stack == %w{ HEAD }
|
379
|
+
stack.clear
|
353
380
|
NetHTTPUtils.request_data("http://localhost:8000/")
|
354
381
|
fail stack.inspect unless stack == %w{ HEAD GET }
|
355
382
|
server.shutdown
|
@@ -394,7 +421,7 @@ if $0 == __FILE__
|
|
394
421
|
[
|
395
422
|
["https://imgur.com/a/cccccc"],
|
396
423
|
["https://imgur.com/mM4Dh7Z"],
|
397
|
-
["https://i.redd.it/si758zk7r5xz.jpg", "HTTP error #404
|
424
|
+
["https://i.redd.it/si758zk7r5xz.jpg", "HTTP error #404 <image/png>"],
|
398
425
|
].each do |url, expectation|
|
399
426
|
begin
|
400
427
|
puts NetHTTPUtils.remove_tags NetHTTPUtils.request_data url
|
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.2.
|
3
|
+
spec.version = "0.3.2.5"
|
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.3.2.
|
4
|
+
version: 0.3.2.5
|
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: 2019-02-
|
11
|
+
date: 2019-02-03 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 --
|