philiprehberger-header_kit 0.5.0 → 0.6.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/CHANGELOG.md +5 -0
- data/README.md +12 -0
- data/lib/philiprehberger/header_kit/accept_encoding.rb +31 -1
- data/lib/philiprehberger/header_kit/version.rb +1 -1
- data/lib/philiprehberger/header_kit.rb +8 -0
- 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: 255a0f1f4321e63ae82d6acaf028cddb9a041d4f1594b16dcbb8f2a51f54a286
|
|
4
|
+
data.tar.gz: 1a0ea312d1937e9e17c7cabe31f7822345d0de02f4627d09c597c5a71a5b7715
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee48374d55f01e11ae5b499c31556037801082a6631ed60306d544109897715bf5510eff7403675e2e94795257903efe289469bd790181cc2c32fef70e65a975
|
|
7
|
+
data.tar.gz: 40cf00b3c4d3d9f88d50ab21f08fc2dfb2d75b9ee13e879f985d59b28a14e81c600376d13d8f13f9bafb4edd3ff9350d6c4f6d5766abf20e9dd94bd2fd9e706c
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.6.0] - 2026-04-23
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `HeaderKit.build_accept_encoding(encodings)` for constructing Accept-Encoding headers from an array of `{encoding:, quality:}` hashes, mirroring the existing `build_accept` builder
|
|
14
|
+
|
|
10
15
|
## [0.5.0] - 2026-04-17
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -66,6 +66,17 @@ Philiprehberger::HeaderKit.parse_accept_encoding("gzip, deflate;q=0.5, br;q=0.8"
|
|
|
66
66
|
# => [{encoding: "gzip", quality: 1.0}, {encoding: "br", quality: 0.8}, {encoding: "deflate", quality: 0.5}]
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
### Build Accept-Encoding
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
Philiprehberger::HeaderKit.build_accept_encoding([
|
|
73
|
+
{encoding: "gzip"},
|
|
74
|
+
{encoding: "br", quality: 0.9},
|
|
75
|
+
{encoding: "deflate", quality: 0.5}
|
|
76
|
+
])
|
|
77
|
+
# => "gzip, br;q=0.9, deflate;q=0.5"
|
|
78
|
+
```
|
|
79
|
+
|
|
69
80
|
### Parse Authorization
|
|
70
81
|
|
|
71
82
|
```ruby
|
|
@@ -216,6 +227,7 @@ Philiprehberger::HeaderKit.parse_retry_after("Fri, 04 Apr 2026 12:00:00 GMT")
|
|
|
216
227
|
| `HeaderKit.parse_accept_language(header)` | Parse Accept-Language into sorted entries |
|
|
217
228
|
| `HeaderKit.negotiate_language(header, available)` | Language negotiation, returns best match or nil |
|
|
218
229
|
| `HeaderKit.parse_accept_encoding(header)` | Parse Accept-Encoding into sorted entries |
|
|
230
|
+
| `HeaderKit.build_accept_encoding(encodings)` | Build Accept-Encoding header string from encoding array |
|
|
219
231
|
| `HeaderKit.parse_authorization(header)` | Parse Authorization header (Bearer, Basic, Digest) |
|
|
220
232
|
| `HeaderKit.parse_cache_control(header)` | Parse Cache-Control into directive hash |
|
|
221
233
|
| `HeaderKit.build_cache_control(directives)` | Build Cache-Control string from hash |
|
|
@@ -50,7 +50,37 @@ module Philiprehberger
|
|
|
50
50
|
value.to_f.clamp(0.0, 1.0)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
# Build an Accept-Encoding header string from an array of encoding hashes.
|
|
54
|
+
#
|
|
55
|
+
# @param encodings [Array<Hash>] each with :encoding and optional :quality
|
|
56
|
+
# @return [String] formatted Accept-Encoding header value
|
|
57
|
+
def self.build(encodings)
|
|
58
|
+
return '' if encodings.nil? || encodings.empty?
|
|
59
|
+
|
|
60
|
+
parts = encodings.map do |entry|
|
|
61
|
+
encoding = entry[:encoding]
|
|
62
|
+
quality = entry[:quality]
|
|
63
|
+
|
|
64
|
+
if quality && quality < 1.0
|
|
65
|
+
"#{encoding};q=#{format_quality(quality)}"
|
|
66
|
+
else
|
|
67
|
+
encoding
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
parts.join(', ')
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Format a quality value, removing trailing zeros.
|
|
75
|
+
#
|
|
76
|
+
# @param quality [Float] the quality value
|
|
77
|
+
# @return [String] formatted quality string
|
|
78
|
+
def self.format_quality(quality)
|
|
79
|
+
formatted = format('%.3f', quality)
|
|
80
|
+
formatted.sub(/0+\z/, '').sub(/\.\z/, '.0')
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
private_class_method :parse_entry, :parse_quality, :format_quality
|
|
54
84
|
end
|
|
55
85
|
end
|
|
56
86
|
end
|
|
@@ -45,6 +45,14 @@ module Philiprehberger
|
|
|
45
45
|
AcceptEncoding.parse(header)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
# Build an Accept-Encoding header string from an array of encoding hashes.
|
|
49
|
+
#
|
|
50
|
+
# @param encodings [Array<Hash>] each with :encoding and optional :quality
|
|
51
|
+
# @return [String] formatted Accept-Encoding header value
|
|
52
|
+
def self.build_accept_encoding(encodings)
|
|
53
|
+
AcceptEncoding.build(encodings)
|
|
54
|
+
end
|
|
55
|
+
|
|
48
56
|
# Parse an Accept-Language header into structured entries sorted by quality.
|
|
49
57
|
#
|
|
50
58
|
# @param header [String] the Accept-Language header value
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-header_kit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Parse and build Accept, Accept-Language, Accept-Encoding, Authorization,
|
|
14
14
|
Cache-Control, Content-Type, Cookie, Link, CORS, Forwarded, and Via HTTP headers.
|