#NEWLINE# def send_headers( self ) : #NEWLINE# #INDENT# 'Assert, process, and send the HTTP response message-headers.\n\n        You must set self.status, and self.outheaders before calling this.\n        ' #NEWLINE# hkeys = [ key . lower ( ) for ( key , value ) in self . outheaders ] #NEWLINE# status = int ( self . status [ : 3 ] ) #NEWLINE# if ( status == 413 ) : #NEWLINE# #INDENT# self . close_connection = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( b'content-length' not in hkeys ) : #NEWLINE# #INDENT# if ( ( status < 200 ) or ( status in ( 204 , 205 , 304 ) ) ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( self . response_protocol == 'HTTP/1.1' ) and ( self . method != b'HEAD' ) ) : #NEWLINE# #INDENT# self . chunked_write = True #NEWLINE# self . outheaders . append ( ( b'Transfer-Encoding' , b'chunked' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . close_connection = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( b'connection' not in k ) : #NEWLINE# #INDENT# if ( self . response_protocol == 'HTTP/1.1' ) : #NEWLINE# #INDENT# if self . close_connection : #NEWLINE# #INDENT# self . outheaders . append ( ( b'Connection' , b'close' ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not self . close_connection ) : #NEWLINE# #INDENT# self . outheaders . append ( ( b'Connection' , b'Keep-Alive' ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( ( not self . close_connection ) and ( not self . chunked_read ) ) : #NEWLINE# #INDENT# remaining = getattr ( self . rfile , 'remaining' , 0 ) #NEWLINE# if ( remaining > 0 ) : #NEWLINE# #INDENT# self . rfile . read ( remaining ) #NEWLINE# #UNINDENT# #UNINDENT# if ( b'date' not in hkeys ) : #NEWLINE# #INDENT# self . outheaders . append ( ( b'Date' , email . utils . formatdate ( usegmt = True ) . encode ( 'ISO-8859-1' ) ) ) #NEWLINE# #UNINDENT# if ( b'server' not in hkeys ) : #NEWLINE# #INDENT# self . outheaders . append ( ( b'Server' , self . server . server_name . encode ( 'ISO-8859-1' ) ) ) #NEWLINE# #UNINDENT# buf = [ ( ( ( self . server . protocol . encode ( 'ascii' ) + SPACE ) + self . status ) + CRLF ) ] #NEWLINE# for ( k , v ) in self . outheaders : #NEWLINE# #INDENT# buf . append ( ( ( ( ( k + COLON ) + SPACE ) + v ) + CRLF ) ) #NEWLINE# #UNINDENT# buf . append ( CRLF ) #NEWLINE# self . conn . wfile . write ( EMPTY . join ( buf ) )