CherryPy is a pythonic, object-oriented HTTP framework. | post your issues to: github.com/cherrypy/cherrypy/issues | FAQ: https://stackoverflow.com/questions/tagged/cheroot+or+cherrypy
jaraco on master
Mark test_HTTP11_Timeout_after_… Fix test_HTTP11_Timeout_after_r… Consolidate error message templ… and 2 more (compare)
jaraco on 17.x
Fix test_HTTP11_Timeout_after_r… Consolidate error message templ… Remove xfail after cherry-picki… (compare)
jaraco on 17.x
Mark test_HTTP11_Timeout_after_… (compare)
jaraco on v18.5.0
jaraco on v18.4.0.post.centos8.p1
import tempfile
import cherrypy
from cheroot import server
response = tempfile.SpooledTemporaryFile(max_size = 1000, mode = "w+b")
response.write(b'Status: 302 Found\r\nLocation: index.php?\r\nContent-type: text/html; charset=UTF-8\r\n\r\n')
emptydict ={}
response.seek(0)
hr = server.HeaderReader()
headers = hr(response,cherrypy.serving.response.headers)
print(headers)
print(80*'-')
response.seek(0)
headers = hr(response,emptydict)
print(headers)
print(80*'-')
otherdict ={ 'Content-Type':'text/html'}
response.seek(0)
headers = hr(response,otherdict)
print(headers)
{'Content-Type': 'text/html', 'Server': 'CherryPy/18.4.0', 'Date': 'Sat, 23 Nov 2019 20:10:51 GMT', "B'Status'": b'302 Found', "B'Location'": b'index.php?', "B'Content-Type'": b'text/html; charset=UTF-8'}
--------------------------------------------------------------------------------
{b'Status': b'302 Found', b'Location': b'index.php?', b'Content-Type': b'text/html; charset=UTF-8'}
--------------------------------------------------------------------------------
{'Content-Type': 'text/html', b'Status': b'302 Found', b'Location': b'index.php?', b'Content-Type': b'text/html; charset=UTF-8'}
"B'Status'": b'302 Found'
does not look right ...
cherrypy.serving.response.headers
is from cherrypy.lib.httputil.HeaderMap()
@staticmethod
def transform_key(key):
return str(key).title()
This will cause a bytes object like b'status'
to result in "B'Status'"
which I would think is wrong. At this place I think it must be decided to first transform the bytes into a string using encoding and not using simply str()
@bmxp thanks for opening an issue! It seems like you feel unqualified or somehow afraid to contribute PRs but you're still very welcome to try :) Even if your contribution isn't accepted as is, it's still very useful for everyone because it's a good demo.
What I meant earlier is adding a failing test to the project and marking it as "expected to fail" (@pytest.mark.xfail
). This way, we'd have some tests that wouldn't crash our CI but also would be a great starting point for somebody else to fix the issue in the future. I'll show you how it'd look in a bit.
HeaderMap
, not HeaderReader
. Let me check it closer
cherrypy.serving.response.headers
?
-otherdict = {'Content-Type': 'text/html'}
+otherdict = {b'Content-Type': b'text/html'}