nice_http 1.8.6 → 1.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -1
  3. data/lib/nice_http.rb +21 -5
  4. metadata +10 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d71a8b887f41eb061251023b5490469bd1a19cb6f1c567ecb73a76dc0771a62
4
- data.tar.gz: d8d11267e373ca3ffa54366be21116949c1d4bccad9ee58ded6b445708a3aa40
3
+ metadata.gz: 8d4be3fb22aecfd4d84cb2c9384da399cf7a521742bba214f5e2746491120f4b
4
+ data.tar.gz: c2a143357e458385078c5e6709100d06ae473f7363282eb9c36c766618631dcf
5
5
  SHA512:
6
- metadata.gz: 7d1f38f6e9f08c8a90094e5f15b337ca89c3f3894fa9c3ce313ed1f2360386f870393a2ac86d4f99e8c9c14f1f13bdbe191926f49fe8b7c9a7f91fce203bef24
7
- data.tar.gz: c751a5dfc67127dbf5e89be704d46381888128b8f96b15a8819006d5ee4ec46cfdaec4df208fdb66eb3e8ca7db61b9020132ef0108a1dce4f03c6c6c361572c6
6
+ metadata.gz: 7e752817f9ca1b87b944904435c2a507b41cc8c76e0744ff10a4db1f21ea7009a75255d97b45d6a381cd7f1ed30d91ef1fc46371fb935e6cd18482df3867f693
7
+ data.tar.gz: 6269a98fa4e85bf2a9b13069d279bd58f184267b5b38342a1aa5c3cfbe855207bbacb94b91f5f22e2735426fc726326be381edaab27229f943455569ce157e3d
data/README.md CHANGED
@@ -122,6 +122,7 @@ NiceHttp.defaults = {
122
122
  host: 'reqres.in',
123
123
  ssl: true,
124
124
  port: 443,
125
+ timeout: 15, #seconds
125
126
  debug: false,
126
127
  log: "./my_logs.log",
127
128
  headers: {"api-key": "the api key"}
@@ -289,6 +290,8 @@ Also interesting keys would be: *time_elapsed_total*, *time_elapsed* and many mo
289
290
 
290
291
  *auto_redirect*: (true or false) in case of true it will take care of the auto redirections.
291
292
 
293
+ *timeout*: Integer that will set a time out for the time waiting to connect to a host or waiting for a response.
294
+
292
295
  ## Authentication requests
293
296
 
294
297
  All we need to do is to add to our request the correct authentication tokens, seeds, headers.
@@ -584,7 +587,7 @@ threads = []
584
587
  end
585
588
  end
586
589
 
587
- t.each(&:join)
590
+ threads.each(&:join)
588
591
 
589
592
  # log files: nice_http_0.log, nice_http_1.log... nice_http_39.log
590
593
  ```
@@ -7,13 +7,14 @@ require_relative "nice_http/http_methods"
7
7
 
8
8
  ######################################################
9
9
  # Attributes you can access using NiceHttp.the_attribute:
10
- # :host, :port, :ssl, :headers, :debug, :log, :log_headers, :proxy_host, :proxy_port,
10
+ # :host, :port, :ssl, :timeout, :headers, :debug, :log, :log_headers, :proxy_host, :proxy_port,
11
11
  # :last_request, :last_response, :request_id, :use_mocks, :connections,
12
12
  # :active, :auto_redirect, :values_for, :create_stats, :stats, :capture, :captured, :request, :requests
13
13
  #
14
14
  # @attr [String] host The host to be accessed
15
15
  # @attr [Integer] port The port number
16
16
  # @attr [Boolean] ssl If you use ssl or not
17
+ # @attr [Integer] timeout Max time to wait until connected to the host or getting a response.
17
18
  # @attr [Hash] headers Contains the headers you will be using on your connection
18
19
  # @attr [Boolean] debug In case true shows all the details of the communication with the host
19
20
  # @attr [String] log_path The path where the logs will be stored. By default empty string.
@@ -71,7 +72,7 @@ class NiceHttp
71
72
  end
72
73
 
73
74
  class << self
74
- attr_accessor :host, :port, :ssl, :headers, :debug, :log_path, :log, :proxy_host, :proxy_port, :log_headers,
75
+ attr_accessor :host, :port, :ssl, :timeout, :headers, :debug, :log_path, :log, :proxy_host, :proxy_port, :log_headers,
75
76
  :last_request, :last_response, :request, :request_id, :use_mocks, :connections,
76
77
  :active, :auto_redirect, :log_files, :values_for, :create_stats, :stats, :capture, :captured, :requests
77
78
  end
@@ -89,6 +90,7 @@ class NiceHttp
89
90
  @host = nil
90
91
  @port = 80
91
92
  @ssl = false
93
+ @timeout = nil
92
94
  @headers = {}
93
95
  @values_for = {}
94
96
  @debug = false
@@ -137,18 +139,19 @@ class NiceHttp
137
139
  subclass.reset!
138
140
  end
139
141
 
140
- attr_reader :host, :port, :ssl, :debug, :log, :log_path, :proxy_host, :proxy_port, :response, :num_redirects
142
+ attr_reader :host, :port, :ssl, :timeout, :debug, :log, :log_path, :proxy_host, :proxy_port, :response, :num_redirects
141
143
  attr_accessor :headers, :cookies, :use_mocks, :auto_redirect, :logger, :values_for, :log_headers
142
144
 
143
145
  ######################################################
144
146
  # Change the default values for NiceHttp supplying a Hash
145
147
  #
146
- # @param par [Hash] keys: :host, :port, :ssl, :headers, :debug, :log, :log_path, :proxy_host, :proxy_port, :use_mocks, :auto_redirect, :values_for, :create_stats, :log_headers, :capture
148
+ # @param par [Hash] keys: :host, :port, :ssl, :timeout, :headers, :debug, :log, :log_path, :proxy_host, :proxy_port, :use_mocks, :auto_redirect, :values_for, :create_stats, :log_headers, :capture
147
149
  ######################################################
148
150
  def self.defaults=(par = {})
149
151
  @host = par[:host] if par.key?(:host)
150
152
  @port = par[:port] if par.key?(:port)
151
153
  @ssl = par[:ssl] if par.key?(:ssl)
154
+ @timeout = par[:timeout] if par.key?(:timeout)
152
155
  @headers = par[:headers].dup if par.key?(:headers)
153
156
  @values_for = par[:values_for].dup if par.key?(:values_for)
154
157
  @debug = par[:debug] if par.key?(:debug)
@@ -300,6 +303,7 @@ class NiceHttp
300
303
  # host -- example.com. (default blank screen)
301
304
  # port -- port for the connection. 80 (default)
302
305
  # ssl -- true, false (default)
306
+ # timeout -- integer or nil (default)
303
307
  # headers -- hash with the headers
304
308
  # values_for -- hash with the values_for
305
309
  # debug -- true, false (default)
@@ -327,6 +331,7 @@ class NiceHttp
327
331
  @port = self.class.port
328
332
  @prepath = ""
329
333
  @ssl = self.class.ssl
334
+ @timeout = self.class.timeout
330
335
  @headers = self.class.headers.dup
331
336
  @values_for = self.class.values_for.dup
332
337
  @debug = self.class.debug
@@ -357,6 +362,7 @@ class NiceHttp
357
362
  @host = args[:host] if args.keys.include?(:host)
358
363
  @port = args[:port] if args.keys.include?(:port)
359
364
  @ssl = args[:ssl] if args.keys.include?(:ssl)
365
+ @timeout = args[:timeout] if args.keys.include?(:timeout)
360
366
  @headers = args[:headers].dup if args.keys.include?(:headers)
361
367
  @values_for = args[:values_for].dup if args.keys.include?(:values_for)
362
368
  @debug = args[:debug] if args.keys.include?(:debug)
@@ -452,6 +458,7 @@ class NiceHttp
452
458
  raise InfoMissing, :port if @port.to_s == ""
453
459
  raise InfoMissing, :host if @host.to_s == ""
454
460
  raise InfoMissing, :ssl unless @ssl.is_a?(TrueClass) or @ssl.is_a?(FalseClass)
461
+ raise InfoMissing, :timeout unless @timeout.is_a?(Integer) or @timeout.nil?
455
462
  raise InfoMissing, :debug unless @debug.is_a?(TrueClass) or @debug.is_a?(FalseClass)
456
463
  raise InfoMissing, :auto_redirect unless auto_redirect.is_a?(TrueClass) or auto_redirect.is_a?(FalseClass)
457
464
  raise InfoMissing, :use_mocks unless @use_mocks.is_a?(TrueClass) or @use_mocks.is_a?(FalseClass)
@@ -465,18 +472,26 @@ class NiceHttp
465
472
  @http.use_ssl = @ssl
466
473
  @http.set_debug_output $stderr if @debug
467
474
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
475
+ unless @timeout.nil?
476
+ @http.open_timeout = @timeout
477
+ @http.read_timeout = @timeout
478
+ end
468
479
  @http.start
469
480
  else
470
481
  @http = Net::HTTP.new(@host, @port)
471
482
  @http.use_ssl = @ssl
472
483
  @http.set_debug_output $stderr if @debug
473
484
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
485
+ unless @timeout.nil?
486
+ @http.open_timeout = @timeout
487
+ @http.read_timeout = @timeout
488
+ end
474
489
  @http.start
475
490
  end
476
491
 
477
492
  @message_server = "(#{self.object_id}):"
478
493
 
479
- log_message = "(#{self.object_id}): Http connection created. host:#{@host}, port:#{@port}, ssl:#{@ssl}, mode:#{@mode}, proxy_host: #{@proxy_host.to_s()}, proxy_port: #{@proxy_port.to_s()} "
494
+ log_message = "(#{self.object_id}): Http connection created. host:#{@host}, port:#{@port}, ssl:#{@ssl}, timeout:#{@timeout}, mode:#{@mode}, proxy_host: #{@proxy_host.to_s()}, proxy_port: #{@proxy_port.to_s()} "
480
495
 
481
496
  @logger.info(log_message)
482
497
  @message_server += " Http connection: "
@@ -499,6 +514,7 @@ class NiceHttp
499
514
  rescue Exception => stack
500
515
  puts stack
501
516
  @logger.fatal stack
517
+ raise stack
502
518
  end
503
519
  end
504
520
 
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nice_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.6
4
+ version: 1.8.7
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-04-22 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nice_hash
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.15'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: 1.15.6
19
+ version: '1.17'
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.17'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '1.15'
30
27
  - - ">="
31
28
  - !ruby/object:Gem::Version
32
- version: 1.15.6
29
+ version: '1.17'
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.17'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rspec
35
35
  requirement: !ruby/object:Gem::Requirement