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

Changeset 1210

Show
Ignore:
Timestamp:
08/03/06 00:12:54
Author:
fumanchu
Message:

Fixes for #544 and #545 (serveFile issues) for CP 2 branch.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cherrypy-2.x/cherrypy/_cperror.py

    r972 r1210  
    126126            # The "Date" header should have been set in Request.__init__ 
    127127             
     128            # "...the response SHOULD NOT include other entity-headers. 
     129            for key in ('Allow', 'Content-Encoding', 'Content-Language', 
     130                        'Content-Length', 'Content-Location', 'Content-MD5', 
     131                        'Content-Range', 'Content-Type', 'Expires', 
     132                        'Last-Modified'): 
     133                if key in response.headers: 
     134                    del response.headers[key] 
     135             
    128136            # "The 304 response MUST NOT contain a message-body." 
    129137            response.body = None 
  • branches/cherrypy-2.x/cherrypy/_cphttptools.py

    r1042 r1210  
    401401            # Responses which are not streamed should have a Content-Length, 
    402402            # but allow user code to set Content-Length if desired. 
    403             if self.headers.get('Content-Length') is None: 
     403            if (self.headers.get('Content-Length') is None 
     404                and code not in (304,)): 
    404405                content = self.collapse_body() 
    405406                self.headers['Content-Length'] = len(content) 
  • branches/cherrypy-2.x/cherrypy/lib/cptools.py

    r1008 r1210  
    8484    if cherrypy.request.headers.has_key('If-Modified-Since'): 
    8585        if cherrypy.request.headers['If-Modified-Since'] == strModifTime: 
    86             response.status = "304 Not Modified" 
    87             response.body = None 
    88             if getattr(cherrypy, "debug", None): 
    89                 cherrypy.log("    Found file (304 Not Modified): %s" % path, "DEBUG") 
    90             return False 
     86            raise cherrypy.HTTPRedirect([], 304) 
    9187    response.headers['Last-Modified'] = strModifTime 
    9288    return True 
     
    140136        if name is None: 
    141137            name = os.path.basename(path) 
    142         cd = "%s; filename=%s" % (disposition, name) 
     138        cd = '%s; filename="%s"' % (disposition, name) 
    143139        response.headers["Content-Disposition"] = cd 
    144140     
  • branches/cherrypy-2.x/cherrypy/test/test_static_filter.py

    r1034 r1210  
    128128        ims = ("If-Modified-Since", lastmod) 
    129129        self.getPage("/static/dirback.jpg", headers=[ims]) 
    130         self.assertStatus("304 Not Modified") 
     130        self.assertStatus(304) 
     131        self.assertNoHeader("Content-Type") 
     132        self.assertNoHeader("Content-Length") 
     133        self.assertNoHeader("Content-Disposition") 
     134        self.assertBody("") 
     135         
    131136##         
    132137##        # Test lots of requests for the same file (no If-Mod). 
  • branches/cherrypy-2.x/cherrypy/test/test_tutorials.py

    r1022 r1210  
    160160        self.assertStatus("200 OK") 
    161161        self.assertHeader("Content-Type", "application/x-download") 
    162         self.assertHeader("Content-Disposition", "attachment; filename=pdf_file.pdf") 
     162        self.assertHeader("Content-Disposition", 
     163                          # Make sure the filename is quoted. 
     164                          'attachment; filename="pdf_file.pdf"') 
    163165        self.assertEqual(len(self.body), 85698) 
    164166     
  • branches/cherrypy-2.x/cherrypy/tutorial/tut09_files.py

    r956 r1210  
    3232Set "name" to the filename that you expect clients to use when they save 
    3333your file. Note that the "name" argument is ignored if you don't also 
    34 provide a "disposition" (usually "attachement"). You can manually set 
     34provide a "disposition" (usually "attachment"). You can manually set 
    3535"contentType", but be aware that if you also use the EncodingFilter, it 
    3636may choke if the file extension is not recognized as belonging to a known 

Hosted by WebFaction

Log in as guest/cpguest to create tickets