MCPcopy Create free account
hub / github.com/apify/impit / truncating_server

Function truncating_server

impit-python/test/basic_client_test.py:45–58  ·  view source on GitHub ↗

Announce a `Content-Length` larger than the body actually sent, then close the socket mid-body.

(port_holder: list[int])

Source from the content-addressed store, hash-verified

43
44
45def truncating_server(port_holder: list[int]) -> None:
46 """Announce a `Content-Length` larger than the body actually sent, then close the socket mid-body."""
47 server = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
48 server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
49 server.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
50 server.bind(('::', 0))
51 port_holder[0] = server.getsockname()[1]
52 server.listen(1)
53
54 conn, _ = server.accept()
55 conn.recv(1024)
56 conn.send(b'HTTP/1.1 200 OK\r\nContent-Length: 100\r\n\r\n0123456789')
57 conn.close()
58 server.close()
59
60
61@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 2

sendMethod · 0.80
closeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…