feat(http1): implement obsolete line folding (#2734)
The client now has an option to allow parsing responses with obsolete line folding in headers. The option is off by default, since the spec recommends to reject such things if you can.
This commit is contained in:
@@ -615,6 +615,49 @@ impl Builder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set whether HTTP/1 connections will accept obsolete line folding for
|
||||
/// header values.
|
||||
///
|
||||
/// Newline codepoints (`\r` and `\n`) will be transformed to spaces when
|
||||
/// parsing.
|
||||
///
|
||||
/// You probably don't need this, here is what [RFC 7230 Section 3.2.4.] has
|
||||
/// to say about it:
|
||||
///
|
||||
/// > A server that receives an obs-fold in a request message that is not
|
||||
/// > within a message/http container MUST either reject the message by
|
||||
/// > sending a 400 (Bad Request), preferably with a representation
|
||||
/// > explaining that obsolete line folding is unacceptable, or replace
|
||||
/// > each received obs-fold with one or more SP octets prior to
|
||||
/// > interpreting the field value or forwarding the message downstream.
|
||||
///
|
||||
/// > A proxy or gateway that receives an obs-fold in a response message
|
||||
/// > that is not within a message/http container MUST either discard the
|
||||
/// > message and replace it with a 502 (Bad Gateway) response, preferably
|
||||
/// > with a representation explaining that unacceptable line folding was
|
||||
/// > received, or replace each received obs-fold with one or more SP
|
||||
/// > octets prior to interpreting the field value or forwarding the
|
||||
/// > message downstream.
|
||||
///
|
||||
/// > A user agent that receives an obs-fold in a response message that is
|
||||
/// > not within a message/http container MUST replace each received
|
||||
/// > obs-fold with one or more SP octets prior to interpreting the field
|
||||
/// > value.
|
||||
///
|
||||
/// Note that this setting does not affect HTTP/2.
|
||||
///
|
||||
/// Default is false.
|
||||
///
|
||||
/// [RFC 7230 Section 3.2.4.]: https://tools.ietf.org/html/rfc7230#section-3.2.4
|
||||
pub fn http1_allow_obsolete_multiline_headers_in_responses(
|
||||
&mut self,
|
||||
enabled: bool,
|
||||
) -> &mut Builder {
|
||||
self.h1_parser_config
|
||||
.allow_obsolete_multiline_headers_in_responses(enabled);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set whether HTTP/1 connections should try to use vectored writes,
|
||||
/// or always flatten into a single buffer.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user