-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve handling of Transfer-Encoding errors #46
base: dev
Are you sure you want to change the base?
Improve handling of Transfer-Encoding errors #46
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks lgtm,
looks like formatting is off. Did you use rustfmt
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ty
comments on request logic also apply to response.
@@ -222,12 +222,23 @@ fn request_body_len(request: &Request) -> Result<usize, ParseError> { | |||
// the Transfer-Encoding overrides the Content-Length | |||
if request | |||
.headers_with_name("Transfer-Encoding") | |||
.next() | |||
.is_some() | |||
.any(|h| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be sufficient to just handle the first header with this key, ie
if let Some(header) = request.headers_with_name("Transfer-Encoding").first()
)) | ||
let bad_values = request | ||
.headers_with_name("Transfer-Encoding") | ||
.map(|h| std::str::from_utf8(h.value.0.as_bytes()).unwrap_or("")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unwrap_or("")
will be misleading if the header value is not value utf8. Better to return a parse error indicating that.
"Transfer-Encoding other than identity not supported yet: {:?}", | ||
bad_values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Transfer-Encoding other than identity not supported yet: {:?}", | |
bad_values | |
"Transfer-Encoding other than identity not supported yet: {bad_values}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad_values
is String
which implements Display
, so no need to format using Debug
Transfer-Encoding errors are currently very opaque. This change updates the logic to allow for
Transfer-Encoding: identity
(the effective default), and add the incorrect values to the error message to make it easier to troubleshoot bad Transfer-Encoding values.An example of the new error message:
parsing error: Transfer-Encoding other than identity not supported yet: "chunked"