protocol-http 0.54.0 → 0.56.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.
@@ -4,7 +4,7 @@
4
4
  # Copyright, 2025, by Samuel Williams.
5
5
 
6
6
  require_relative "split"
7
- require_relative "quoted_string"
7
+ require_relative "../quoted_string"
8
8
  require_relative "../error"
9
9
 
10
10
  module Protocol
@@ -62,16 +62,44 @@ module Protocol
62
62
  end
63
63
  end
64
64
 
65
- # Initializes the TE header with the given value. The value is split into distinct entries and converted to lowercase for normalization.
65
+ # Parses a raw header value.
66
66
  #
67
- # @parameter value [String | Nil] the raw header value containing transfer encodings separated by commas.
67
+ # @parameter value [String] a raw header value containing comma-separated encodings.
68
+ # @returns [TE] a new instance with normalized (lowercase) encodings.
69
+ def self.parse(value)
70
+ self.new(value.downcase.split(COMMA))
71
+ end
72
+
73
+ # Coerces a value into a parsed header object.
74
+ #
75
+ # @parameter value [String | Array] the value to coerce.
76
+ # @returns [TE] a parsed header object with normalized values.
77
+ def self.coerce(value)
78
+ case value
79
+ when Array
80
+ self.new(value.map(&:downcase))
81
+ else
82
+ self.parse(value.to_s)
83
+ end
84
+ end
85
+
86
+ # Initializes the TE header with the given values.
87
+ #
88
+ # @parameter value [Array | String | Nil] an array of encodings, a raw header value, or `nil` for an empty header.
68
89
  def initialize(value = nil)
69
- super(value&.downcase)
90
+ if value.is_a?(Array)
91
+ super(value)
92
+ elsif value.is_a?(String)
93
+ super()
94
+ self << value
95
+ elsif value
96
+ raise ArgumentError, "Invalid value: #{value.inspect}"
97
+ end
70
98
  end
71
99
 
72
100
  # Adds one or more comma-separated values to the TE header. The values are converted to lowercase for normalization.
73
101
  #
74
- # @parameter value [String] the value or values to add, separated by commas.
102
+ # @parameter value [String] a raw header value containing one or more values separated by commas.
75
103
  def << value
76
104
  super(value.downcase)
77
105
  end
@@ -129,3 +157,4 @@ module Protocol
129
157
  end
130
158
  end
131
159
  end
160
+
@@ -27,16 +27,44 @@ module Protocol
27
27
  # The `identity` transfer encoding indicates no transformation has been applied.
28
28
  IDENTITY = "identity"
29
29
 
30
- # Initializes the transfer encoding header with the given value. The value is split into distinct entries and converted to lowercase for normalization.
30
+ # Parses a raw header value.
31
31
  #
32
- # @parameter value [String | Nil] the raw header value containing transfer encodings separated by commas.
32
+ # @parameter value [String] a raw header value containing comma-separated encodings.
33
+ # @returns [TransferEncoding] a new instance with normalized (lowercase) encodings.
34
+ def self.parse(value)
35
+ self.new(value.downcase.split(COMMA))
36
+ end
37
+
38
+ # Coerces a value into a parsed header object.
39
+ #
40
+ # @parameter value [String | Array] the value to coerce.
41
+ # @returns [TransferEncoding] a parsed header object with normalized values.
42
+ def self.coerce(value)
43
+ case value
44
+ when Array
45
+ self.new(value.map(&:downcase))
46
+ else
47
+ self.parse(value.to_s)
48
+ end
49
+ end
50
+
51
+ # Initializes the transfer encoding header with the given values.
52
+ #
53
+ # @parameter value [Array | String | Nil] an array of encodings, a raw header value, or `nil` for an empty header.
33
54
  def initialize(value = nil)
34
- super(value&.downcase)
55
+ if value.is_a?(Array)
56
+ super(value)
57
+ elsif value.is_a?(String)
58
+ super()
59
+ self << value
60
+ elsif value
61
+ raise ArgumentError, "Invalid value: #{value.inspect}"
62
+ end
35
63
  end
36
64
 
37
65
  # Adds one or more comma-separated values to the transfer encoding header. The values are converted to lowercase for normalization.
38
66
  #
39
- # @parameter value [String] the value or values to add, separated by commas.
67
+ # @parameter value [String] a raw header value containing one or more values separated by commas.
40
68
  def << value
41
69
  super(value.downcase)
42
70
  end
@@ -76,3 +104,4 @@ module Protocol
76
104
  end
77
105
  end
78
106
  end
107
+
@@ -12,16 +12,44 @@ module Protocol
12
12
  #
13
13
  # The `vary` header is used in HTTP responses to indicate which request headers affect the selected response. It allows caches to differentiate stored responses based on specific request headers.
14
14
  class Vary < Split
15
- # Initializes a `Vary` header with the given value. The value is split into distinct entries and converted to lowercase for normalization.
15
+ # Parses a raw header value.
16
16
  #
17
- # @parameter value [String] the raw header value containing request header names separated by commas.
18
- def initialize(value)
19
- super(value.downcase)
17
+ # @parameter value [String] a raw header value containing comma-separated header names.
18
+ # @returns [Vary] a new instance with normalized (lowercase) header names.
19
+ def self.parse(value)
20
+ self.new(value.downcase.split(COMMA))
21
+ end
22
+
23
+ # Coerces a value into a parsed header object.
24
+ #
25
+ # @parameter value [String | Array] the value to coerce.
26
+ # @returns [Vary] a parsed header object with normalized values.
27
+ def self.coerce(value)
28
+ case value
29
+ when Array
30
+ self.new(value.map(&:downcase))
31
+ else
32
+ self.parse(value.to_s)
33
+ end
34
+ end
35
+
36
+ # Initializes a `Vary` header with the given values.
37
+ #
38
+ # @parameter value [Array | String | Nil] an array of header names, a raw header value, or `nil` for an empty header.
39
+ def initialize(value = nil)
40
+ if value.is_a?(Array)
41
+ super(value)
42
+ elsif value.is_a?(String)
43
+ super()
44
+ self << value
45
+ elsif value
46
+ raise ArgumentError, "Invalid value: #{value.inspect}"
47
+ end
20
48
  end
21
49
 
22
50
  # Adds one or more comma-separated values to the `vary` header. The values are converted to lowercase for normalization.
23
51
  #
24
- # @parameter value [String] the value or values to add, separated by commas.
52
+ # @parameter value [String] a raw header value containing one or more values separated by commas.
25
53
  def << value
26
54
  super(value.downcase)
27
55
  end
@@ -29,3 +57,4 @@ module Protocol
29
57
  end
30
58
  end
31
59
  end
60
+
@@ -189,7 +189,7 @@ module Protocol
189
189
  #
190
190
  # @yields {|key, value| ...}
191
191
  # @parameter key [String] The header key.
192
- # @parameter value [String] The header value.
192
+ # @parameter value [String] The raw header value.
193
193
  def each(&block)
194
194
  @fields.each(&block)
195
195
  end
@@ -228,7 +228,6 @@ module Protocol
228
228
  # @parameter key [String] the header key.
229
229
  # @parameter value [String] the header value to assign.
230
230
  def add(key, value)
231
- # The value MUST be a string, so we convert it to a string to prevent errors later on.
232
231
  value = value.to_s
233
232
 
234
233
  if @indexed
@@ -238,18 +237,51 @@ module Protocol
238
237
  @fields << [key, value]
239
238
  end
240
239
 
241
- alias []= add
242
-
243
240
  # Set the specified header key to the specified value, replacing any existing header keys with the same name.
244
241
  #
245
242
  # @parameter key [String] the header key to replace.
246
243
  # @parameter value [String] the header value to assign.
247
244
  def set(key, value)
248
- # TODO This could be a bit more efficient:
249
245
  self.delete(key)
250
246
  self.add(key, value)
251
247
  end
252
248
 
249
+ # Set the specified header key to the specified value, replacing any existing values.
250
+ #
251
+ # The value can be a String or a coercable value.
252
+ #
253
+ # @parameter key [String] the header key.
254
+ # @parameter value [String | Array] the header value to assign.
255
+ def []=(key, value)
256
+ key = key.downcase
257
+
258
+ # Delete existing value if any:
259
+ self.delete(key)
260
+
261
+ if policy = @policy[key]
262
+ unless value.is_a?(policy)
263
+ value = policy.coerce(value)
264
+ end
265
+ else
266
+ value = value.to_s
267
+ end
268
+
269
+ # Clear the indexed cache so it will be rebuilt with parsed values when accessed:
270
+ if @indexed
271
+ @indexed[key] = value
272
+ end
273
+
274
+ @fields << [key, value.to_s]
275
+ end
276
+
277
+ # Get the value of the specified header key.
278
+ #
279
+ # @parameter key [String] The header key.
280
+ # @returns [String | Array | Object] The header value.
281
+ def [] key
282
+ to_h[key]
283
+ end
284
+
253
285
  # Merge the headers into this instance.
254
286
  def merge!(headers)
255
287
  headers.each do |key, value|
@@ -338,6 +370,11 @@ module Protocol
338
370
  # @parameter key [String] The header key.
339
371
  # @returns [String | Array | Object] The merged header value.
340
372
  def delete(key)
373
+ # If we've indexed the headers, we can bail out early if the key is not present:
374
+ if @indexed && !@indexed.key?(key.downcase)
375
+ return nil
376
+ end
377
+
341
378
  deleted, @fields = @fields.partition do |field|
342
379
  field.first.downcase == key
343
380
  end
@@ -350,7 +387,7 @@ module Protocol
350
387
  return @indexed.delete(key)
351
388
  elsif policy = @policy[key]
352
389
  (key, value), *tail = deleted
353
- merged = policy.new(value)
390
+ merged = policy.parse(value)
354
391
 
355
392
  tail.each{|k,v| merged << v}
356
393
 
@@ -376,7 +413,11 @@ module Protocol
376
413
  if current_value = hash[key]
377
414
  current_value << value
378
415
  else
379
- hash[key] = policy.new(value)
416
+ if policy.respond_to?(:parse)
417
+ hash[key] = policy.parse(value)
418
+ else
419
+ hash[key] = policy.new(value)
420
+ end
380
421
  end
381
422
  else
382
423
  # By default, headers are not allowed in trailers:
@@ -392,14 +433,6 @@ module Protocol
392
433
  end
393
434
  end
394
435
 
395
- # Get the value of the specified header key.
396
- #
397
- # @parameter key [String] The header key.
398
- # @returns [String | Array | Object] The header value.
399
- def [] key
400
- to_h[key]
401
- end
402
-
403
436
  # Compute a hash table of headers, where the keys are normalized to lower case and the values are normalized according to the policy for that header.
404
437
  #
405
438
  # @returns [Hash] A hash table of `{key, value}` pairs.
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2025, by Samuel Williams.
5
+
6
+ module Protocol
7
+ module HTTP
8
+ # According to https://tools.ietf.org/html/rfc7231#appendix-C
9
+ TOKEN = /[!#$%&'*+\-.^_`|~0-9A-Z]+/i
10
+
11
+ QUOTED_STRING = /"(?:.(?!(?<!\\)"))*.?"/
12
+
13
+ # https://tools.ietf.org/html/rfc7231#section-5.3.1
14
+ QVALUE = /0(\.[0-9]{0,3})?|1(\.[0]{0,3})?/
15
+
16
+ # Handling of HTTP quoted strings.
17
+ module QuotedString
18
+ # Unquote a "quoted-string" value according to <https://tools.ietf.org/html/rfc7230#section-3.2.6>. It should already match the QUOTED_STRING pattern above by the parser.
19
+ def self.unquote(value, normalize_whitespace = true)
20
+ value = value[1...-1]
21
+
22
+ value.gsub!(/\\(.)/, '\1')
23
+
24
+ if normalize_whitespace
25
+ # LWS = [CRLF] 1*( SP | HT )
26
+ value.gsub!(/[\r\n]+\s+/, " ")
27
+ end
28
+
29
+ return value
30
+ end
31
+
32
+ QUOTES_REQUIRED = /[()<>@,;:\\"\/\[\]?={} \t]/
33
+
34
+ # Quote a string for HTTP header values if required.
35
+ #
36
+ # @raises [ArgumentError] if the value contains invalid characters like control characters or newlines.
37
+ def self.quote(value, force = false)
38
+ # Check if quoting is required:
39
+ if value =~ QUOTES_REQUIRED or force
40
+ "\"#{value.gsub(/["\\]/, '\\\\\0')}\""
41
+ else
42
+ value
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP
8
- VERSION = "0.54.0"
8
+ VERSION = "0.56.0"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -22,10 +22,6 @@ Please see the [project documentation](https://socketry.github.io/protocol-http/
22
22
 
23
23
  - [Middleware](https://socketry.github.io/protocol-http/guides/middleware/index) - This guide explains how to build and use HTTP middleware with `Protocol::HTTP::Middleware`.
24
24
 
25
- - [Hypertext References](https://socketry.github.io/protocol-http/guides/hypertext-references/index) - This guide explains how to use `Protocol::HTTP::Reference` for constructing and manipulating hypertext references (URLs with parameters).
26
-
27
- - [URL Parsing](https://socketry.github.io/protocol-http/guides/url-parsing/index) - This guide explains how to use `Protocol::HTTP::URL` for parsing and manipulating URL components, particularly query strings and parameters.
28
-
29
25
  - [Streaming](https://socketry.github.io/protocol-http/guides/streaming/index) - This guide gives an overview of how to implement streaming requests and responses.
30
26
 
31
27
  - [Design Overview](https://socketry.github.io/protocol-http/guides/design-overview/index) - This guide explains the high level design of `protocol-http` in the context of wider design patterns that can be used to implement HTTP clients and servers.
@@ -34,6 +30,23 @@ Please see the [project documentation](https://socketry.github.io/protocol-http/
34
30
 
35
31
  Please see the [project releases](https://socketry.github.io/protocol-http/releases/index) for all releases.
36
32
 
33
+ ### v0.56.0
34
+
35
+ - Introduce `Header::*.parse(value)` which parses a raw header value string into a header instance.
36
+ - Introduce `Header::*.coerce(value)` which coerces any value (`String`, `Array`, etc.) into a header instance with normalization.
37
+ - `Header::*#initialize` now accepts arrays without normalization for efficiency, or strings for backward compatibility.
38
+ - Update `Headers#[]=` to use `coerce(value)` for smart conversion of user input.
39
+ - Normalization (e.g., lowercasing) is applied by `parse`, `coerce`, and `<<` methods, but not by `new` when given arrays.
40
+
41
+ ### v0.55.0
42
+
43
+ - **Breaking**: Move `Protocol::HTTP::Header::QuotedString` to `Protocol::HTTP::QuotedString` for better reusability.
44
+ - **Breaking**: Handle cookie key/value pairs using `QuotedString` as per RFC 6265.
45
+ - Don't use URL encoding for cookie key/value.
46
+ - **Breaking**: Remove `Protocol::HTTP::URL` and `Protocol::HTTP::Reference` – replaced by `Protocol::URL` gem.
47
+ - `Protocol::HTTP::URL` -\> `Protocol::URL::Encoding`.
48
+ - `Protocol::HTTP::Reference` -\> `Protocol::URL::Reference`.
49
+
37
50
  ### v0.54.0
38
51
 
39
52
  - Introduce rich support for `Header::Digest`, `Header::ServerTiming`, `Header::TE`, `Header::Trailer` and `Header::TransferEncoding`.
@@ -73,21 +86,13 @@ Please see the [project releases](https://socketry.github.io/protocol-http/relea
73
86
  - Clarify behaviour of streaming bodies and copy `Protocol::Rack::Body::Streaming` to `Protocol::HTTP::Body::Streamable`.
74
87
  - Copy `Async::HTTP::Body::Writable` to `Protocol::HTTP::Body::Writable`.
75
88
 
76
- ### v0.31.0
77
-
78
- - Ensure chunks are flushed if required, when streaming.
79
-
80
- ### v0.30.0
81
-
82
- - [`Request[]` and `Response[]` Keyword Arguments](https://socketry.github.io/protocol-http/releases/index#request[]-and-response[]-keyword-arguments)
83
- - [Interim Response Handling](https://socketry.github.io/protocol-http/releases/index#interim-response-handling)
84
-
85
89
  ## See Also
86
90
 
87
91
  - [protocol-http1](https://github.com/socketry/protocol-http1) — HTTP/1 client/server implementation using this
88
92
  interface.
89
93
  - [protocol-http2](https://github.com/socketry/protocol-http2) — HTTP/2 client/server implementation using this
90
94
  interface.
95
+ - [protocol-url](https://github.com/socketry/protocol-url) — URL parsing and manipulation library.
91
96
  - [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client and server, supporting multiple HTTP
92
97
  protocols & TLS.
93
98
  - [async-websocket](https://github.com/socketry/async-websocket) — Asynchronous client and server WebSockets.
data/releases.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Releases
2
2
 
3
+ ## v0.56.0
4
+
5
+ - Introduce `Header::*.parse(value)` which parses a raw header value string into a header instance.
6
+ - Introduce `Header::*.coerce(value)` which coerces any value (`String`, `Array`, etc.) into a header instance with normalization.
7
+ - `Header::*#initialize` now accepts arrays without normalization for efficiency, or strings for backward compatibility.
8
+ - Update `Headers#[]=` to use `coerce(value)` for smart conversion of user input.
9
+ - Normalization (e.g., lowercasing) is applied by `parse`, `coerce`, and `<<` methods, but not by `new` when given arrays.
10
+
11
+ ## v0.55.0
12
+
13
+ - **Breaking**: Move `Protocol::HTTP::Header::QuotedString` to `Protocol::HTTP::QuotedString` for better reusability.
14
+ - **Breaking**: Handle cookie key/value pairs using `QuotedString` as per RFC 6265.
15
+ - Don't use URL encoding for cookie key/value.
16
+ - **Breaking**: Remove `Protocol::HTTP::URL` and `Protocol::HTTP::Reference` – replaced by `Protocol::URL` gem.
17
+ - `Protocol::HTTP::URL` -\> `Protocol::URL::Encoding`.
18
+ - `Protocol::HTTP::Reference` -\> `Protocol::URL::Reference`.
19
+
3
20
  ## v0.54.0
4
21
 
5
22
  - Introduce rich support for `Header::Digest`, `Header::ServerTiming`, `Header::TE`, `Header::Trailer` and `Header::TransferEncoding`.
@@ -125,3 +142,160 @@ def call(request)
125
142
  # ...
126
143
  end
127
144
  ```
145
+
146
+ ## v0.29.0
147
+
148
+ - Introduce `rewind` and `rewindable?` methods for body rewinding capabilities.
149
+ - Add support for output buffer in `read_partial`/`readpartial` methods.
150
+ - `Reader#buffered!` now returns `self` for method chaining.
151
+
152
+ ## v0.28.0
153
+
154
+ - Add convenient `Reader#buffered!` method to buffer the body.
155
+ - Modernize gem infrastructure with RuboCop integration.
156
+
157
+ ## v0.27.0
158
+
159
+ - Expand stream interface to support `gets`/`puts` operations.
160
+ - Skip empty key/value pairs in header processing.
161
+ - Prefer lowercase method names for consistency.
162
+ - Add `as_json` support to avoid default Rails implementation.
163
+ - Use `@callback` to track invocation state.
164
+ - Drop `base64` gem dependency.
165
+
166
+ ## v0.26.0
167
+
168
+ - Prefer connection `close` over `keep-alive` when both are present.
169
+ - Add support for `#readpartial` method.
170
+ - Add `base64` dependency.
171
+
172
+ ## v0.25.0
173
+
174
+ - Introduce explicit support for informational responses (1xx status codes).
175
+ - Add `cache-control` support for `must-revalidate`, `proxy-revalidate`, and `s-maxage` directives.
176
+ - Add `#strong_match?` and `#weak_match?` methods to `ETags` header.
177
+ - Fix `last-modified`, `if-modified-since` and `if-unmodified-since` headers to use proper `Date` parsing.
178
+ - Improve date/expires header parsing.
179
+ - Add tests for `Stream#close_read`.
180
+ - Check if input is closed before raising `IOError`.
181
+ - Ensure saved files truncate existing file by default.
182
+
183
+ ## v0.24.0
184
+
185
+ - Add output stream `#<<` as alias for `#write`.
186
+ - Add support for `Headers#include?` and `#key?` methods.
187
+ - Fix URL unescape functionality.
188
+ - Fix cookie parsing issues.
189
+ - Fix superclass mismatch in `Protocol::HTTP::Middleware::Builder`.
190
+ - Allow trailers without explicit `trailer` header.
191
+ - Fix cookie handling and Ruby 2 keyword arguments.
192
+
193
+ ## v0.23.0
194
+
195
+ - Improve argument handling.
196
+ - Rename `path` parameter to `target` to better match RFCs.
197
+
198
+ ## v0.22.0
199
+
200
+ - Rename `trailers` to `trailer` for consistency.
201
+
202
+ ## v0.21.0
203
+
204
+ - Streaming interface improvements.
205
+ - Rename `Streamable` to `Completable`.
206
+
207
+ ## v0.20.0
208
+
209
+ - Improve `Authorization` header implementation.
210
+
211
+ ## v0.19.0
212
+
213
+ - Expose `Body#ready?` for more efficient response handling.
214
+
215
+ ## v0.18.0
216
+
217
+ - Add `#trailers` method which enumerates trailers without marking tail.
218
+ - Don't clear trailers in `#dup`, move functionality to `flatten!`.
219
+ - All requests and responses must have mutable headers instance.
220
+
221
+ ## v0.17.0
222
+
223
+ - Remove deferred headers due to complexity.
224
+ - Remove deprecated `Headers#slice!`.
225
+ - Add support for static, dynamic and streaming content to `cache-control` model.
226
+ - Initial support for trailers.
227
+ - Add support for `Response#not_modified?`.
228
+
229
+ ## v0.16.0
230
+
231
+ - Add support for `if-match` and `if-none-match` headers.
232
+ - Revert `Request#target` change for HTTP/2 compatibility.
233
+
234
+ ## v0.15.0
235
+
236
+ - Prefer `Request#target` over `Request#path`.
237
+ - Add body implementation to support HEAD requests.
238
+ - Add support for computing digest on buffered body.
239
+ - Add `Headers#set(key, value)` to replace existing values.
240
+ - Add support for `vary` header.
241
+ - Add support for `no-cache` & `no-store` cache directives.
242
+
243
+ ## v0.14.0
244
+
245
+ - Add `Cacheable` body for buffering and caching responses.
246
+ - Add support for `cache-control` header.
247
+
248
+ ## v0.13.0
249
+
250
+ - Add support for `connection` header.
251
+ - Fix handling of keyword arguments.
252
+
253
+ ## v0.12.0
254
+
255
+ - Improved handling of `cookie` header.
256
+ - Add `Headers#clear` method.
257
+
258
+ ## v0.11.0
259
+
260
+ - Ensure `Body#call` invokes `stream.close` when done.
261
+
262
+ ## v0.10.0
263
+
264
+ - Allow user to specify size for character devices.
265
+
266
+ ## v0.9.1
267
+
268
+ - Add support for `authorization` header.
269
+
270
+ ## v0.8.0
271
+
272
+ - Remove `reason` from `Response`.
273
+
274
+ ## v0.7.0
275
+
276
+ - Explicit path handling in `Reference#with`.
277
+
278
+ ## v0.6.0
279
+
280
+ - Initial version with basic HTTP protocol support.
281
+
282
+ ## v0.5.1
283
+
284
+ - Fix path splitting behavior when path is empty.
285
+ - Add `connect` method.
286
+ - Support protocol in `[]` constructor.
287
+ - Incorporate middleware functionality.
288
+
289
+ ## v0.4.0
290
+
291
+ - Add `Request`, `Response` and `Body` classes from `async-http`.
292
+ - Allow deletion of non-existent header fields.
293
+
294
+ ## v0.3.0
295
+
296
+ - **Initial release** of `protocol-http` gem.
297
+ - Initial implementation of HTTP/2 flow control.
298
+ - Support for connection preface and settings frames.
299
+ - Initial headers support.
300
+ - Implementation of `Connection`, `Client` & `Server` classes.
301
+ - HTTP/2 protocol framing and headers.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,20 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.54.0
4
+ version: 0.56.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - Thomas Morgan
9
9
  - Bruno Sutic
10
10
  - Herrick Fang
11
+ - William T. Nelson
11
12
  - Bryan Powell
12
13
  - Dan Olson
13
14
  - Earlopain
14
15
  - Genki Takiuchi
15
16
  - Marcelo Junior
16
17
  - Olle Jonsson
17
- - William T. Nelson
18
18
  - Yuta Iwama
19
19
  bindir: bin
20
20
  cert_chain:
@@ -96,7 +96,6 @@ files:
96
96
  - lib/protocol/http/header/etags.rb
97
97
  - lib/protocol/http/header/multiple.rb
98
98
  - lib/protocol/http/header/priority.rb
99
- - lib/protocol/http/header/quoted_string.rb
100
99
  - lib/protocol/http/header/server_timing.rb
101
100
  - lib/protocol/http/header/split.rb
102
101
  - lib/protocol/http/header/te.rb
@@ -108,10 +107,9 @@ files:
108
107
  - lib/protocol/http/middleware.rb
109
108
  - lib/protocol/http/middleware/builder.rb
110
109
  - lib/protocol/http/peer.rb
111
- - lib/protocol/http/reference.rb
110
+ - lib/protocol/http/quoted_string.rb
112
111
  - lib/protocol/http/request.rb
113
112
  - lib/protocol/http/response.rb
114
- - lib/protocol/http/url.rb
115
113
  - lib/protocol/http/version.rb
116
114
  - license.md
117
115
  - readme.md
metadata.gz.sig CHANGED
Binary file
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Released under the MIT License.
4
- # Copyright, 2025, by Samuel Williams.
5
-
6
- module Protocol
7
- module HTTP
8
- module Header
9
- # According to https://tools.ietf.org/html/rfc7231#appendix-C
10
- TOKEN = /[!#$%&'*+\-.^_`|~0-9A-Z]+/i
11
-
12
- QUOTED_STRING = /"(?:.(?!(?<!\\)"))*.?"/
13
-
14
- # https://tools.ietf.org/html/rfc7231#section-5.3.1
15
- QVALUE = /0(\.[0-9]{0,3})?|1(\.[0]{0,3})?/
16
-
17
- # Handling of HTTP quoted strings.
18
- module QuotedString
19
- # Unquote a "quoted-string" value according to <https://tools.ietf.org/html/rfc7230#section-3.2.6>. It should already match the QUOTED_STRING pattern above by the parser.
20
- def self.unquote(value, normalize_whitespace = true)
21
- value = value[1...-1]
22
-
23
- value.gsub!(/\\(.)/, '\1')
24
-
25
- if normalize_whitespace
26
- # LWS = [CRLF] 1*( SP | HT )
27
- value.gsub!(/[\r\n]+\s+/, " ")
28
- end
29
-
30
- return value
31
- end
32
-
33
- QUOTES_REQUIRED = /[()<>@,;:\\"\/\[\]?={} \t]/
34
-
35
- # Quote a string for HTTP header values if required.
36
- #
37
- # @raises [ArgumentError] if the value contains invalid characters like control characters or newlines.
38
- def self.quote(value, force = false)
39
- # Check if quoting is required:
40
- if value =~ QUOTES_REQUIRED or force
41
- "\"#{value.gsub(/["\\]/, '\\\\\0')}\""
42
- else
43
- value
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end