nice_http 1.8.7 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nice_http/http_methods.rb +75 -45
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d4be3fb22aecfd4d84cb2c9384da399cf7a521742bba214f5e2746491120f4b
4
- data.tar.gz: c2a143357e458385078c5e6709100d06ae473f7363282eb9c36c766618631dcf
3
+ metadata.gz: 0d34a54e00d6d1befdc3127bbc8a9a5c23d1d4e84cce71f5d8847db2d50ed0c7
4
+ data.tar.gz: 8be85233d7d4e9047f237238d27fc022d5a00572ea47d45f7e11c177f5be4721
5
5
  SHA512:
6
- metadata.gz: 7e752817f9ca1b87b944904435c2a507b41cc8c76e0744ff10a4db1f21ea7009a75255d97b45d6a381cd7f1ed30d91ef1fc46371fb935e6cd18482df3867f693
7
- data.tar.gz: 6269a98fa4e85bf2a9b13069d279bd58f184267b5b38342a1aa5c3cfbe855207bbacb94b91f5f22e2735426fc726326be381edaab27229f943455569ce157e3d
6
+ metadata.gz: 143ef9899c2ea697d7d946dd7f9b2b2b90df17f5088dc7f101aeb2b7a77d7c514ac200811703e679010acade18f3b6c42f06d1473fcc9856f22737565c68c5c6
7
+ data.tar.gz: 28910b261bbdfac6ab516868a8185188c3541f95a3d13576f100206566c2344a4e07b5a2e8484509da69684eac2d3910420d0b861e5451d45223b5c311bbd900
@@ -85,7 +85,7 @@ module NiceHttpHttpMethods
85
85
  else
86
86
  @start_time_net = Time.now if @start_time_net.nil?
87
87
  resp = @http.get(path, headers_t)
88
- if resp.code == 401 and @headers_orig.values.map(&:class).include?(Proc)
88
+ if (resp.code == 401 or resp.code == 408) and @headers_orig.values.map(&:class).include?(Proc)
89
89
  try = false
90
90
  @headers_orig.each do |k,v|
91
91
  if v.is_a?(Proc) and headers_t.key?(k)
@@ -103,14 +103,19 @@ module NiceHttpHttpMethods
103
103
  end
104
104
  rescue Exception => stack
105
105
  @logger.warn stack
106
- @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
107
- @http.finish()
108
- @http.start()
109
- @start_time_net = Time.now if @start_time_net.nil?
110
- @headers_orig.each {|k,v| headers_t[k] = v.call if v.is_a?(Proc) and headers_t.key?(k)}
111
- resp = @http.get(path, headers_t)
112
- data = resp.body
113
- manage_response(resp, data)
106
+ if !@timeout.nil? and (Time.now - @start_time_net) > @timeout
107
+ @logger.warn "The connection seems to be closed in the host machine. Timeout."
108
+ return { fatal_error: "Net::ReadTimeout", code: nil, message: nil, data: "" }
109
+ else
110
+ @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
111
+ @http.finish()
112
+ @http.start()
113
+ @start_time_net = Time.now if @start_time_net.nil?
114
+ @headers_orig.each {|k,v| headers_t[k] = v.call if v.is_a?(Proc) and headers_t.key?(k)}
115
+ resp = @http.get(path, headers_t)
116
+ data = resp.body
117
+ manage_response(resp, data)
118
+ end
114
119
  end
115
120
  if @auto_redirect and @response[:code].to_i >= 300 and @response[:code].to_i < 400 and @response.include?(:location)
116
121
  if @num_redirects <= 30
@@ -219,7 +224,7 @@ module NiceHttpHttpMethods
219
224
  else
220
225
  resp = @http.post(path, data, headers_t)
221
226
  #todo: do it also for forms and multipart
222
- if resp.code == 401 and @headers_orig.values.map(&:class).include?(Proc)
227
+ if (resp.code == 401 or resp.code == 408) and @headers_orig.values.map(&:class).include?(Proc)
223
228
  try = false
224
229
  @headers_orig.each do |k,v|
225
230
  if v.is_a?(Proc) and headers_t.key?(k)
@@ -236,12 +241,17 @@ module NiceHttpHttpMethods
236
241
  end
237
242
  rescue Exception => stack
238
243
  @logger.warn stack
239
- @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
240
- @http.finish()
241
- @http.start()
242
- @start_time_net = Time.now if @start_time_net.nil?
243
- @headers_orig.each {|k,v| headers_t[k] = v.call if v.is_a?(Proc) and headers_t.key?(k)}
244
- resp, data = @http.post(path, data, headers_t)
244
+ if !@timeout.nil? and (Time.now - @start_time_net) > @timeout
245
+ @logger.warn "The connection seems to be closed in the host machine. Timeout."
246
+ return { fatal_error: "Net::ReadTimeout", code: nil, message: nil, data: "" }
247
+ else
248
+ @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
249
+ @http.finish()
250
+ @http.start()
251
+ @start_time_net = Time.now if @start_time_net.nil?
252
+ @headers_orig.each {|k,v| headers_t[k] = v.call if v.is_a?(Proc) and headers_t.key?(k)}
253
+ resp, data = @http.post(path, data, headers_t)
254
+ end
245
255
  end
246
256
  manage_response(resp, data)
247
257
  if @auto_redirect and @response[:code].to_i >= 300 and @response[:code].to_i < 400 and @response.include?(:location)
@@ -315,7 +325,7 @@ module NiceHttpHttpMethods
315
325
  begin
316
326
  @start_time_net = Time.now if @start_time_net.nil?
317
327
  resp = @http.send_request("PUT", path, data, headers_t)
318
- if resp.code == 401 and @headers_orig.values.map(&:class).include?(Proc)
328
+ if (resp.code == 401 or resp.code == 408) and @headers_orig.values.map(&:class).include?(Proc)
319
329
  try = false
320
330
  @headers_orig.each do |k,v|
321
331
  if v.is_a?(Proc) and headers_t.key?(k)
@@ -331,12 +341,17 @@ module NiceHttpHttpMethods
331
341
  data = resp.body
332
342
  rescue Exception => stack
333
343
  @logger.warn stack
334
- @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
335
- @http.finish()
336
- @http.start()
337
- @headers_orig.each {|k,v| headers_t[k] = v.call if v.is_a?(Proc) and headers_t.key?(k)}
338
- @start_time_net = Time.now if @start_time_net.nil?
339
- resp, data = @http.send_request("PUT", path, data, headers_t)
344
+ if !@timeout.nil? and (Time.now - @start_time_net) > @timeout
345
+ @logger.warn "The connection seems to be closed in the host machine. Timeout."
346
+ return { fatal_error: "Net::ReadTimeout", code: nil, message: nil, data: "" }
347
+ else
348
+ @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
349
+ @http.finish()
350
+ @http.start()
351
+ @headers_orig.each {|k,v| headers_t[k] = v.call if v.is_a?(Proc) and headers_t.key?(k)}
352
+ @start_time_net = Time.now if @start_time_net.nil?
353
+ resp, data = @http.send_request("PUT", path, data, headers_t)
354
+ end
340
355
  end
341
356
  manage_response(resp, data)
342
357
 
@@ -396,7 +411,7 @@ module NiceHttpHttpMethods
396
411
  begin
397
412
  @start_time_net = Time.now if @start_time_net.nil?
398
413
  resp = @http.patch(path, data, headers_t)
399
- if resp.code == 401 and @headers_orig.values.map(&:class).include?(Proc)
414
+ if (resp.code == 401 or resp.code == 408) and @headers_orig.values.map(&:class).include?(Proc)
400
415
  try = false
401
416
  @headers_orig.each do |k,v|
402
417
  if v.is_a?(Proc) and headers_t.key?(k)
@@ -412,12 +427,17 @@ module NiceHttpHttpMethods
412
427
  data = resp.body
413
428
  rescue Exception => stack
414
429
  @logger.warn stack
415
- @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
416
- @http.finish()
417
- @http.start()
418
- @headers_orig.each {|k,v| headers_t[k] = v.call if v.is_a?(Proc) and headers_t.key?(k)}
419
- @start_time_net = Time.now if @start_time_net.nil?
420
- resp, data = @http.patch(path, data, headers_t)
430
+ if !@timeout.nil? and (Time.now - @start_time_net) > @timeout
431
+ @logger.warn "The connection seems to be closed in the host machine. Timeout."
432
+ return { fatal_error: "Net::ReadTimeout", code: nil, message: nil, data: "" }
433
+ else
434
+ @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
435
+ @http.finish()
436
+ @http.start()
437
+ @headers_orig.each {|k,v| headers_t[k] = v.call if v.is_a?(Proc) and headers_t.key?(k)}
438
+ @start_time_net = Time.now if @start_time_net.nil?
439
+ resp, data = @http.patch(path, data, headers_t)
440
+ end
421
441
  end
422
442
  manage_response(resp, data)
423
443
  if @auto_redirect and @response[:code].to_i >= 300 and @response[:code].to_i < 400 and @response.include?(:location)
@@ -492,7 +512,7 @@ module NiceHttpHttpMethods
492
512
  @start_time_net = Time.now if @start_time_net.nil?
493
513
  if data.to_s == ""
494
514
  resp = @http.delete(path, headers_t)
495
- if resp.code == 401 and @headers_orig.values.map(&:class).include?(Proc)
515
+ if (resp.code == 401 or resp.code == 408) and @headers_orig.values.map(&:class).include?(Proc)
496
516
  try = false
497
517
  @headers_orig.each do |k,v|
498
518
  if v.is_a?(Proc) and headers_t.key?(k)
@@ -509,7 +529,7 @@ module NiceHttpHttpMethods
509
529
  request = Net::HTTP::Delete.new(path, headers_t)
510
530
  request.body = data
511
531
  resp = @http.request(request)
512
- if resp.code == 401 and @headers_orig.values.map(&:class).include?(Proc)
532
+ if (resp.code == 401 or resp.code == 408) and @headers_orig.values.map(&:class).include?(Proc)
513
533
  try = false
514
534
  @headers_orig.each do |k,v|
515
535
  if v.is_a?(Proc) and headers_t.key?(k)
@@ -528,12 +548,17 @@ module NiceHttpHttpMethods
528
548
  data = resp.body
529
549
  rescue Exception => stack
530
550
  @logger.warn stack
531
- @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
532
- @http.finish()
533
- @http.start()
534
- @headers_orig.each {|k,v| headers_t[k] = v.call if v.is_a?(Proc) and headers_t.key?(k)}
535
- @start_time_net = Time.now if @start_time_net.nil?
536
- resp, data = @http.delete(path, headers_t)
551
+ if !@timeout.nil? and (Time.now - @start_time_net) > @timeout
552
+ @logger.warn "The connection seems to be closed in the host machine. Timeout."
553
+ return { fatal_error: "Net::ReadTimeout", code: nil, message: nil, data: "" }
554
+ else
555
+ @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
556
+ @http.finish()
557
+ @http.start()
558
+ @headers_orig.each {|k,v| headers_t[k] = v.call if v.is_a?(Proc) and headers_t.key?(k)}
559
+ @start_time_net = Time.now if @start_time_net.nil?
560
+ resp, data = @http.delete(path, headers_t)
561
+ end
537
562
  end
538
563
  manage_response(resp, data)
539
564
 
@@ -578,7 +603,7 @@ module NiceHttpHttpMethods
578
603
  begin
579
604
  @start_time_net = Time.now if @start_time_net.nil?
580
605
  resp = @http.head(path, headers_t)
581
- if resp.code == 401 and @headers_orig.values.map(&:class).include?(Proc)
606
+ if (resp.code == 401 or resp.code == 408) and @headers_orig.values.map(&:class).include?(Proc)
582
607
  try = false
583
608
  @headers_orig.each do |k,v|
584
609
  if v.is_a?(Proc) and headers_t.key?(k)
@@ -594,12 +619,17 @@ module NiceHttpHttpMethods
594
619
  data = resp.body
595
620
  rescue Exception => stack
596
621
  @logger.warn stack
597
- @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
598
- @http.finish()
599
- @http.start()
600
- @headers_orig.each {|k,v| headers_t[k] = v.call if v.is_a?(Proc) and headers_t.key?(k)}
601
- @start_time_net = Time.now if @start_time_net.nil?
602
- resp, data = @http.head(path, headers_t)
622
+ if !@timeout.nil? and (Time.now - @start_time_net) > @timeout
623
+ @logger.warn "The connection seems to be closed in the host machine. Timeout."
624
+ return { fatal_error: "Net::ReadTimeout", code: nil, message: nil, data: "" }
625
+ else
626
+ @logger.warn "The connection seems to be closed in the host machine. Trying to reconnect"
627
+ @http.finish()
628
+ @http.start()
629
+ @headers_orig.each {|k,v| headers_t[k] = v.call if v.is_a?(Proc) and headers_t.key?(k)}
630
+ @start_time_net = Time.now if @start_time_net.nil?
631
+ resp, data = @http.head(path, headers_t)
632
+ end
603
633
  end
604
634
  manage_response(resp, data)
605
635
  return @response
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nice_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.7
4
+ version: 1.8.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-13 00:00:00.000000000 Z
11
+ date: 2020-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nice_hash