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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38a12dc1f12b37cdbb3094c424fcd5ab11777dd9
4
- data.tar.gz: c9fc99deed5181dfc566968a4c7ab54aefe3ed9e
3
+ metadata.gz: bd8f869b3617b0ac419185dad8c2a63a17843e0b
4
+ data.tar.gz: 202eae3aaf1b2cc53eca758adcc4a103fe45f450
5
5
  SHA512:
6
- metadata.gz: 503c47b1ba730c6525bd9325a8431875a0e1494ba8f87faa0a9e3e27536410b4c9640c368e1ef8ec8636a2150c867f3e6a952e8f74e11f0138ac7c5e8811e413
7
- data.tar.gz: 8ca0c0f35fab0df31616d4c766029d8407a78fba6aed04f40cbad4a111dea689175c8f5c5f36de853ef85a58bf2640f5cecfb14c51e2258441893d2dcaa39195
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 = request_data http, :HEAD, form: form, header: header, auth: auth,
301
- max_start_http_retry_delay: max_start_http_retry_delay,
302
- max_read_retry_delay: max_read_retry_delay
303
- if "405" == body.instance_variable_get(:@last_response).code
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("https://goo.gl/ySqUb5") # this will fail if domain redirects are broken
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 [\"image/png\"]"],
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.4"
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
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-02 00:00:00.000000000 Z
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 --