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

http/message: Split request line as bytes to avoid splitting on 0x0A. Fixes #1577 #1578

Merged
merged 2 commits into from
Sep 2, 2017
Merged

Conversation

rslinckx
Copy link
Contributor

No description provided.

yield bytes(d.encode("latin1"))
for d in self.data:
if six.PY3:
yield bytes([d])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the cast is necessary anymore, since we open the file in binary mode.

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'm not sure what was the intention there, but it's reading the data byte-by-byte and yielding byte-by-byte.

In py2, iterating the data str will yield individual bytes as str
In py3, iterating the data bytes will yield individual bytes as int, which then need to be returned as new bytes using bytes([d])

Previous code was just plain wrong under py2 as str(self.data.decode("latin1")) will try to re-encode an unicode string in ascii

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the explanation.

@tilgovi
Copy link
Collaborator

tilgovi commented Aug 27, 2017

Looks good. Thank you!

@tilgovi
Copy link
Collaborator

tilgovi commented Aug 31, 2017

@berkerpeksag, @benoitc do you see any problem with this?

@benoitc benoitc merged commit c171c15 into benoitc:master Sep 2, 2017
@benoitc
Copy link
Owner

benoitc commented Sep 2, 2017

@rslinckx thanks

@tilgovi merged :)

mjjbell pushed a commit to mjjbell/gunicorn that referenced this pull request Mar 16, 2018
http/message: Split request line as bytes to avoid splitting on 0x0A. Fixes benoitc#1577
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