Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scapy/layers/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,8 @@ def request(
self._connect_or_reuse(host, port=port, tls=tls, timeout=timeout)
continue
if not resp:
self.close()
self._sockinfo = None
break
# First case: auth was required. Handle that
if resp.Status_Code in [b"401", b"407"]:
Expand Down
27 changes: 27 additions & 0 deletions test/scapy/layers/http.uts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,33 @@ with run_httpserver(mech=HTTP_AUTH_MECHS.BASIC, BASIC_IDENTITIES={"user": "passw

assert html == "<!doctype html><html><body><h1>OK</h1></body></html>"

= HTTP - HTTP_Client discards a timed-out connection
~ http-client

from scapy.layers.http import HTTP_Client, HTTPResponse

class _TimeoutClient(HTTP_Client):
def __init__(self):
super().__init__(verb=False)
self.connection_count = 0
self.close_count = 0
self.responses = [None, HTTPResponse(Status_Code=b"200")]
def _connect_or_reuse(self, host, port=None, tls=False, timeout=5):
key = (host, port, tls)
if self._sockinfo != key:
self.connection_count += 1
self._sockinfo = key
def sr1(self, req, **kwargs):
return self.responses.pop(0)
def close(self):
self.close_count += 1

client = _TimeoutClient()
assert client.request("http://example.test:80/first", timeout=0.01) is None
assert client.request("http://example.test:80/second").Status_Code == b"200"
assert client.close_count == 1
assert client.connection_count == 2


= HTTP - HTTP_Server with native python client without auth
~ http-client
Expand Down
Loading