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 ca8a5bb
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: lib/protocol/http1/connection.rb
+6-10Lines changed: 6 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ module HTTP1
34
34
# HTTP/1.x request line parser:
35
35
TOKEN=/[!#$%&'*+\-\.\^_`|~0-9a-zA-Z]+/.freeze
36
36
VALID_METHOD=/\A#{TOKEN}\z/.freeze
37
-
# The HTTP-version is case-sensitive (RFC 9112 Section 2.3). Only the HTTP/1.x family is accepted; any minor version is treated as HTTP/1.1 (RFC 9110 Section 2.5):
37
+
# The HTTP-version is case-sensitive, and only HTTP/1.x is accepted:
# @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
+
# @raises [BadRequest] if the request line, headers, or body framing are invalid.
445
445
defread_request
446
446
open!
447
447
@@ -503,7 +503,7 @@ def interim_status?(status)
503
503
# @returns [Tuple(String, Integer, String, HTTP::Headers, Protocol::HTTP1::Body)] the version, status, reason, headers, and body of the response.
504
504
# @raises [ProtocolError] if the connection is not in the open or half-closed local state.
505
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.
506
+
# @raises [BadRequest] if the status line, headers, or body framing are invalid.
# - The `CONNECT` method is used to establish a tunnel, so the body is read until the connection is closed.
988
-
# - The `upgrade` header is used to upgrade the connection to a different protocol (typically WebSockets), so the body is read until the connection is closed. It is ignored in HTTP/1.0 requests, as required by RFC 9110 Section 7.8.
988
+
# - The `upgrade` header is used to upgrade the connection to a different protocol (typically WebSockets), so the body is read until the connection is closed. It is ignored in HTTP/1.0 requests.
989
989
# - Otherwise, the body is read according to {read_body}.
990
990
#
991
991
# @parameter method [String] the HTTP method.
@@ -1003,9 +1003,7 @@ def read_request_body(method, headers, version = nil)
1003
1003
returnread_tunnel_body
1004
1004
end
1005
1005
1006
-
# A successful upgrade response implies that the connection will become a tunnel immediately after the empty line that concludes the header fields.
1007
-
#
1008
-
# A server that receives an Upgrade header field in an HTTP/1.0 request MUST ignore that Upgrade field (RFC 9110 Section 7.8), so the body is framed according to the remaining headers instead.
1006
+
# A successful upgrade response implies that the connection will become a tunnel immediately after the empty line that concludes the header fields. An HTTP/1.0 request cannot upgrade (RFC 9110 Section 7.8):
1009
1007
ifheaders[UPGRADE]andversion != HTTP10
1010
1008
returnread_upgrade_body
1011
1009
end
@@ -1021,9 +1019,7 @@ def read_request_body(method, headers, version = nil)
1021
1019
# - Otherwise, if the `content-length` is present, the body is read until the content length is reached.
1022
1020
# - Otherwise, if `remainder` is true, the body is read until the connection is closed.
1023
1021
#
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.
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.
1022
+
# Invalid framing is rejected and marks the connection as non-persistent, since the rest of the stream can no longer be delimited.
1027
1023
#
1028
1024
# @parameter headers [Hash] the headers of the message.
1029
1025
# @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.
0 commit comments