File tree 2 files changed +30
-1
lines changed
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -470,8 +470,13 @@ def read_request_line(socket)
470
470
471
471
def read_header ( socket )
472
472
if socket
473
+ end_of_headers = false
474
+
473
475
while line = read_line ( socket )
474
- break if /\A #{ CRLF } \z /om =~ line
476
+ if line == CRLF
477
+ end_of_headers = true
478
+ break
479
+ end
475
480
if ( @request_bytes += line . bytesize ) > MAX_HEADER_LENGTH
476
481
raise HTTPStatus ::RequestEntityTooLarge , 'headers too large'
477
482
end
@@ -480,6 +485,9 @@ def read_header(socket)
480
485
end
481
486
@raw_header << line
482
487
end
488
+
489
+ # Allow if @header already set to support chunked trailers
490
+ raise HTTPStatus ::EOFError unless end_of_headers || @header
483
491
end
484
492
@header = HTTPUtils ::parse_header ( @raw_header . join )
485
493
Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ def test_invalid_content_length_header
86
86
msg = <<-_end_of_message_
87
87
GET / HTTP/1.1
88
88
Content-Length:#{ cl }
89
+
89
90
_end_of_message_
90
91
req = WEBrick ::HTTPRequest . new ( WEBrick ::Config ::HTTP )
91
92
assert_raise ( WEBrick ::HTTPStatus ::BadRequest ) {
@@ -189,6 +190,7 @@ def test_duplicate_content_length_header
189
190
GET / HTTP/1.1
190
191
Content-Length: 1
191
192
Content-Length: 2
193
+
192
194
_end_of_message_
193
195
req = WEBrick ::HTTPRequest . new ( WEBrick ::Config ::HTTP )
194
196
assert_raise ( WEBrick ::HTTPStatus ::BadRequest ) {
@@ -632,6 +634,25 @@ def test_eof_raised_when_line_is_nil
632
634
}
633
635
end
634
636
637
+ def test_eof_raised_with_missing_line_between_headers_and_body
638
+ msg = <<-_end_of_message_
639
+ GET / HTTP/1.0
640
+ _end_of_message_
641
+ req = WEBrick ::HTTPRequest . new ( WEBrick ::Config ::HTTP )
642
+ assert_raise ( WEBrick ::HTTPStatus ::EOFError ) {
643
+ req . parse ( StringIO . new ( msg . gsub ( /^ {6}/ , "" ) . gsub ( "\n " , "\r \n " ) ) )
644
+ }
645
+
646
+ msg = <<-_end_of_message_
647
+ GET / HTTP/1.0
648
+ Foo: 1
649
+ _end_of_message_
650
+ req = WEBrick ::HTTPRequest . new ( WEBrick ::Config ::HTTP )
651
+ assert_raise ( WEBrick ::HTTPStatus ::EOFError ) {
652
+ req . parse ( StringIO . new ( msg . gsub ( /^ {6}/ , "" ) . gsub ( "\n " , "\r \n " ) ) )
653
+ }
654
+ end
655
+
635
656
def test_cookie_join
636
657
req = WEBrick ::HTTPRequest . new ( WEBrick ::Config ::HTTP )
637
658
req . parse ( StringIO . new ( "GET / HTTP/1.1\r \n cookie: a=1\r \n cookie: b=2\r \n \r \n " ) )
You can’t perform that action at this time.
0 commit comments