Skip to content
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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

TheFrozenFire
Copy link

@TheFrozenFire TheFrozenFire commented Nov 1, 2024

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"

Copy link
Member

@th4s th4s left a 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?

@th4s th4s requested a review from sinui0 November 25, 2024 09:33
Copy link
Member

@sinui0 sinui0 left a 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| {
Copy link
Member

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(""))
Copy link
Member

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.

Comment on lines +239 to +240
"Transfer-Encoding other than identity not supported yet: {:?}",
bad_values
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Transfer-Encoding other than identity not supported yet: {:?}",
bad_values
"Transfer-Encoding other than identity not supported yet: {bad_values}"

Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants