patient_http 1.6.0 → 1.6.1
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/CHANGELOG.md +10 -0
- data/README.md +3 -1
- data/VERSION +1 -1
- data/lib/patient_http/http_headers.rb +31 -6
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3b3bb6335d47143a8f6e8123be222265651c3e3cee1c8a0084f3aae02b6f6444
|
|
4
|
+
data.tar.gz: 9c0a549ff00b9861073fd9853d82a6736c26bf34fca3ac689acf14008968abd5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c13e5e339088c84e7977ba82c6484780a890076af083d2dbf2754bf1ff0eb05d6a28d585be4d56b13bf5a052d00b643b2c8d44b90a5766fab9cd426c03375830
|
|
7
|
+
data.tar.gz: cdf38eeac4823f3cb922001541c3d9425c993cc4ce075ca80ff427d2a79a6d38928999518cd690181aaa8d4064554ea087666a54bb426a829809135dc0c4bf35
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## 1.6.1
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Request headers with a `nil` or empty string value are no longer sent. `HttpHeaders` drops such entries when it is built from a hash (so `{"X-Header" => nil}` does not set the header) and removes the header when a value is set to `nil` or `""`, including through `merge`. Some servers reject requests that carry a header with no value.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `HttpHeaders#delete` removes a header by name (case insensitive) and returns its value.
|
|
16
|
+
|
|
7
17
|
## 1.6.0
|
|
8
18
|
|
|
9
19
|
### Added
|
data/README.md
CHANGED
|
@@ -309,7 +309,7 @@ error = PatientHttp::HttpError.load(json_data)
|
|
|
309
309
|
|
|
310
310
|
The `Response` object includes the HTTP status code, headers, body, and callback arguments. Error objects (`HttpError`, `RedirectError`, `RequestError`) include the error message, context about the request, and callback arguments.
|
|
311
311
|
|
|
312
|
-
|
|
312
|
+
Request and response headers are case insensitive. A request header with a `nil` or empty string value is never sent: setting a header to `nil` or `""` removes it, and a header hash such as `{"X-Header" => nil}` does not set the header at all. Headers that appear multiple times in the response (such as `set-cookie`) are flattened into a single joined string value.
|
|
313
313
|
|
|
314
314
|
Response bodies are automatically encoded for JSON serialization. Binary content is Base64 encoded, and large text content is gzipped and then Base64 encoded to reduce payload size. Decoding is handled transparently when you access the `body` or `json` methods on the `Response` object.
|
|
315
315
|
|
|
@@ -868,6 +868,8 @@ Please use the [standardrb](https://github.com/testdouble/standard) syntax and l
|
|
|
868
868
|
|
|
869
869
|
The [patient_http-sidekiq](https://github.com/bdurand/patient_http-sidekiq) and [patient_http-solid_queue](https://github.com/bdurand/patient_http-solid_queue) gems each provide a test application for integration testing.
|
|
870
870
|
|
|
871
|
+
Running the full test suite requires running the included docker-compose.yml file to start up a valkey and s3mock server.
|
|
872
|
+
|
|
871
873
|
## Further Reading
|
|
872
874
|
|
|
873
875
|
- [Architecture](ARCHITECTURE.md)
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.6.
|
|
1
|
+
1.6.1
|
|
@@ -5,16 +5,20 @@ module PatientHttp
|
|
|
5
5
|
#
|
|
6
6
|
# This class provides a hash-like interface for HTTP headers with case-insensitive
|
|
7
7
|
# key access. Header names are normalized to lowercase for storage and lookup.
|
|
8
|
+
#
|
|
9
|
+
# Headers with an empty value are never stored. Setting a header to nil or an
|
|
10
|
+
# empty string removes it, so a request never sends a header with no value.
|
|
8
11
|
class HttpHeaders
|
|
9
12
|
include Enumerable
|
|
10
13
|
|
|
11
|
-
# Initializes a new HttpHeaders instance.
|
|
14
|
+
# Initializes a new HttpHeaders instance. Entries with a nil or empty value
|
|
15
|
+
# are skipped.
|
|
12
16
|
#
|
|
13
|
-
# @param headers [Hash] initial headers to set
|
|
17
|
+
# @param headers [Hash, HttpHeaders] initial headers to set
|
|
14
18
|
def initialize(headers = {})
|
|
15
19
|
@headers = {}
|
|
16
20
|
headers&.each do |key, value|
|
|
17
|
-
|
|
21
|
+
self[key] = value
|
|
18
22
|
end
|
|
19
23
|
end
|
|
20
24
|
|
|
@@ -26,12 +30,26 @@ module PatientHttp
|
|
|
26
30
|
@headers[key.to_s.downcase]
|
|
27
31
|
end
|
|
28
32
|
|
|
29
|
-
# Sets the value for a header (case insensitive).
|
|
33
|
+
# Sets the value for a header (case insensitive). Setting a header to nil
|
|
34
|
+
# or an empty string removes it.
|
|
30
35
|
#
|
|
31
36
|
# @param key [String, Symbol] header name
|
|
32
|
-
# @param value [String] header value
|
|
37
|
+
# @param value [String, nil] header value
|
|
33
38
|
def []=(key, value)
|
|
34
|
-
|
|
39
|
+
name = key.to_s.downcase
|
|
40
|
+
if empty_value?(value)
|
|
41
|
+
@headers.delete(name)
|
|
42
|
+
else
|
|
43
|
+
@headers[name] = value
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Removes a header (case insensitive).
|
|
48
|
+
#
|
|
49
|
+
# @param key [String, Symbol] header name
|
|
50
|
+
# @return [String, nil] the removed value or nil if not found
|
|
51
|
+
def delete(key)
|
|
52
|
+
@headers.delete(key.to_s.downcase)
|
|
35
53
|
end
|
|
36
54
|
|
|
37
55
|
# Fetches the value for a header with an optional default.
|
|
@@ -102,5 +120,12 @@ module PatientHttp
|
|
|
102
120
|
def hash
|
|
103
121
|
@headers.hash
|
|
104
122
|
end
|
|
123
|
+
|
|
124
|
+
private
|
|
125
|
+
|
|
126
|
+
# A header value is empty when it is nil or a string with no characters.
|
|
127
|
+
def empty_value?(value)
|
|
128
|
+
value.nil? || (value.is_a?(String) && value.empty?)
|
|
129
|
+
end
|
|
105
130
|
end
|
|
106
131
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: patient_http
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.6.
|
|
4
|
+
version: 1.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian Durand
|
|
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
146
146
|
- !ruby/object:Gem::Version
|
|
147
147
|
version: '0'
|
|
148
148
|
requirements: []
|
|
149
|
-
rubygems_version:
|
|
149
|
+
rubygems_version: 3.6.9
|
|
150
150
|
specification_version: 4
|
|
151
151
|
summary: Generic async HTTP connection pool for Ruby applications using Fiber-based
|
|
152
152
|
concurrency
|