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

Changeset 1538

Show
Ignore:
Timestamp:
12/20/06 16:37:49
Author:
fumanchu
Message:

Fix for chunked responses when write is called directly by the WSGI app. Also a fix for leading CRLF in request.

Files:

Legend:

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

    r1537 r1538  
    107107        # (although your TCP stack might suffer for it: cf Apache's history 
    108108        # with FIN_WAIT_2). 
    109         request_line = self.rfile.readline() 
    110         if not request_line: 
    111             # Force self.ready = False so the connection will close. 
    112             self.ready = False 
    113             return 
     109        while True: 
     110            request_line = self.rfile.readline() 
     111            if not request_line: 
     112                # Force self.ready = False so the connection will close. 
     113                self.ready = False 
     114                return 
     115            elif request_line == "\r\n": 
     116                # "...if the server is reading the protocol stream at the 
     117                # beginning of a message and receives a CRLF first, it 
     118                # should ignore the CRLF." RFC 2616 sec 4.1 
     119                pass 
     120            else: 
     121                break 
    114122         
    115123        server = self.connection.server 
     
    316324        try: 
    317325            for chunk in response: 
    318                 if not self.sent_headers: 
    319                     self.sent_headers = True 
    320                     self.send_headers() 
    321                 if self.chunked_write: 
    322                     wfile.write(hex(len(chunk))[2:]) 
    323                     wfile.write("\r\n") 
    324                     wfile.write(chunk) 
    325                     wfile.write("\r\n") 
    326                 else: 
    327                     wfile.write(chunk) 
    328                 wfile.flush() 
     326                self.write(chunk) 
    329327        finally: 
    330328            if hasattr(response, "close"): 
     
    369367        return self.write 
    370368     
    371     def write(self, d): 
     369    def write(self, chunk): 
    372370        if not self.sent_headers: 
    373371            self.sent_headers = True 
    374372            self.send_headers() 
    375         self.connection.wfile.write(d) 
    376         self.connection.wfile.flush() 
     373        wfile = self.connection.wfile 
     374        if self.chunked_write: 
     375            wfile.write(hex(len(chunk))[2:]) 
     376            wfile.write("\r\n") 
     377            wfile.write(chunk) 
     378            wfile.write("\r\n") 
     379        else: 
     380            wfile.write(chunk) 
     381        wfile.flush() 
    377382     
    378383    def send_headers(self): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets