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

Changeset 1318

Show
Ignore:
Timestamp:
09/02/06 13:35:24
Author:
fumanchu
Message:

Fix to 2.1, 2.2, 3.0 for bugs in Range slicing and final boundary. Also made the output match Apache output (CRLFs).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cherrypy-2.1/cherrypy/lib/cptools.py

    r731 r1318  
    312312                               % (start, stop - 1, c_len)) 
    313313                        bodyfile.seek(start) 
    314                         yield bodyfile.read((stop + 1) - start) 
     314                        yield bodyfile.read(stop - start) 
    315315                        yield "\n" 
    316316                    # Final boundary 
    317                     yield "--" + boundary 
     317                    yield "--" + boundary + "--" 
    318318                response.body = fileRanges() 
    319319        else: 
  • branches/cherrypy-2.1/cherrypy/test/test_core.py

    r718 r1318  
    582582Content-range: bytes 4-6/14 
    583583 
    584 o, w 
     584o,  
    585585--%s 
    586586Content-type: text/html 
  • branches/cherrypy-2.x/cherrypy/lib/cptools.py

    r1210 r1318  
    174174                 
    175175                def fileRanges(): 
     176                    # Apache compatibility: 
     177                    yield "\r\n" 
     178                     
    176179                    for start, stop in r: 
    177180                        yield "--" + boundary 
    178                         yield "\nContent-type: %s" % contentType 
    179                         yield ("\nContent-range: bytes %s-%s/%s\n\n" 
     181                        yield "\r\nContent-type: %s" % contentType 
     182                        yield ("\r\nContent-range: bytes %s-%s/%s\r\n\r\n" 
    180183                               % (start, stop - 1, c_len)) 
    181184                        bodyfile.seek(start) 
    182                         yield bodyfile.read((stop + 1) - start) 
    183                         yield "\n" 
     185                        yield bodyfile.read(stop - start) 
     186                        yield "\r\n" 
    184187                    # Final boundary 
    185                     yield "--" + boundary 
     188                    yield "--" + boundary + "--" 
     189                     
     190                    # Apache compatibility: 
     191                    yield "\r\n" 
    186192                response.body = fileRanges() 
    187193        else: 
  • branches/cherrypy-2.x/cherrypy/test/test_core.py

    r1033 r1318  
    220220    class Ranges(Test): 
    221221         
    222         def get_ranges(self): 
    223             h = cherrypy.request.headers.get('Range') 
    224             return repr(httptools.getRanges(h, 8)) 
     222        def get_ranges(self, bytes): 
     223            return repr(httptools.getRanges('bytes=%s' % bytes, 8)) 
    225224         
    226225        def slice_file(self): 
     
    640639     
    641640    def testRanges(self): 
    642         self.getPage("/ranges/get_ranges", [('Range', 'bytes=3-6')]
     641        self.getPage("/ranges/get_ranges?bytes=3-6"
    643642        self.assertBody("[(3, 7)]") 
    644643         
    645644        # Test multiple ranges and a suffix-byte-range-spec, for good measure. 
    646         self.getPage("/ranges/get_ranges", [('Range', 'bytes=2-4,-1')]
     645        self.getPage("/ranges/get_ranges?bytes=2-4,-1"
    647646        self.assertBody("[(2, 5), (7, 8)]") 
    648647         
     
    665664        self.assert_(ct.startswith(expected_type)) 
    666665        boundary = ct[len(expected_type):] 
    667         expected_body = """--%s 
    668 Content-type: text/html 
    669 Content-range: bytes 4-6/14 
    670  
    671 o, w 
    672 --%s 
    673 Content-type: text/html 
    674 Content-range: bytes 2-5/14 
    675  
    676 llo,  
    677 --%s""" % (boundary, boundary, boundary
     666        expected_body = ("\r\n--%s\r\n" 
     667                         "Content-type: text/html\r\n" 
     668                         "Content-range: bytes 4-6/14\r\n" 
     669                         "\r\n" 
     670                         "o, \r\n" 
     671                         "--%s\r\n" 
     672                         "Content-type: text/html\r\n" 
     673                         "Content-range: bytes 2-5/14\r\n" 
     674                         "\r\n" 
     675                         "llo,\r\n" 
     676                         "--%s--\r\n" % (boundary, boundary, boundary)
    678677        self.assertBody(expected_body) 
    679678        self.assertHeader("Content-Length") 
  • trunk/cherrypy/lib/static.py

    r1281 r1318  
    9898                 
    9999                def file_ranges(): 
     100                    # Apache compatibility: 
     101                    yield "\r\n" 
     102                     
    100103                    for start, stop in r: 
    101104                        yield "--" + boundary 
    102                         yield "\nContent-type: %s" % content_type 
    103                         yield ("\nContent-range: bytes %s-%s/%s\n\n" 
     105                        yield "\r\nContent-type: %s" % content_type 
     106                        yield ("\r\nContent-range: bytes %s-%s/%s\r\n\r\n" 
    104107                               % (start, stop - 1, c_len)) 
    105108                        bodyfile.seek(start) 
    106                         yield bodyfile.read((stop + 1) - start) 
    107                         yield "\n" 
     109                        yield bodyfile.read(stop - start) 
     110                        yield "\r\n" 
    108111                    # Final boundary 
    109                     yield "--" + boundary 
     112                    yield "--" + boundary + "--" 
     113                     
     114                    # Apache compatibility: 
     115                    yield "\r\n" 
    110116                response.body = file_ranges() 
    111117        else: 
  • trunk/cherrypy/test/test_core.py

    r1311 r1318  
    239239    class Ranges(Test): 
    240240         
    241         def get_ranges(self): 
    242             h = cherrypy.request.headers.get('Range') 
    243             return repr(http.get_ranges(h, 8)) 
     241        def get_ranges(self, bytes): 
     242            return repr(http.get_ranges('bytes=%s' % bytes, 8)) 
    244243         
    245244        def slice_file(self): 
     
    642641     
    643642    def testRanges(self): 
    644         self.getPage("/ranges/get_ranges", [('Range', 'bytes=3-6')]
     643        self.getPage("/ranges/get_ranges?bytes=3-6"
    645644        self.assertBody("[(3, 7)]") 
    646645         
    647646        # Test multiple ranges and a suffix-byte-range-spec, for good measure. 
    648         self.getPage("/ranges/get_ranges", [('Range', 'bytes=2-4,-1')]
     647        self.getPage("/ranges/get_ranges?bytes=2-4,-1"
    649648        self.assertBody("[(2, 5), (7, 8)]") 
    650649         
     
    660659            self.getPage("/ranges/slice_file", [('Range', 'bytes=4-6,2-5')]) 
    661660            self.assertStatus(206) 
    662             ct = "" 
    663             for k, v in self.headers: 
    664                 if k.lower() == "content-type": 
    665                     ct = v 
    666                     break 
     661            ct = self.assertHeader("Content-Type") 
    667662            expected_type = "multipart/byteranges; boundary=" 
    668663            self.assert_(ct.startswith(expected_type)) 
    669664            boundary = ct[len(expected_type):] 
    670             expected_body = """--%s 
    671 Content-type: text/html 
    672 Content-range: bytes 4-6/14 
    673  
    674 o, w 
    675 --%s 
    676 Content-type: text/html 
    677 Content-range: bytes 2-5/14 
    678  
    679 llo,  
    680 --%s""" % (boundary, boundary, boundary
     665            expected_body = ("\r\n--%s\r\n" 
     666                             "Content-type: text/html\r\n" 
     667                             "Content-range: bytes 4-6/14\r\n" 
     668                             "\r\n" 
     669                             "o, \r\n" 
     670                             "--%s\r\n" 
     671                             "Content-type: text/html\r\n" 
     672                             "Content-range: bytes 2-5/14\r\n" 
     673                             "\r\n" 
     674                             "llo,\r\n" 
     675                             "--%s--\r\n" % (boundary, boundary, boundary)
    681676            self.assertBody(expected_body) 
    682677            self.assertHeader("Content-Length") 
     
    685680            self.getPage("/ranges/slice_file", [('Range', 'bytes=2300-2900')]) 
    686681            self.assertStatus(416) 
     682            # "When this status code is returned for a byte-range request, 
     683            # the response SHOULD include a Content-Range entity-header 
     684            # field specifying the current length of the selected resource" 
    687685            self.assertHeader("Content-Range", "bytes */14") 
    688686        elif cherrypy.server.protocol_version == "HTTP/1.0": 

Hosted by WebFaction

Log in as guest/cpguest to create tickets