File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed
Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -26,5 +26,18 @@ def initialize(key)
2626 # @attribute [String] key The header key that was duplicated.
2727 attr :key
2828 end
29+
30+ # Raised when an invalid trailer header is encountered in headers.
31+ class InvalidTrailerError < Error
32+ include BadRequest
33+
34+ # @parameter key [String] The trailer key that is invalid.
35+ def initialize ( key )
36+ super ( "Invalid trailer key: #{ key . inspect } " )
37+ end
38+
39+ # @attribute [String] key The trailer key that is invalid.
40+ attr :key
41+ end
2942 end
3043end
Original file line number Diff line number Diff line change @@ -407,7 +407,7 @@ def delete(key)
407407 if policy = @policy [ key ]
408408 # Check if we're adding to trailers and this header is allowed:
409409 if trailer && !policy . trailer?
410- return false
410+ raise InvalidTrailerError , key
411411 end
412412
413413 if current_value = hash [ key ]
@@ -422,7 +422,7 @@ def delete(key)
422422 else
423423 # By default, headers are not allowed in trailers:
424424 if trailer
425- return false
425+ raise InvalidTrailerError , key
426426 end
427427
428428 if hash . key? ( key )
@@ -435,6 +435,8 @@ def delete(key)
435435
436436 # 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.
437437 #
438+ # This will enforce policy rules, such as merging multiple headers into arrays, or raising errors for duplicate headers.
439+ #
438440 # @returns [Hash] A hash table of `{key, value}` pairs.
439441 def to_h
440442 unless @indexed
Original file line number Diff line number Diff line change 343343 it "can't add a #{ key . inspect } header in the trailer" , unique : key do
344344 trailer = headers . trailer!
345345 headers . add ( key , "example" )
346- expect ( headers ) . not . to be ( :include? , key )
346+ expect { headers . to_h } . to raise_exception ( Protocol :: HTTP :: InvalidTrailerError )
347347 end
348348 end
349349 end
You can’t perform that action at this time.
0 commit comments