nice_http 1.9.8 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +81 -24
- data/lib/nice_http/initialize.rb +72 -25
- data/lib/nice_http/manage/response.rb +0 -16
- data/lib/nice_http/reset.rb +3 -1
- data/lib/nice_http/validate_response.rb +56 -0
- data/lib/nice_http.rb +17 -14
- metadata +8 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1059fecf29256a3b57fbe27257398501830f3385e947c7d2922cdc57c4aab031
|
|
4
|
+
data.tar.gz: 7961065317e4fc908cdc2d9a258e6a6b1614872a203254fa8a8f98bb9368feda
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 34e4639b8c9a3b8c3dc25c4515d95e52d0ebe0dda4c2895bb4ef67a8db56401a06d0e9cc152d680b11e12aab4f29299fba3f17c0b924aa3851607f936a4bb1ef
|
|
7
|
+
data.tar.gz: 782a12d030df576799172bad7f46f01949940d8f4521fe4842a9f3379becb5628caff7b85f7c6a695a2e59946b0ee70692a5d3ec1fc1e044065daecf8a638682
|
data/README.md
CHANGED
|
@@ -20,34 +20,37 @@ NiceHttp is able to use hashes as requests data and uses the Request Hash struct
|
|
|
20
20
|
|
|
21
21
|
**On the next link you have a full example using nice_http and RSpec to test REST APIs, Uber API and Reqres API: https://github.com/MarioRuiz/api-testing-example**
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Example that creates 1000 good random and unique requests to register an user and test that the validation of the fields are correct by the user was able to be registered. Send 800 requests where just one field is wrong and verify the user was not able to be created: https://gist.github.com/MarioRuiz/824d7a462b62fd85f02c1a09455deefb
|
|
23
|
+
**Related gems:** NiceHttp uses [nice_hash](https://github.com/MarioRuiz/nice_hash) (v1.19+) for request/response hashes (e.g. `resp.data.json`, `set_values`, `nice_merge`) and for generating headers. [string_pattern](https://github.com/MarioRuiz/string_pattern) (v2.4+) is used by nice_hash for pattern-based string generation and validation. To generate random or pattern-based request data, see the [nice_hash documentation](https://github.com/MarioRuiz/nice_hash). Example: 1000 valid requests + 800 with one wrong field to test validation — [gist](https://gist.github.com/MarioRuiz/824d7a462b62fd85f02c1a09455deefb).
|
|
26
24
|
|
|
27
25
|
# Table of Contents
|
|
28
26
|
|
|
29
|
-
- [
|
|
30
|
-
- [
|
|
31
|
-
- [
|
|
32
|
-
- [
|
|
33
|
-
- [
|
|
34
|
-
|
|
35
|
-
- [
|
|
36
|
-
- [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
- [
|
|
40
|
-
- [
|
|
27
|
+
- [NiceHttp](#nicehttp)
|
|
28
|
+
- [Table of Contents](#table-of-contents)
|
|
29
|
+
- [Installation](#installation)
|
|
30
|
+
- [A very simple first example](#a-very-simple-first-example)
|
|
31
|
+
- [Create a connection](#create-a-connection)
|
|
32
|
+
- [Creating requests](#creating-requests)
|
|
33
|
+
- [Responses](#responses)
|
|
34
|
+
- [Async responses](#async-responses)
|
|
35
|
+
- [Special settings](#special-settings)
|
|
36
|
+
- [Authentication requests](#authentication-requests)
|
|
37
|
+
- [Basic Authentication](#basic-authentication)
|
|
38
|
+
- [OpenID](#openid)
|
|
39
|
+
- [OAuth2](#oauth2)
|
|
40
|
+
- [JWT token](#jwt-token)
|
|
41
41
|
- [lambda on headers](#lambda-on-headers)
|
|
42
|
-
- [Http logs](#
|
|
43
|
-
- [Multithreading](#
|
|
44
|
-
- [Http stats](#
|
|
45
|
-
- [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- [
|
|
49
|
-
- [
|
|
50
|
-
- [
|
|
42
|
+
- [Http logs](#http-logs)
|
|
43
|
+
- [Multithreading](#multithreading)
|
|
44
|
+
- [Http stats](#http-stats)
|
|
45
|
+
- [Testing with generated data](#testing-with-generated-data)
|
|
46
|
+
- [Validating API responses](#validating-api-responses)
|
|
47
|
+
- [Tips](#tips)
|
|
48
|
+
- [Download a file](#download-a-file)
|
|
49
|
+
- [Send multipart content](#send-multipart-content)
|
|
50
|
+
- [Send x-www-form-urlencoded](#send-x-www-form-urlencoded)
|
|
51
|
+
- [Running tests](#running-tests)
|
|
52
|
+
- [Contributing](#contributing)
|
|
53
|
+
- [License](#license)
|
|
51
54
|
|
|
52
55
|
## Installation
|
|
53
56
|
|
|
@@ -99,6 +102,9 @@ http3 = NiceHttp.new my_reqres_server
|
|
|
99
102
|
```
|
|
100
103
|
|
|
101
104
|
|
|
105
|
+
**Connection errors ("Too many open files")**
|
|
106
|
+
If you see "Too many open files" when creating connections (e.g. with many threads), NiceHttp will retry connection creation a few times with backoff. You can set `NiceHttp.connection_retry_attempts` (default 3) and `NiceHttp.connection_retry_base_delay` (default 1.0 seconds), or pass `connection_retry_attempts` and `connection_retry_base_delay` in the options hash when creating a connection. For long-running or multi-threaded usage, prefer reusing one connection per thread and calling `close` when finished.
|
|
107
|
+
|
|
102
108
|
You can specify all the defaults you will be using when creating connections by using the NiceHttp methods, in this example, http1 and http2 will be connecting to reqres.in with the default parameters and http3 to example.com:
|
|
103
109
|
|
|
104
110
|
```ruby
|
|
@@ -748,6 +754,46 @@ NiceHttp.add_stats(:customer, :create, started, Time.now, customer_name)
|
|
|
748
754
|
|
|
749
755
|
This will generate an items key that will contain an array of the values you added.
|
|
750
756
|
|
|
757
|
+
## Testing with generated data
|
|
758
|
+
|
|
759
|
+
When you build request hashes with [nice_hash](https://github.com/MarioRuiz/nice_hash) patterns (in `data`, `headers`, or `values_for`), you can:
|
|
760
|
+
|
|
761
|
+
* **Reproducible tests:** Use `seed` so the same request is generated every time:
|
|
762
|
+
```ruby
|
|
763
|
+
req = { path: "/api/users", data: { name: :"10-20:L", email: :"20-40:@" } }
|
|
764
|
+
resp = http.post req.generate(seed: 42) # same payload every run
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
* **Batch generation:** Generate many different request hashes in one go (e.g. for load or boundary tests):
|
|
768
|
+
```ruby
|
|
769
|
+
template = { path: "/api/users", data: { name: :"10-20:L", job: :"leader|developer" } }
|
|
770
|
+
requests = template.generate_n(5, :correct) # 5 different hashes
|
|
771
|
+
requests.each { |r| http.post r }
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
* **UUIDs:** Use the `:uuid` shorthand (string_pattern 2.4+) in your request data:
|
|
775
|
+
```ruby
|
|
776
|
+
resp = http.post(path: "/api/items", data: { id: :uuid, name: "Item" })
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
## Validating API responses
|
|
780
|
+
|
|
781
|
+
You can validate JSON responses against a structure or patterns using [nice_hash](https://github.com/MarioRuiz/nice_hash):
|
|
782
|
+
|
|
783
|
+
* **Structure comparison:** Check that the response has the expected keys and nested structure:
|
|
784
|
+
```ruby
|
|
785
|
+
expected = { user: { name: "xxx", id: 1 } }
|
|
786
|
+
NiceHash.compare_structure(expected, resp.data.json) # => true/false
|
|
787
|
+
```
|
|
788
|
+
|
|
789
|
+
* **Diff for assertions:** Get dot-notation differences for clearer failure messages:
|
|
790
|
+
```ruby
|
|
791
|
+
diff = NiceHash.diff(expected, resp.data.json)
|
|
792
|
+
# => { "user.name" => { expected: "Alice", got: "Bob" } } or {}
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
* **Pattern validation:** If your expected structure uses nice_hash patterns (e.g. `:"10:N"`, ranges), use `validate` to check that response values match those patterns.
|
|
796
|
+
|
|
751
797
|
## Tips
|
|
752
798
|
|
|
753
799
|
### Download a file
|
|
@@ -795,6 +841,17 @@ Example posting a csv file:
|
|
|
795
841
|
}
|
|
796
842
|
```
|
|
797
843
|
|
|
844
|
+
## Running tests
|
|
845
|
+
|
|
846
|
+
Run the test suite with:
|
|
847
|
+
|
|
848
|
+
```bash
|
|
849
|
+
bundle install
|
|
850
|
+
bundle exec rspec
|
|
851
|
+
```
|
|
852
|
+
|
|
853
|
+
By default, a **local Sinatra fake API** is started on ports 4567 and 4568 so specs do not depend on external services (reqres.in, Replit, example.com). Set `USE_FAKE_API=false` to use real external hosts instead (not recommended for CI).
|
|
854
|
+
|
|
798
855
|
## Contributing
|
|
799
856
|
|
|
800
857
|
Bug reports are very welcome on GitHub at https://github.com/marioruiz/nice_http.
|
data/lib/nice_http/initialize.rb
CHANGED
|
@@ -33,6 +33,9 @@ class NiceHttp
|
|
|
33
33
|
# async_completed -- string (default empty string)
|
|
34
34
|
# async_resource -- string (default empty string)
|
|
35
35
|
# async_status -- string (default empty string)
|
|
36
|
+
# connection_retry_attempts -- positive integer (default 3). When connection creation fails with "too many open files", retry up to this many times with backoff.
|
|
37
|
+
# connection_retry_base_delay -- non-negative number, seconds (default 1.0). Base delay before each retry; jitter is added to avoid thundering herd.
|
|
38
|
+
# @note When connection creation fails with "too many open files" (EMFILE/ENFILE), the library retries up to connection_retry_attempts times with backoff. For sustained load or many threads, prefer reusing one connection per thread and calling close when done.
|
|
36
39
|
# @example
|
|
37
40
|
# http2 = NiceHttp.new( host: "reqres.in", port: 443, ssl: true )
|
|
38
41
|
# @example
|
|
@@ -69,7 +72,9 @@ class NiceHttp
|
|
|
69
72
|
@async_completed = self.class.async_completed
|
|
70
73
|
@async_resource = self.class.async_resource
|
|
71
74
|
@async_status = self.class.async_status
|
|
72
|
-
|
|
75
|
+
@connection_retry_attempts = self.class.connection_retry_attempts || 3
|
|
76
|
+
@connection_retry_base_delay = self.class.connection_retry_base_delay || 1.0
|
|
77
|
+
|
|
73
78
|
#todo: set only the cookies for the current domain
|
|
74
79
|
#key: path, value: hash with key is the name of the cookie and value the value
|
|
75
80
|
# we set the default value for non existing keys to empty Hash {} so in case of merge there is no problem
|
|
@@ -86,7 +91,11 @@ class NiceHttp
|
|
|
86
91
|
@port = args[:port] if args.keys.include?(:port)
|
|
87
92
|
@ssl = args[:ssl] if args.keys.include?(:ssl)
|
|
88
93
|
@timeout = args[:timeout] if args.keys.include?(:timeout)
|
|
89
|
-
|
|
94
|
+
# Keep object reference when it has .generate (e.g. nice_hash); otherwise dup to avoid mutating caller's hash
|
|
95
|
+
if args.keys.include?(:headers)
|
|
96
|
+
h = args[:headers]
|
|
97
|
+
@headers = (h.is_a?(Hash) && h.respond_to?(:generate)) ? h : h.dup
|
|
98
|
+
end
|
|
90
99
|
@values_for = args[:values_for].dup if args.keys.include?(:values_for)
|
|
91
100
|
@debug = args[:debug] if args.keys.include?(:debug)
|
|
92
101
|
@log = args[:log] if args.keys.include?(:log)
|
|
@@ -100,7 +109,9 @@ class NiceHttp
|
|
|
100
109
|
@async_header = args[:async_header] if args.keys.include?(:async_header)
|
|
101
110
|
@async_completed = args[:async_completed] if args.keys.include?(:async_completed)
|
|
102
111
|
@async_resource = args[:async_resource] if args.keys.include?(:async_resource)
|
|
103
|
-
@async_status = args[:async_status] if args.keys.include?(:async_status)
|
|
112
|
+
@async_status = args[:async_status] if args.keys.include?(:async_status)
|
|
113
|
+
@connection_retry_attempts = args[:connection_retry_attempts] if args.keys.include?(:connection_retry_attempts)
|
|
114
|
+
@connection_retry_base_delay = args[:connection_retry_base_delay] if args.keys.include?(:connection_retry_base_delay)
|
|
104
115
|
end
|
|
105
116
|
|
|
106
117
|
log_filename = ""
|
|
@@ -175,7 +186,7 @@ class NiceHttp
|
|
|
175
186
|
raise InfoMissing, :log
|
|
176
187
|
end
|
|
177
188
|
@log_file = log_filename
|
|
178
|
-
@logger.level = Logger::INFO
|
|
189
|
+
@logger.level = Logger::INFO
|
|
179
190
|
|
|
180
191
|
if @host.to_s != "" and (@host.start_with?("http:") or @host.start_with?("https:"))
|
|
181
192
|
uri = URI.parse(@host)
|
|
@@ -199,28 +210,45 @@ class NiceHttp
|
|
|
199
210
|
raise InfoMissing, :async_completed unless @async_completed.is_a?(String) or @async_completed.nil?
|
|
200
211
|
raise InfoMissing, :async_resource unless @async_resource.is_a?(String) or @async_resource.nil?
|
|
201
212
|
raise InfoMissing, :async_status unless @async_status.is_a?(String) or @async_status.nil?
|
|
202
|
-
|
|
213
|
+
raise InfoMissing, :connection_retry_attempts unless @connection_retry_attempts.is_a?(Integer) && @connection_retry_attempts >= 1
|
|
214
|
+
raise InfoMissing, :connection_retry_base_delay unless @connection_retry_base_delay.is_a?(Numeric) && @connection_retry_base_delay >= 0
|
|
215
|
+
|
|
203
216
|
begin
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
217
|
+
attempt = 1
|
|
218
|
+
loop do
|
|
219
|
+
begin
|
|
220
|
+
if !@proxy_host.nil? && !@proxy_port.nil?
|
|
221
|
+
@http = Net::HTTP::Proxy(@proxy_host, @proxy_port).new(@host, @port)
|
|
222
|
+
@http.use_ssl = @ssl
|
|
223
|
+
@http.set_debug_output $stderr if @debug
|
|
224
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
225
|
+
unless @timeout.nil?
|
|
226
|
+
@http.open_timeout = @timeout
|
|
227
|
+
@http.read_timeout = @timeout
|
|
228
|
+
end
|
|
229
|
+
@http.start
|
|
230
|
+
else
|
|
231
|
+
@http = Net::HTTP.new(@host, @port)
|
|
232
|
+
@http.use_ssl = @ssl
|
|
233
|
+
@http.set_debug_output $stderr if @debug
|
|
234
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
235
|
+
unless @timeout.nil?
|
|
236
|
+
@http.open_timeout = @timeout
|
|
237
|
+
@http.read_timeout = @timeout
|
|
238
|
+
end
|
|
239
|
+
@http.start
|
|
240
|
+
end
|
|
241
|
+
break
|
|
242
|
+
rescue Exception => e
|
|
243
|
+
if connection_retryable_error?(e) && attempt < @connection_retry_attempts
|
|
244
|
+
delay = @connection_retry_base_delay + rand(0.25)
|
|
245
|
+
@logger.warn "(#{self.object_id}): Too many open files (attempt #{attempt}/#{@connection_retry_attempts}), retrying in #{delay.round(2)}s..."
|
|
246
|
+
sleep(delay)
|
|
247
|
+
attempt += 1
|
|
248
|
+
else
|
|
249
|
+
raise
|
|
250
|
+
end
|
|
222
251
|
end
|
|
223
|
-
@http.start
|
|
224
252
|
end
|
|
225
253
|
|
|
226
254
|
@message_server = "(#{self.object_id}):"
|
|
@@ -241,7 +269,11 @@ class NiceHttp
|
|
|
241
269
|
@auto_redirect = auto_redirect
|
|
242
270
|
# for the case we have headers following nice_hash implementation
|
|
243
271
|
@headers_orig = @headers.dup
|
|
244
|
-
@headers = @headers.generate
|
|
272
|
+
@headers = if @headers.is_a?(Hash) && @headers.respond_to?(:generate)
|
|
273
|
+
@headers.generate
|
|
274
|
+
else
|
|
275
|
+
@headers.dup
|
|
276
|
+
end
|
|
245
277
|
|
|
246
278
|
self.class.active += 1
|
|
247
279
|
self.class.connections.push(self)
|
|
@@ -251,4 +283,19 @@ class NiceHttp
|
|
|
251
283
|
raise stack
|
|
252
284
|
end
|
|
253
285
|
end
|
|
286
|
+
|
|
287
|
+
######################################################
|
|
288
|
+
# Returns true if the exception indicates file-descriptor exhaustion (too many open files).
|
|
289
|
+
# Used to decide whether to retry connection creation.
|
|
290
|
+
######################################################
|
|
291
|
+
def connection_retryable_error?(e)
|
|
292
|
+
return true if e.is_a?(Errno::EMFILE) || e.is_a?(Errno::ENFILE)
|
|
293
|
+
return true if e.message.to_s.downcase.include?("too many open files")
|
|
294
|
+
c = e.cause
|
|
295
|
+
return true if c && (c.is_a?(Errno::EMFILE) || c.is_a?(Errno::ENFILE))
|
|
296
|
+
return true if c && c.message.to_s.downcase.include?("too many open files")
|
|
297
|
+
false
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
private :connection_retryable_error?
|
|
254
301
|
end
|
|
@@ -29,22 +29,6 @@ module NiceHttpManageResponse
|
|
|
29
29
|
|
|
30
30
|
create_stats(resp) if @create_stats
|
|
31
31
|
|
|
32
|
-
begin
|
|
33
|
-
# this is to be able to access all keys as symbols on Ruby < 2.6.0
|
|
34
|
-
if RUBY_VERSION < "2.6.0"
|
|
35
|
-
new_resp = Hash.new()
|
|
36
|
-
resp.each { |key, value|
|
|
37
|
-
if key.kind_of?(String)
|
|
38
|
-
new_resp[key.to_sym] = value
|
|
39
|
-
end
|
|
40
|
-
}
|
|
41
|
-
new_resp.each { |key, value|
|
|
42
|
-
resp[key] = value
|
|
43
|
-
}
|
|
44
|
-
end
|
|
45
|
-
rescue
|
|
46
|
-
end
|
|
47
|
-
|
|
48
32
|
#for mock_responses to be able to add outside of the header like content-type for example
|
|
49
33
|
if resp.kind_of?(Hash) and !resp.has_key?(:header)
|
|
50
34
|
resp[:header] = {}
|
data/lib/nice_http/reset.rb
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
class NiceHttp
|
|
2
|
+
######################################################
|
|
3
|
+
# Validates that a response body matches an expected structure (keys and nesting).
|
|
4
|
+
# Uses NiceHash.compare_structure. Best for JSON responses.
|
|
5
|
+
#
|
|
6
|
+
# @param resp [Hash] Response object (e.g. from get/post). Must have :data (body string or Hash/Array).
|
|
7
|
+
# @param expected_structure [Hash, Array] Structure with expected keys and nesting (values can be placeholders).
|
|
8
|
+
# @param options [Hash] Optional. :include_diff => true to add a diff in the result when validation fails.
|
|
9
|
+
# @return [Hash] { ok: true } when structure matches, or { ok: false } or { ok: false, diff: Hash } when it does not.
|
|
10
|
+
# @example
|
|
11
|
+
# resp = http.get("/api/users/1")
|
|
12
|
+
# result = NiceHttp.validate_response(resp, { user: { name: "xxx", id: 1 } })
|
|
13
|
+
# expect(result[:ok]).to be true
|
|
14
|
+
# @example
|
|
15
|
+
# result = NiceHttp.validate_response(resp, expected, include_diff: true)
|
|
16
|
+
# puts result[:diff] unless result[:ok]
|
|
17
|
+
######################################################
|
|
18
|
+
def self.validate_response(resp, expected_structure, options = {})
|
|
19
|
+
data = resp.is_a?(Hash) ? resp[:data] : resp.data
|
|
20
|
+
parsed = if data.is_a?(String)
|
|
21
|
+
begin
|
|
22
|
+
require "json"
|
|
23
|
+
JSON.parse(data.to_s)
|
|
24
|
+
rescue JSON::ParserError
|
|
25
|
+
return { ok: false, error: "response data is not valid JSON" }
|
|
26
|
+
end
|
|
27
|
+
elsif data.is_a?(Hash) || data.is_a?(Array)
|
|
28
|
+
data
|
|
29
|
+
else
|
|
30
|
+
return { ok: false, error: "response data is missing or not JSON" }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Normalize to symbol keys so compare_structure/diff match typical expected_structure (symbol keys)
|
|
34
|
+
parsed = deep_symbolize(parsed) if parsed.is_a?(Hash) || parsed.is_a?(Array)
|
|
35
|
+
|
|
36
|
+
ok = NiceHash.compare_structure(expected_structure, parsed)
|
|
37
|
+
|
|
38
|
+
result = { ok: ok }
|
|
39
|
+
if !ok && options[:include_diff]
|
|
40
|
+
result[:diff] = NiceHash.diff(expected_structure, parsed)
|
|
41
|
+
end
|
|
42
|
+
result
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.deep_symbolize(obj)
|
|
46
|
+
case obj
|
|
47
|
+
when Hash
|
|
48
|
+
obj.each_with_object({}) { |(k, v), h| h[k.to_sym] = deep_symbolize(v) }
|
|
49
|
+
when Array
|
|
50
|
+
obj.map { |e| deep_symbolize(e) }
|
|
51
|
+
else
|
|
52
|
+
obj
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
private_class_method :deep_symbolize
|
|
56
|
+
end
|
data/lib/nice_http.rb
CHANGED
|
@@ -23,13 +23,15 @@ require_relative "nice_http/inherited"
|
|
|
23
23
|
require_relative "nice_http/save_stats"
|
|
24
24
|
require_relative "nice_http/close"
|
|
25
25
|
require_relative "nice_http/initialize"
|
|
26
|
+
require_relative "nice_http/validate_response"
|
|
26
27
|
|
|
27
28
|
######################################################
|
|
28
|
-
# Attributes you can access using NiceHttp.the_attribute:
|
|
29
|
-
# :host, :port, :ssl, :timeout, :headers, :debug, :log, :log_headers, :proxy_host, :proxy_port,
|
|
30
|
-
# :last_request, :last_response, :request_id, :use_mocks, :connections,
|
|
29
|
+
# Attributes you can access using NiceHttp.the_attribute:
|
|
30
|
+
# :host, :port, :ssl, :timeout, :headers, :debug, :log, :log_headers, :proxy_host, :proxy_port,
|
|
31
|
+
# :last_request, :last_response, :request_id, :use_mocks, :connections,
|
|
31
32
|
# :active, :auto_redirect, :values_for, :create_stats, :stats, :capture, :captured, :request, :requests,
|
|
32
|
-
# :async_wait_seconds, :async_header, :async_completed, :async_resource, :async_status
|
|
33
|
+
# :async_wait_seconds, :async_header, :async_completed, :async_resource, :async_status,
|
|
34
|
+
# :connection_retry_attempts, :connection_retry_base_delay
|
|
33
35
|
#
|
|
34
36
|
# @attr [String] host The host to be accessed
|
|
35
37
|
# @attr [Integer] port The port number
|
|
@@ -38,12 +40,12 @@ require_relative "nice_http/initialize"
|
|
|
38
40
|
# @attr [Hash] headers Contains the headers you will be using on your connection
|
|
39
41
|
# @attr [Boolean] debug In case true shows all the details of the communication with the host
|
|
40
42
|
# @attr [String] log_path The path where the logs will be stored. By default empty string.
|
|
41
|
-
# @attr [String, Symbol] log :fix_file, :no, :screen, :file, "path and file name".
|
|
42
|
-
# :fix_file, will log the communication on nice_http.log. (default).
|
|
43
|
-
# :no, will not generate any logs.
|
|
44
|
-
# :screen, will print the logs on the screen.
|
|
45
|
-
# :file, will be generated a log file with name: nice_http_YY-mm-dd-HHMMSS.log.
|
|
46
|
-
# :file_run, will generate a log file with the name where the object was created and extension .log, fex: myfile.rb.log
|
|
43
|
+
# @attr [String, Symbol] log :fix_file, :no, :screen, :file, "path and file name".
|
|
44
|
+
# :fix_file, will log the communication on nice_http.log. (default).
|
|
45
|
+
# :no, will not generate any logs.
|
|
46
|
+
# :screen, will print the logs on the screen.
|
|
47
|
+
# :file, will be generated a log file with name: nice_http_YY-mm-dd-HHMMSS.log.
|
|
48
|
+
# :file_run, will generate a log file with the name where the object was created and extension .log, fex: myfile.rb.log
|
|
47
49
|
# String the path and file name where the logs will be stored.
|
|
48
50
|
# @attr [String] log_file path and file name where the logs will be stored. (only reader)
|
|
49
51
|
# @attr [Symbol] log_headers. :all, :partial, :none (default :all) If :all will log all the headers. If :partial will log the last 10 characters. If :none no headers.
|
|
@@ -61,10 +63,10 @@ require_relative "nice_http/initialize"
|
|
|
61
63
|
# @attr [Hash] response Contains the full response hash
|
|
62
64
|
# @attr [Integer] num_redirects Number of consecutive redirections managed
|
|
63
65
|
# @attr [Hash] headers The updated headers of the communication
|
|
64
|
-
# @attr [Hash] cookies Cookies set. The key is the path (String) where cookies are set and the value a Hash with pairs of cookie keys and values, example:
|
|
66
|
+
# @attr [Hash] cookies Cookies set. The key is the path (String) where cookies are set and the value a Hash with pairs of cookie keys and values, example:
|
|
65
67
|
# { '/' => { "cfid" => "d95adfas2550255", "amddom.settings" => "doom" } }
|
|
66
|
-
# @attr [Logger] logger An instance of the Logger class where logs will be stored. You can access on anytime to store specific data, for example:
|
|
67
|
-
# my_http.logger.info "add this to the log file"
|
|
68
|
+
# @attr [Logger] logger An instance of the Logger class where logs will be stored. You can access on anytime to store specific data, for example:
|
|
69
|
+
# my_http.logger.info "add this to the log file"
|
|
68
70
|
# @see https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html
|
|
69
71
|
# @attr [Hash] values_for The default values to set on the data in case not specified others
|
|
70
72
|
# @attr [Boolean] create_stats If true, NiceHttp will create stats of the http communication and store them on NiceHttp.stats hash
|
|
@@ -101,7 +103,8 @@ class NiceHttp
|
|
|
101
103
|
attr_accessor :host, :port, :ssl, :timeout, :headers, :debug, :log_path, :log, :proxy_host, :proxy_port, :log_headers,
|
|
102
104
|
:last_request, :last_response, :request, :request_id, :use_mocks, :connections,
|
|
103
105
|
:active, :auto_redirect, :log_files, :values_for, :create_stats, :stats, :capture, :captured, :requests,
|
|
104
|
-
:async_wait_seconds, :async_header, :async_completed, :async_resource, :async_status
|
|
106
|
+
:async_wait_seconds, :async_header, :async_completed, :async_resource, :async_status,
|
|
107
|
+
:connection_retry_attempts, :connection_retry_base_delay
|
|
105
108
|
end
|
|
106
109
|
|
|
107
110
|
at_exit do
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nice_http
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.10.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mario Ruiz
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: nice_hash
|
|
@@ -16,20 +15,20 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '1.
|
|
18
|
+
version: '1.19'
|
|
20
19
|
- - ">="
|
|
21
20
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: 1.
|
|
21
|
+
version: 1.19.0
|
|
23
22
|
type: :runtime
|
|
24
23
|
prerelease: false
|
|
25
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
25
|
requirements:
|
|
27
26
|
- - "~>"
|
|
28
27
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '1.
|
|
28
|
+
version: '1.19'
|
|
30
29
|
- - ">="
|
|
31
30
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 1.
|
|
31
|
+
version: 1.19.0
|
|
33
32
|
- !ruby/object:Gem::Dependency
|
|
34
33
|
name: rspec
|
|
35
34
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -87,6 +86,7 @@ files:
|
|
|
87
86
|
- lib/nice_http/utils/get_value_xml_tag.rb
|
|
88
87
|
- lib/nice_http/utils/set_lambdas.rb
|
|
89
88
|
- lib/nice_http/utils/set_value_xml_tag.rb
|
|
89
|
+
- lib/nice_http/validate_response.rb
|
|
90
90
|
homepage: https://github.com/MarioRuiz/nice_http
|
|
91
91
|
licenses:
|
|
92
92
|
- MIT
|
|
@@ -106,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
106
106
|
- !ruby/object:Gem::Version
|
|
107
107
|
version: '0'
|
|
108
108
|
requirements: []
|
|
109
|
-
rubygems_version:
|
|
110
|
-
signing_key:
|
|
109
|
+
rubygems_version: 4.0.6
|
|
111
110
|
specification_version: 4
|
|
112
111
|
summary: NiceHttp -- simplest library for accessing and testing HTTP and REST resources.
|
|
113
112
|
Get http logs and statistics automatically. Use hashes on your requests. Access
|