Changeset 1406
- Timestamp:
- 10/21/06 22:36:38
- Files:
-
- trunk/cherrypy/_cprequest.py (modified) (1 diff)
- trunk/cherrypy/_cpwsgiserver.py (modified) (1 diff)
- trunk/cherrypy/test/test_conn.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cprequest.py
r1400 r1406 607 607 if self.stream: 608 608 headers.pop('Content-Length', None) 609 elif code < 200 or code in (204, 304): 610 # "All 1xx (informational), 204 (no content), 611 # and 304 (not modified) responses MUST NOT 612 # include a message-body." 613 headers.pop('Content-Length', None) 614 self.body = "" 609 615 else: 610 616 # Responses which are not streamed should have a Content-Length, 611 617 # but allow user code to set Content-Length if desired. 612 if (dict.get(headers, 'Content-Length') is None 613 and code not in (304,)): 618 if dict.get(headers, 'Content-Length') is None: 614 619 content = self.collapse_body() 615 620 dict.__setitem__(headers, 'Content-Length', len(content)) trunk/cherrypy/_cpwsgiserver.py
r1388 r1406 320 320 hkeys = [key.lower() for (key,value) in self.outheaders] 321 321 322 status = int(self.status[:3]) 322 323 if (self.response_protocol == 'HTTP/1.1' 323 324 and (# Request Entity Too Large. Close conn to avoid garbage. 324 s elf.status[:3] == "413"325 status == 413 325 326 # No Content-Length. Close conn to determine transfer-length. 326 or "content-length" not in hkeys)): 327 or ("content-length" not in hkeys and 328 # "All 1xx (informational), 204 (no content), 329 # and 304 (not modified) responses MUST NOT 330 # include a message-body." 331 status >= 200 and status not in (204, 304)))): 327 332 if "connection" not in hkeys: 328 333 self.outheaders.append(("Connection", "close")) trunk/cherrypy/test/test_conn.py
r1367 r1406 38 38 cherrypy.request.headers['Content-Type'])) 39 39 upload.exposed = True 40 41 def custom(self, response_code): 42 cherrypy.response.status = response_code 43 return "Code = %s" % response_code 44 custom.exposed = True 40 45 41 46 cherrypy.tree.mount(Root()) … … 292 297 self.assertBody("thanks for 'I am a small file' (text/plain)") 293 298 299 def test_No_Message_Body(self): 300 if cherrypy.server.protocol_version != "HTTP/1.1": 301 print "skipped ", 302 return 303 304 self.PROTOCOL = "HTTP/1.1" 305 306 # Set our HTTP_CONN to an instance so it persists between requests. 307 if self.scheme == "https": 308 self.HTTP_CONN = httplib.HTTPSConnection(self.HOST, self.PORT) 309 else: 310 self.HTTP_CONN = httplib.HTTPConnection(self.HOST, self.PORT) 311 # Don't automatically re-connect 312 self.HTTP_CONN.auto_open = False 313 self.HTTP_CONN.connect() 314 315 # Make the first request and assert there's no "Connection: close". 316 self.getPage("/") 317 self.assertStatus('200 OK') 318 self.assertBody(pov) 319 self.assertNoHeader("Connection") 320 321 # Make a 204 request on the same connection. 322 self.getPage("/custom/204") 323 self.assertStatus(204) 324 self.assertNoHeader("Content-Length") 325 self.assertBody("") 326 self.assertNoHeader("Connection") 327 328 # Make a 304 request on the same connection. 329 self.getPage("/custom/304") 330 self.assertStatus(304) 331 self.assertNoHeader("Content-Length") 332 self.assertBody("") 333 self.assertNoHeader("Connection") 334 294 335 def test_Chunked_Encoding(self): 295 336 if cherrypy.server.protocol_version != "HTTP/1.1":

