File tree Expand file tree Collapse file tree 2 files changed +43
-3
lines changed Expand file tree Collapse file tree 2 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -40,8 +40,8 @@ module HTTP1
4040 WS = /[ \t ]/ # Whitespace.
4141 OWS = /#{ WS } */ # Optional whitespace.
4242 VCHAR = /[!-~]/ # Match visible characters from ASCII 33 to 126.
43- FIELD_VALUE = /(?: #{ VCHAR } +(?:#{ WS } +#{ VCHAR } )* )*/ . freeze
44- HEADER = /\A (#{ FIELD_NAME } ):#{ OWS } (#{ FIELD_VALUE } )#{ OWS } \z / . freeze
43+ FIELD_VALUE = /#{ VCHAR } +(?:#{ WS } +#{ VCHAR } + )*/ . freeze
44+ HEADER = /\A (#{ FIELD_NAME } ):#{ OWS } (?:( #{ FIELD_VALUE } )#{ OWS } )? \z / . freeze
4545
4646 VALID_FIELD_NAME = /\A #{ FIELD_NAME } \z / . freeze
4747 VALID_FIELD_VALUE = /\A #{ FIELD_VALUE } \z / . freeze
@@ -487,7 +487,7 @@ def read_headers
487487 break if line . empty?
488488
489489 if match = line . match ( HEADER )
490- fields << [ match [ 1 ] , match [ 2 ] ]
490+ fields << [ match [ 1 ] , match [ 2 ] || "" ]
491491 else
492492 raise BadHeader , "Could not parse header: #{ line . inspect } "
493493 end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ # Released under the MIT License.
4+ # Copyright, 2025, by Samuel Williams.
5+
6+ require "protocol/http1/connection"
7+
8+ describe Protocol ::HTTP1 do
9+ describe "REQUEST_LINE" do
10+ it "parses in linear time" do
11+ skip_unless_method_defined ( :linear_time? , Regexp . singleton_class )
12+
13+ expect ( Regexp ) . to be ( :linear_time? , Protocol ::HTTP1 ::REQUEST_LINE )
14+ end
15+ end
16+
17+ describe "HEADER" do
18+ it "parses in linear time" do
19+ skip_unless_method_defined ( :linear_time? , Regexp . singleton_class )
20+
21+ expect ( Regexp ) . to be ( :linear_time? , Protocol ::HTTP1 ::HEADER )
22+ end
23+ end
24+
25+ describe "VALID_FIELD_NAME" do
26+ it "parses in linear time" do
27+ skip_unless_method_defined ( :linear_time? , Regexp . singleton_class )
28+
29+ expect ( Regexp ) . to be ( :linear_time? , Protocol ::HTTP1 ::VALID_FIELD_NAME )
30+ end
31+ end
32+
33+ describe "VALID_FIELD_VALUE" do
34+ it "parses in linear time" do
35+ skip_unless_method_defined ( :linear_time? , Regexp . singleton_class )
36+
37+ expect ( Regexp ) . to be ( :linear_time? , Protocol ::HTTP1 ::VALID_FIELD_VALUE )
38+ end
39+ end
40+ end
You can’t perform that action at this time.
0 commit comments