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

Changeset 482

Show
Ignore:
Timestamp:
07/18/05 14:21:42
Author:
fumanchu
Message:

Whew. All tests now pass for all servers in both 1.0 and 1.1 modes. There's also a new assertNoHeader method for webtest.

Files:

Legend:

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

    r481 r482  
    101101            # must add a "Connection: close" header to tell the client that 
    102102            # 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. 
    103117            wfile.write("Connection: close\r\n") 
    104118         
  • trunk/cherrypy/_cpwsgi.py

    r406 r482  
    116116        tb = _cputil.formatExc() 
    117117        cherrypy.log(tb) 
    118         s, h, b = _cphttptools.bareError(tb
     118        s, h, b = _cphttptools.bareError(
    119119        # CherryPy test suite expects bareError body to be output, 
    120120        # so don't call start_response (which, according to PEP 333, 
  • trunk/cherrypy/_cpwsgiserver.py

    r475 r482  
    126126        if "server" not in self.outheaderkeys: 
    127127            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")) 
    128131        self.wfile.write(self.environ["SERVER_PROTOCOL"] + " " + self.status + "\r\n") 
    129132        for (k,v) in self.outheaders: 
  • trunk/cherrypy/test/helper.py

    r480 r482  
    9797        self.status = cherrypy.response.status 
    9898        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         
    100116        if webtest.ServerError.on: 
    101117            raise webtest.ServerError 
  • trunk/cherrypy/test/test_core.py

    r474 r482  
    349349        helper.webtest.ignored_exceptions.append(ValueError) 
    350350        try: 
    351             valerr = '\n    raise ValueError\nValueError\n
     351            valerr = r'\n    raise ValueError\nValueError\n$
    352352            self.getPage("/error/page_method") 
    353             self.assert_(self.body.endswith(valerr)
     353            self.assertMatchesBody(valerr
    354354             
     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.$' 
    355359            self.getPage("/error/page_yield") 
    356             self.assert_(self.body.endswith(valerr)
     360            self.assertMatchesBody(valerr
    357361             
    358             if cherrypy._httpserver is None
     362            if cherrypy._httpserver is None and proto == "HTTP/1.0"
    359363                self.assertRaises(ValueError, self.getPage, "/error/page_http_1_1") 
    360364            else: 
     
    368372     
    369373    def testHeaderCaseSensitivity(self): 
     374        """Tests that each header only appears once, regardless of case.""" 
    370375        self.getPage("/headers/") 
    371376        self.assertBody("double header test") 
    372377        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
    376381     
    377382    def testHTTPMethods(self): 
  • trunk/cherrypy/test/test_gzip_filter.py

    r474 r482  
    7171        try: 
    7272            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$") 
    7586        finally: 
    7687            helper.webtest.ignored_exceptions.pop() 
  • trunk/cherrypy/test/test_static_filter.py

    r474 r482  
    6464        #   into \r\n on Windows when extracting the CherryPy tarball so 
    6565        #   we just check the content 
    66         self.assert_(self.body.startswith('Dummy stylesheet')
     66        self.assertMatchesBody('^Dummy stylesheet'
    6767 
    6868if __name__ == "__main__": 
  • trunk/cherrypy/test/webtest.py

    r477 r482  
    244244        self.handleWebError(msg) 
    245245     
     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     
    246255    def assertBody(self, value, msg=None): 
    247256        """Fail if value != self.body.""" 

Hosted by WebFaction

Log in as guest/cpguest to create tickets