#NEWLINE# def test_file_stream( self ) : #NEWLINE# #INDENT# if ( cherrypy . server . protocol_version != 'HTTP/1.1' ) : #NEWLINE# #INDENT# return self . skip ( ) #NEWLINE# #UNINDENT# self . PROTOCOL = 'HTTP/1.1' #NEWLINE# self . persistent = True #NEWLINE# conn = self . HTTP_CONN #NEWLINE# conn . putrequest ( 'GET' , '/bigfile' , skip_host = True ) #NEWLINE# conn . putheader ( 'Host' , self . HOST ) #NEWLINE# conn . endheaders ( ) #NEWLINE# response = conn . response_class ( conn . sock , method = 'GET' ) #NEWLINE# response . begin ( ) #NEWLINE# self . assertEqual ( response . status , 200 ) #NEWLINE# body = ntob ( '' ) #NEWLINE# remaining = BIGFILE_SIZE #NEWLINE# while ( remaining > 0 ) : #NEWLINE# #INDENT# data = response . fp . read ( 65536 ) #NEWLINE# if ( not data ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# body += data #NEWLINE# remaining -= len ( data ) #NEWLINE# if ( self . scheme == 'https' ) : #NEWLINE# #INDENT# newconn = HTTPSConnection #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# newconn = HTTPConnection #NEWLINE# #UNINDENT# ( s , h , b ) = helper . webtest . openURL ( ntob ( '/tell' ) , headers = [ ] , host = self . HOST , port = self . PORT , http_conn = b ) #NEWLINE# if ( not b ) : #NEWLINE# #INDENT# tell_position = BIGFILE_SIZE #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tell_position = int ( b ) #NEWLINE# #UNINDENT# expected = len ( body ) #NEWLINE# if ( tell_position >= BIGFILE_SIZE ) : #NEWLINE# #INDENT# if ( expected < ( BIGFILE_SIZE / 2 ) ) : #NEWLINE# #INDENT# self . fail ( ( 'The file should have advanced to position %r, but has already advanced to the end of the file. It may not be streamed as intended, or at the wrong chunk size (64k)' % expected ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( tell_position < expected ) : #NEWLINE# #INDENT# self . fail ( ( 'The file should have advanced to position %r, but has only advanced to position %r. It may not be streamed as intended, or at the wrong chunk size (65536)' % ( expected , tell_position ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( body != ntob ( ( 'x' * BIGFILE_SIZE ) ) ) : #NEWLINE# #INDENT# self . fail ( ( "Body != 'x' * %d. Got %r instead (%d bytes)." % ( BIGFILE_SIZE , body [ : 50 ] , len ( body ) ) ) ) #NEWLINE# #UNINDENT# conn . close ( )