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

Make header parsing more RFC-7230-compliant #1318

Merged

Conversation

haikuginger
Copy link
Contributor

Fixes #1286.

This change ensures that we fail with a descriptive exception in cases where invalid headers beginning with optional whitespace are passed without a prior header to which they can be attached.

This change also brings our parsing of valid line-folded headers more in line with RFC-7230 by joining such a value to the existing header value with a single space character and stripping optional whitespace from either end.

@haikuginger haikuginger self-assigned this Jan 23, 2018
@@ -305,13 +306,22 @@ def from_httplib(cls, message): # Python 2
# python2.7 does not expose a proper API for exporting multiheaders
# efficiently. This function re-reads raw lines from the message
# object and extracts the multiheaders properly.
obs_fold_continued_leaders = (' ', '\t',)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: trailing comma isn't needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely not needed; I've picked it up as a stylistic thing, though, with tuples; they require a trailing comma to build a 1-tuple, so I've just been doing it consistently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am unsure whether this consistency is a hobgoblin of mine or not, so opinions on that topic are quite welcome. 😉

Copy link
Member

Choose a reason for hiding this comment

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

It's just the only thing that stood out to me in this code. :) I think it looks great either way. 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Given that it's not the style of the project, I'd rather we either introduce a check for this to ensure it's consistent across the project or drop it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fair. Given that I don't want to blow up the scope of this PR, I'll remove the trailing comma for now and revisit the style later on.

@codecov-io
Copy link

codecov-io commented Jan 25, 2018

Codecov Report

Merging #1318 into master will increase coverage by 2.66%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1318      +/-   ##
=========================================
+ Coverage   97.33%    100%   +2.66%     
=========================================
  Files          21      21              
  Lines        1989    1991       +2     
=========================================
+ Hits         1936    1991      +55     
+ Misses         53       0      -53
Impacted Files Coverage Δ
urllib3/_collections.py 100% <ø> (ø) ⬆️
urllib3/connectionpool.py 100% <0%> (ø) ⬆️
urllib3/util/selectors.py 100% <0%> (+16.35%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64514ec...70418f8. Read the comment docs.

@haikuginger
Copy link
Contributor Author

@sigmavirus24, hoping to get a review from you on this to make sure it passes RFC muster.

Copy link
Contributor

@sigmavirus24 sigmavirus24 left a comment

Choose a reason for hiding this comment

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

Style nit but otherwise this LGTM afaict

@haikuginger haikuginger reopened this Jan 29, 2018
@haikuginger haikuginger merged commit d9898fb into urllib3:master Jan 30, 2018
@haikuginger haikuginger deleted the header-continuation-standardization branch January 30, 2018 14:11
Dobatymo pushed a commit to Dobatymo/urllib3 that referenced this pull request Mar 16, 2022
…standardization

Make header parsing more RFC-7230-compliant
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.

None yet

4 participants