-
-
Notifications
You must be signed in to change notification settings - Fork 369
Fix native HTTP server compatibility #1712
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 native HTTP server compatibility #1712
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cherrypy/_cpnative_server.py
Outdated
@@ -7,6 +7,7 @@ | |||
import cheroot.server | |||
|
|||
import cherrypy | |||
from cherrypy._cpcompat import tonative |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I consider tonative
to be deprecated. I'd like to avoid using it if possible and instead use either text or bytes explicitly on all Pythons.
4c6b8ff
to
03d13a1
Compare
Codecov Report
@@ Coverage Diff @@
## master #1712 +/- ##
==========================================
+ Coverage 80.35% 80.81% +0.45%
==========================================
Files 104 105 +1
Lines 13546 13563 +17
==========================================
+ Hits 10885 10961 +76
+ Misses 2661 2602 -59 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've stripped out the commit that seems to be unnecessary, including the one that fixes the reported issue. I believe this PR is ready to go.
@jaraco did it cause AppVeyor failures? |
@@ -95,7 +95,7 @@ def send_response(self, status, headers, body): | |||
req = self.req | |||
|
|||
# Set response status | |||
req.status = str(status or '500 Server Error') | |||
req.status = status or b'500 Server Error' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaraco there's or ''
over the place defaulting to bytes/unicode all over the place. Shall we try from __future__ import unicode_strings
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd very much like to do that. It was a feature that wasn't available in the early implementations (Python 2.3 compatibility and all), and even some people still advise against its use. It's my opinion, however, that using from __future__ import unicode_literals
is the best way to achieve compatibility. Let's do it as time permits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern is that from code it's not always obvious what kind of data the variable is expected to hold. Should we introduce some convention of prefixing b_
or suffixing _b
to improve the situation?
cherrypy/test/test_native.py
Outdated
@@ -0,0 +1,29 @@ | |||
"""Docstring.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaraco I guess we could explain what's going on in this test suite here.
I do see appveyor failures; the failures seem unrelated, though I can't tell for sure. Is the startup/teardown of the native server causing conflicts with other tests? |
I have no idea about the conflicts, but there's clearly some race conditions involved. |
return sessions.BaseUrlSession(url) | ||
|
||
|
||
def test_basic_request(cp_native_server): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaraco it looks like this test doesn't catch the bug for some reason.
Ref:
What kind of change does this PR introduce?
What is the related issue number (starting with
#
)disabling wsgi interface fails under python3 #1377
What is the current behavior? (You can also link to an open issue here)
Various exceptions related to str/bytes py2/3 compat are being raised.
What is the new behavior (if this is a feature change)?
Will be working
Other information:
Still WIP, don't merge.
I hope to get some help from @jaraco.
Checklist:
and description in grammatically correct, complete sentences