#NEWLINE# def _build_request( self , request , scenario ) : #NEWLINE# #INDENT# path = self . _get_request_path ( request , scenario ) #NEWLINE# http = ( '%s %s HTTP/1.1\r\n' % ( request . method , headers ) ) #NEWLINE# headers = BetterDict ( ) #NEWLINE# headers . merge ( { #NEWLINE# #INDENT# 'Host' : self . hostname , #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( not scenario . get ( 'keepalive' , True ) ) : #NEWLINE# #INDENT# headers . merge ( { #NEWLINE# #INDENT# 'Connection' : 'close' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# body = '' #NEWLINE# if isinstance ( request . body , dict ) : #NEWLINE# #INDENT# if ( request . method != 'GET' ) : #NEWLINE# #INDENT# body = urlencode ( request . body ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( request . body , string_types ) : #NEWLINE# #INDENT# body = request . body #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if request . body : #NEWLINE# #INDENT# raise ValueError ( ( "Cannot handle 'body' option of type %s: %s" % ( type ( request . body ) , request . body ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if body : #NEWLINE# #INDENT# headers . merge ( { #NEWLINE# #INDENT# 'Content-Length' : len ( body ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# headers . merge ( scenario . get ( 'headers' ) ) #NEWLINE# headers . merge ( request . headers ) #NEWLINE# for ( header , value ) in iteritems ( headers ) : #NEWLINE# #INDENT# http += ( '%s: %s\r\n' % ( header , value ) ) #NEWLINE# #UNINDENT# http += ( '\r\n%s' % ( body , ) ) #NEWLINE# return http