Changeset 482
- Timestamp:
- 07/18/05 14:21:42
- Files:
-
- trunk/cherrypy/_cphttpserver.py (modified) (1 diff)
- trunk/cherrypy/_cpwsgi.py (modified) (1 diff)
- trunk/cherrypy/_cpwsgiserver.py (modified) (1 diff)
- trunk/cherrypy/test/helper.py (modified) (1 diff)
- trunk/cherrypy/test/test_core.py (modified) (2 diffs)
- trunk/cherrypy/test/test_gzip_filter.py (modified) (1 diff)
- trunk/cherrypy/test/test_static_filter.py (modified) (1 diff)
- trunk/cherrypy/test/webtest.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cphttpserver.py
r481 r482 101 101 # must add a "Connection: close" header to tell the client that 102 102 # we will close the connection when we're done sending output. 103 # 104 # From RFC 2616 sec 14.10: 105 # HTTP/1.1 defines the "close" connection option for the sender 106 # to signal that the connection will be closed after completion 107 # of the response. For example, 108 # 109 # Connection: close 110 # 111 # in either the request or the response header fields indicates 112 # that the connection SHOULD NOT be considered `persistent' 113 # (section 8.1) after the current request/response is complete. 114 # 115 # HTTP/1.1 applications that do not support persistent connections 116 # MUST include the "close" connection option in every message. 103 117 wfile.write("Connection: close\r\n") 104 118 trunk/cherrypy/_cpwsgi.py
r406 r482 116 116 tb = _cputil.formatExc() 117 117 cherrypy.log(tb) 118 s, h, b = _cphttptools.bareError( tb)118 s, h, b = _cphttptools.bareError() 119 119 # CherryPy test suite expects bareError body to be output, 120 120 # so don't call start_response (which, according to PEP 333, trunk/cherrypy/_cpwsgiserver.py
r475 r482 126 126 if "server" not in self.outheaderkeys: 127 127 self.outheaders.append(("Server", self.server.version)) 128 if (self.environ["SERVER_PROTOCOL"] == "HTTP/1.1" 129 and "connection" not in self.outheaderkeys): 130 self.outheaders.append(("Connection", "close")) 128 131 self.wfile.write(self.environ["SERVER_PROTOCOL"] + " " + self.status + "\r\n") 129 132 for (k,v) in self.outheaders: trunk/cherrypy/test/helper.py
r480 r482 97 97 self.status = cherrypy.response.status 98 98 self.headers = cherrypy.response.headers 99 self.body = "".join([chunk for chunk in cherrypy.response.body]) 99 try: 100 self.body = [] 101 for chunk in cherrypy.response.body: 102 self.body.append(chunk) 103 except: 104 if cherrypy.config.get("server.protocolVersion") == "HTTP/1.0": 105 # Pass the error through 106 raise 107 108 from cherrypy import _cphttptools 109 s, h, b = _cphttptools.bareError() 110 # Don't reset status or headers; we're emulating an error which 111 # occurs after status and headers have been written to the client. 112 for chunk in b: 113 self.body.append(chunk) 114 self.body = "".join(self.body) 115 100 116 if webtest.ServerError.on: 101 117 raise webtest.ServerError trunk/cherrypy/test/test_core.py
r474 r482 349 349 helper.webtest.ignored_exceptions.append(ValueError) 350 350 try: 351 valerr = '\n raise ValueError\nValueError\n'351 valerr = r'\n raise ValueError\nValueError\n$' 352 352 self.getPage("/error/page_method") 353 self.assert _(self.body.endswith(valerr))353 self.assertMatchesBody(valerr) 354 354 355 import cherrypy 356 proto = cherrypy.config.get("server.protocolVersion", "HTTP/1.0") 357 if proto == "HTTP/1.1": 358 valerr = r'Unrecoverable error in the server.$' 355 359 self.getPage("/error/page_yield") 356 self.assert _(self.body.endswith(valerr))360 self.assertMatchesBody(valerr) 357 361 358 if cherrypy._httpserver is None :362 if cherrypy._httpserver is None and proto == "HTTP/1.0": 359 363 self.assertRaises(ValueError, self.getPage, "/error/page_http_1_1") 360 364 else: … … 368 372 369 373 def testHeaderCaseSensitivity(self): 374 """Tests that each header only appears once, regardless of case.""" 370 375 self.getPage("/headers/") 371 376 self.assertBody("double header test") 372 377 hnames = [name.title() for name, val in self.headers] 373 hnames.sort()374 self.assertEqual(hnames, ['Content-Length', 'Content-Type', 'Date', 'Expires',375 'Location', 'Server'])378 for key in ['Content-Length', 'Content-Type', 'Date', 379 'Expires', 'Location', 'Server']: 380 self.assertEqual(hnames.count(key), 1) 376 381 377 382 def testHTTPMethods(self): trunk/cherrypy/test/test_gzip_filter.py
r474 r482 71 71 try: 72 72 self.getPage('/noshow', headers=[("Accept-Encoding", "gzip")]) 73 self.assert_('Content-Encoding' not in dict(self.headers)) 74 self.assert_(self.body.endswith("IndexError\n")) 73 74 import cherrypy 75 proto = cherrypy.config.get("server.protocolVersion", "HTTP/1.0") 76 if proto == "HTTP/1.1": 77 # In this case, there's nothing we can do to deliver a 78 # readable page, since 1) the gzip header is already set, 79 # and 2) we may have already written some of the body. 80 # The fix is to not use yield when using HTTP/1.1 and gzip. 81 self.assertHeader('Content-Encoding', 'gzip') 82 self.assertMatchesBody(r"Unrecoverable error in the server.$") 83 else: 84 self.assertNoHeader('Content-Encoding') 85 self.assertMatchesBody(r"IndexError\n$") 75 86 finally: 76 87 helper.webtest.ignored_exceptions.pop() trunk/cherrypy/test/test_static_filter.py
r474 r482 64 64 # into \r\n on Windows when extracting the CherryPy tarball so 65 65 # we just check the content 66 self.assert _(self.body.startswith('Dummy stylesheet'))66 self.assertMatchesBody('^Dummy stylesheet') 67 67 68 68 if __name__ == "__main__": trunk/cherrypy/test/webtest.py
r477 r482 244 244 self.handleWebError(msg) 245 245 246 def assertNoHeader(self, key, msg=None): 247 """Fail if key in self.headers.""" 248 lowkey = key.lower() 249 matches = [k for k, v in self.headers if k.lower() == lowkey] 250 if matches: 251 if msg is None: 252 msg = '%s in headers' % `key` 253 self.handleWebError(msg) 254 246 255 def assertBody(self, value, msg=None): 247 256 """Fail if value != self.body."""

