Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1279

Show
Ignore:
Timestamp:
08/25/06 19:35:38
Author:
fumanchu
Message:

Fix for the fix for #551 (basically, die on timeout instead of responding with 408).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cpwsgiserver.py

    r1273 r1279  
    5555     
    5656    def parse_request(self): 
    57         request_line = None 
    58         try: 
    59             request_line = self.rfile.readline() 
    60         except socket.timeout: 
    61             self.simple_response("408 Request Timeout") 
    62             return 
    63          
     57        # HTTP/1.1 connections are persistent by default. If a client 
     58        # requests a page, then idles (leaves the connection open), 
     59        # then rfile.readline() will raise socket.error("timed out"). 
     60        # Note that it does this based on the value given to settimeout(), 
     61        # and doesn't need the client to request or acknowledge the close 
     62        # (although your TCP stack might suffer for it: cf Apache's history 
     63        # with FIN_WAIT_2). 
     64        request_line = self.rfile.readline() 
    6465        if not request_line: 
     66            # Force self.ready = False so the connection will close. 
     67            self.ready = False 
    6568            return 
    6669         
  • trunk/cherrypy/test/test_conn.py

    r1278 r1279  
    44import httplib 
    55import socket 
     6import time 
    67 
    78import cherrypy 
     
    103104        self.assertRaises(httplib.NotConnected, self.getPage, "/") 
    104105     
     106    def test_HTTP11_Timeout(self): 
     107        if cherrypy.server.protocol_version != "HTTP/1.1": 
     108            print "skipped ", 
     109            return 
     110         
     111        old_timeout = None 
     112        try: 
     113            httpserver = cherrypy.server.httpservers.keys()[0] 
     114            old_timeout = httpserver.timeout 
     115        except AttributeError: 
     116            print "skipped ", 
     117            return 
     118         
     119        try: 
     120            httpserver.timeout = 0.1 
     121            self.PROTOCOL = "HTTP/1.1" 
     122             
     123            # Make an initial request 
     124            conn = httplib.HTTPConnection(self.HOST, self.PORT) 
     125            conn.auto_open = False 
     126            conn.connect() 
     127            conn.putrequest("GET", "/", skip_host=True) 
     128            conn.putheader("Host", self.HOST) 
     129            conn.endheaders() 
     130            response = conn.response_class(conn.sock, method="GET") 
     131            response.begin() 
     132            self.assertEqual(response.status, 200) 
     133             
     134            # Make a second request on the same socket 
     135            conn._output('GET /hello HTTP/1.1') 
     136            conn._output("Host: %s" % self.HOST) 
     137            conn._send_output() 
     138            response = conn.response_class(conn.sock, method="GET") 
     139            response.begin() 
     140            self.assertEqual(response.status, 200) 
     141             
     142            # Wait for our socket timeout 
     143            time.sleep(0.2) 
     144             
     145            # Make another request on the same socket, which should error 
     146            conn._output('GET /hello HTTP/1.1') 
     147            conn._output("Host: %s" % self.HOST) 
     148            conn._send_output() 
     149            response = conn.response_class(conn.sock, method="GET") 
     150            self.assertRaises(socket.error, response.begin) 
     151             
     152            conn.close() 
     153        finally: 
     154            if old_timeout is not None: 
     155                httpserver.timeout = old_timeout 
     156     
    105157    def test_HTTP11_pipelining(self): 
    106158        if cherrypy.server.protocol_version != "HTTP/1.1": 

Hosted by WebFaction

Log in as guest/cpguest to create tickets