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 e55900c
Browse filesBrowse the repository at this point in the historyBrowse files
# - Otherwise, if the `content-length` is present, the body is read until the content length is reached.
1003
1005
# - Otherwise, if `remainder` is true, the body is read until the connection is closed.
1004
1006
#
1007
+
# Framing errors (e.g. `transfer-encoding` in an HTTP/1.0 message, or a request whose final transfer coding is not `chunked`) are rejected and mark the connection as non-persistent, since the remainder of the stream can no longer be delimited reliably.
1008
+
#
1005
1009
# @parameter headers [Hash] the headers of the message.
1006
-
# @parameter remainder [Boolean] whether to read the remainder of the body.
1010
+
# @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.
1011
+
# @parameter version [String | Nil] the HTTP version of the message, if known.
1007
1012
# @returns [Object] the body.
1008
-
def read_body(headers, remainder = false)
1013
+
# @raises [BadRequest] if the message framing is invalid.
1014
+
def read_body(headers, remainder = false, version = nil)
1009
1015
# 3. If a Transfer-Encoding header field is present and the chunked
1010
1016
# transfer coding (Section 4.1) is the final encoding, the message
1011
1017
# body length is determined by reading and decoding the chunked
1012
1018
# data until the transfer coding indicates the data is complete.
1013
1019
if transfer_encoding = headers.delete(TRANSFER_ENCODING)
1020
+
# A server or client that receives an HTTP/1.0 message containing a
1021
+
# Transfer-Encoding header field MUST treat the message as if the
1022
+
# framing is faulty, even if a Content-Length is present, and close
1023
+
# the connection after processing the message.
1024
+
if version == HTTP10
1025
+
@persistent = false
1026
+
raise BadRequest, "HTTP/1.0 message contains transfer encoding!"
1027
+
end
1028
+
1014
1029
# If a message is received with both a Transfer-Encoding and a
1015
1030
# Content-Length header field, the Transfer-Encoding overrides the
1016
1031
# Content-Length. Such a message might indicate an attempt to
Copy file name to clipboardExpand all lines: releases.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,9 @@
1
1
# Releases
2
2
3
+
## Unreleased
4
+
5
+
- Reject `transfer-encoding` in HTTP/1.0 messages and requests whose final transfer coding is not `chunked` with `BadRequest`, and mark the connection as non-persistent, as required by RFC 9112 for reliable message framing.
6
+
3
7
## v0.41.0
4
8
5
9
- Map remote socket failures to `Protocol::HTTP::RemoteError` and prevent connection reuse.
0 commit comments