def cleanHeaders(headers, method, body, host, port):
 if (headers is None):
  headers = []
 found = False
 for (k, v) in headers:
  if (k.lower() == 'host'):
   found = True
   break
 if (not found):
  if (port == 80):
   headers.append(('Host', host))
  else:
   headers.append(('Host', ('%s:%s' % (host, port))))
 if (method in methods_with_bodies):
  found = False
  for (k, v) in headers:
   if (k.lower() == 'content-type'):
    found = True
    break
  if (not found):
   headers.append(('Content-Type', 'application/x-www-form-urlencoded'))
   headers.append(('Content-Length', str(len((body or '')))))
 return headers

def cleanHeaders ( headers , method , body , host , port ) : if ( headers is None ) : headers = [ ] found = False for ( k , v ) in headers : if ( k . lower ( ) == 'host' ) : found = True break if ( not found ) : if ( port == 80 ) : headers . append ( ( 'Host' , host ) ) else : headers . append ( ( 'Host' , ( '%s:%s' % ( host , port ) ) ) ) if ( method in methods_with_bodies ) : found = False for ( k , v ) in headers : if ( k . lower ( ) == 'content-type' ) : found = True break if ( not found ) : headers . append ( ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ) headers . append ( ( 'Content-Length' , str ( len ( ( body or '' ) ) ) ) ) return headers
return request headers .