def build_ws_upgrade_request(web_socket_url, extra_headers=None, web_socket_version=DEFAULT_PROTOCOL_VERSION, origin=None):
 request_headers = Headers()
 request_headers['Sec-WebSocket-Key'] = gen_ws_sec_key()
 for (key, value) in WEBSOCKET_UPGRADE_HEADERS.items():
  request_headers[key] = value
 if (extra_headers is not None):
  for (key, value) in extra_headers:
   request_headers[key] = value
 request_headers['Sec-WebSocket-Version'] = str(web_socket_version)
 if (origin is not None):
  request_headers['Origin'] = origin
 else:
  scheme = ('https://' if ('wss://' in web_socket_url) else 'http://')
  args = (scheme, web_socket_url.get_domain())
  request_headers['Origin'] = ('%s%s' % args)
 forged_url = web_socket_url.url_string.replace('wss://', 'https://', 1)
 forged_url = forged_url.replace('ws://', 'http://', 1)
 forged_url = URL(forged_url)
 upgrade_request = FuzzableRequest(forged_url, 'GET', headers=request_headers)
 return upgrade_request

def build_ws_upgrade_request ( web_socket_url , extra_headers = None , web_socket_version = DEFAULT_PROTOCOL_VERSION , origin = None ) : request_headers = Headers ( ) request_headers [ 'Sec-WebSocket-Key' ] = gen_ws_sec_key ( ) for ( key , value ) in WEBSOCKET_UPGRADE_HEADERS . items ( ) : request_headers [ key ] = value if ( extra_headers is not None ) : for ( key , value ) in extra_headers : request_headers [ key ] = value request_headers [ 'Sec-WebSocket-Version' ] = str ( web_socket_version ) if ( origin is not None ) : request_headers [ 'Origin' ] = origin else : scheme = ( 'https://' if ( 'wss://' in web_socket_url ) else 'http://' ) args = ( scheme , web_socket_url . get_domain ( ) ) request_headers [ 'Origin' ] = ( '%s%s' % args ) forged_url = web_socket_url . url_string . replace ( 'wss://' , 'https://' , 1 ) forged_url = forged_url . replace ( 'ws://' , 'http://' , 1 ) forged_url = URL ( forged_url ) upgrade_request = FuzzableRequest ( forged_url , 'GET' , headers = request_headers ) return upgrade_request
create a get request with the required http headers to upgrade to web sockets .