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

Correctly handle repeated headers. #743

Merged
merged 1 commit into from
Mar 25, 2016

Conversation

Stebalien
Copy link
Contributor

HeaderX: a
HeaderX: b

MUST be interpreted as

HeaderX: a, b

See: https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2

Fixes #683

@GitCop
Copy link

GitCop commented Mar 11, 2016

Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:

  • Commit: 2ba4227
    • Commits must be in the following format: %{type}(%{scope}): %{description}

Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md


This message was auto-generated by https://gitcop.com

@@ -79,7 +79,6 @@ __hyper__tm!(ContentLength, tests {
test_header!(test1, vec![b"3495"], Some(HeaderField(3495)));

test_header!(test_invalid, vec![b"34v95"], None);
test_header!(test_duplicates, vec![b"5", b"5"], Some(HeaderField(5)));
test_header!(test_duplicates_vary, vec![b"5", b"6", b"5"], None);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why did you test this case?

Copy link
Member

Choose a reason for hiding this comment

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

For the test_duplicates test, from RFC7230#3.3.2:

If a message is received that has multiple Content-Length header
fields with field-values consisting of the same decimal value, or a
single Content-Length header field with a field value containing a
list of identical decimal values (e.g., "Content-Length: 42, 42"),
indicating that duplicate Content-Length header fields have been
generated or combined by an upstream message processor, then the
recipient MUST either reject the message as invalid or replace the
duplicated field-values with a single valid Content-Length field
containing that decimal value prior to determining the message body
length or forwarding the message.

For the test_duplicates_vary test, step 4 of RFC7230#3.3.3:

If a message is received without Transfer-Encoding and with
either multiple Content-Length header fields having differing
field-values or a single Content-Length header field having an
invalid value, then the message framing is invalid and the
recipient MUST treat it as an unrecoverable error.

The request should error out with varying Content-Lengths, which hyper doesn't do, but at the very least, it shouldn't pick any of the stated values as valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, this change never picks any of the stated values even if they are all identical.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like the parsing of ContentLength has been left alone, so this test should still pass. I'd rather keep the functionality of ContentLength the same for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, my diagnosis was wrong (guessing is bad). This change doesn't change the behavior of ContentLength as you say. However, it changes the behavior of the test_header macro to correctly verify that parsing and then formatting a header returns the original header. However, in this case, hyper will "clean" the header removing the second content length so this test will fail.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 90.608% when pulling 9d39576 on Stebalien:repeated-header into 028f586 on hyperium:master.

@seanmonstar
Copy link
Member

This looks fantastic. If you could add the ContentLength test back in, this will be good to go!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 90.62% when pulling 70c6914 on Stebalien:repeated-header into 028f586 on hyperium:master.

@seanmonstar seanmonstar merged commit 2cb83b4 into hyperium:master Mar 25, 2016
@seanmonstar
Copy link
Member

Thanks!

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.

4 participants