You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5dba537
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: lib/protocol/http1/connection.rb
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -441,6 +441,7 @@ def read_request_line
441
441
# @yields {|host, method, path, version, headers, body| ...} if a block is given.
442
442
# @returns [Tuple(String, String, String, String, HTTP::Headers, Protocol::HTTP1::Body) | Nil] the host, method, path, version, headers, and body of the request, or `nil` if the connection is closed.
443
443
# @raises [ProtocolError] if the connection is not in the idle state.
444
+
# @raises [BadRequest] if the request line, headers, or body framing are invalid, e.g. an unsupported HTTP version, a malformed header, or a `transfer-encoding` that cannot be used to delimit the body.
444
445
defread_request
445
446
open!
446
447
@@ -502,6 +503,7 @@ def interim_status?(status)
502
503
# @returns [Tuple(String, Integer, String, HTTP::Headers, Protocol::HTTP1::Body)] the version, status, reason, headers, and body of the response.
503
504
# @raises [ProtocolError] if the connection is not in the open or half-closed local state.
504
505
# @raises [EOFError] if the connection is closed.
506
+
# @raises [BadRequest] if the status line, headers, or body framing are invalid, e.g. an unsupported HTTP version, a malformed header, or a `transfer-encoding` that cannot be used to delimit the body.
# @parameter headers [Hash] the headers of the request.
989
993
# @parameter version [String | Nil] the HTTP version of the request, if known.
994
+
# @returns [Object | Nil] the body, or `nil` if the request has no body.
995
+
# @raises [BadRequest] if the `content-length` is invalid or the message framing is invalid, see {read_body}.
990
996
defread_request_body(method,headers,version=nil)
991
997
# 2. Any 2xx (Successful) response to a CONNECT request implies that
992
998
# the connection will become a tunnel immediately after the empty
@@ -1017,6 +1023,8 @@ def read_request_body(method, headers, version = nil)
1017
1023
#
1018
1024
# Framing errors (e.g. `transfer-encoding` in an HTTP/1.0 message, `chunked` applied more than once, or a request whose transfer coding is anything other than exactly `chunked`) are rejected and mark the connection as non-persistent, since the remainder of the stream can no longer be delimited reliably.
1019
1025
#
1026
+
# Rejecting HTTP/1.0 responses with `transfer-encoding` follows RFC 9112 Section 6.1; browsers instead ignore the header and read until the connection is closed. If interoperability with such servers ever requires relaxing this, the correct relaxation is close-delimited reading via {read_remainder_body}, never chunked decoding, since an HTTP/1.0 peer cannot be relied upon to have applied the coding.
1027
+
#
1020
1028
# @parameter headers [Hash] the headers of the message.
1021
1029
# @parameter remainder [Boolean] whether to read the remainder of the body, i.e. the message is a response which may be delimited by closing the connection.
1022
1030
# @parameter version [String | Nil] the HTTP version of the message, if known.
0 commit comments