MCPcopy Index your code
hub / github.com/secdev/scapy / http_request

Function http_request

scapy/layers/http.py:978–1017  ·  view source on GitHub ↗

Util to perform an HTTP request. :param host: the host to connect to :param path: the path of the request (default /) :param port: the port (default 80/443) :param timeout: timeout before None is returned :param display: display the result in the default browser (default Fa

(
    host, path="/", port=None, timeout=3, display=False, tls=False, verbose=0, **headers
)

Source from the content-addressed store, hash-verified

976
977
978def http_request(
979 host, path="/", port=None, timeout=3, display=False, tls=False, verbose=0, **headers
980):
981 """
982 Util to perform an HTTP request.
983
984 :param host: the host to connect to
985 :param path: the path of the request (default /)
986 :param port: the port (default 80/443)
987 :param timeout: timeout before None is returned
988 :param display: display the result in the default browser (default False)
989 :param iface: interface to use. Changing this turns on "raw"
990 :param headers: any additional headers passed to the request
991
992 :returns: the HTTPResponse packet
993 """
994 client = HTTP_Client(HTTP_AUTH_MECHS.NONE, verb=verbose)
995 if port is None:
996 port = 443 if tls else 80
997 ans = client.request(
998 "http%s://%s:%s%s" % (tls and "s" or "", host, port, path),
999 timeout=timeout,
1000 )
1001
1002 if ans:
1003 if display:
1004 if Raw not in ans:
1005 warning("No HTTP content returned. Cannot display")
1006 return ans
1007 # Write file
1008 file = get_temp_file(autoext=".html")
1009 with open(file, "wb") as fd:
1010 fd.write(ans.load)
1011 # Open browser
1012 if WINDOWS:
1013 os.startfile(file)
1014 else:
1015 with ContextManagerSubprocess(conf.prog.universal_open):
1016 subprocess.Popen([conf.prog.universal_open, file])
1017 return ans
1018
1019
1020# Bindings

Callers

nothing calls this directly

Calls 6

requestMethod · 0.95
warningFunction · 0.90
get_temp_fileFunction · 0.90
HTTP_ClientClass · 0.85
writeMethod · 0.45

Tested by

no test coverage detected