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

fix header encoding error #67

Closed
benoitc opened this issue Jun 7, 2014 · 6 comments
Closed

fix header encoding error #67

benoitc opened this issue Jun 7, 2014 · 6 comments
Labels

Comments

@benoitc
Copy link

benoitc commented Jun 7, 2014

find embedded a patch fixing benoitc/gunicorn#775

--- protocol.orig.py    2014-06-07 15:19:01.234911490 +0200
+++ protocol.py 2014-06-07 15:22:23.158921591 +0200
@@ -629,8 +629,9 @@
         # status + headers
         hdrs = ''.join(itertools.chain(
            (self.status_line,),
-           *((k, ': ', v, '\r\n') for k, v in self.headers)))
-        hdrs = hdrs.encode('ascii') + b'\r\n'
+            *((k, ': ', str(v).strip(), '\r\n') for k, v in self.headers)))
+
+        hdrs = hdrs.encode('utf8') + b'\r\n'

         self.output_length += len(hdrs)
         self.transport.write(hdrs)
@asvetlov
Copy link
Member

asvetlov commented Jun 7, 2014

LGTM
@fafhrd91 thoughts?

@fafhrd91
Copy link
Member

fafhrd91 commented Jun 7, 2014

I think we should add check for Unicode in add_header method.

@asvetlov
Copy link
Member

asvetlov commented Jun 7, 2014

@fafhrd91 something like

assert isinstance(value, str), '{!r} is not a string'.format(value)

???

@fafhrd91
Copy link
Member

fafhrd91 commented Jun 7, 2014

Yes, I think assert is enough. add_header already expects value as a string object in any case

@asvetlov asvetlov mentioned this issue Jun 7, 2014
@asvetlov
Copy link
Member

asvetlov commented Jun 7, 2014

Done in #68

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants