#NEWLINE# def write_headers( self , start_line , headers , chunk = None , callback = None ) : #NEWLINE# #INDENT# 'Implements `.HTTPConnection.write_headers`.' #NEWLINE# if self . is_client : #NEWLINE# #INDENT# self . _request_start_line = start_line #NEWLINE# self . _chunking_output = ( ( start_line . method in ( 'POST' , 'PUT' , 'PATCH' ) ) and ( 'Content-Length' not in headers ) and ( 'Transfer-Encoding' not in headers ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _response_start_line = start_line #NEWLINE# self . _chunking_output = ( ( self . _request_start_line . version == 'HTTP/1.1' ) and ( start_line . code != 304 ) and ( 'Content-Length' not in headers ) and ( 'Transfer-Encoding' not in headers ) ) #NEWLINE# if ( ( self . _request_start_line . version == 'HTTP/1.0' ) and ( self . _request_headers . get ( 'Connection' , '' ) . lower ( ) == 'keep-alive' ) ) : #NEWLINE# #INDENT# headers [ 'Connection' ] = 'Keep-Alive' #NEWLINE# #UNINDENT# #UNINDENT# if self . _chunking_output : #NEWLINE# #INDENT# headers [ 'Transfer-Encoding' ] = 'chunked' #NEWLINE# #UNINDENT# if ( ( not self . is_client ) and ( ( self . _request_start_line . method == 'HEAD' ) or ( start_line . code == 304 ) ) ) : #NEWLINE# #INDENT# self . _expected_content_remaining = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'Content-Length' in headers ) : #NEWLINE# #INDENT# self . _expected_content_remaining = int ( headers [ 'Content-Length' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _expected_content_remaining = None #NEWLINE# #UNINDENT# #UNINDENT# lines = [ utf8 ( ( '%s %s %s' % start_line ) ) ] #NEWLINE# lines . extend ( [ ( ( utf8 ( n ) + b': ' ) + utf8 ( v ) ) for ( n , v ) in headers . get_all ( ) ] ) #NEWLINE# for line in lines : #NEWLINE# #INDENT# if ( b'\n' in line ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Newline in header: ' + repr ( line ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# future = None #NEWLINE# if self . stream . closed ( ) : #NEWLINE# #INDENT# future = self . _write_future = Future ( ) #NEWLINE# future . set_exception ( iostream . StreamClosedError ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( callback is not None ) : #NEWLINE# #INDENT# self . _write_callback = stack_context . wrap ( callback ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# future = self . _write_future = Future ( ) #NEWLINE# #UNINDENT# data = ( b'\r\n' . join ( lines ) + b'\r\n\r\n' ) #NEWLINE# if chunk : #NEWLINE# #INDENT# data += self . _format_chunk ( chunk ) #NEWLINE# #UNINDENT# self . _pending_write = self . stream . write ( line ) #NEWLINE# self . _pending_write . add_done_callback ( self . _on_write_complete ) #NEWLINE# #UNINDENT# return future