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

Function truncating_server

impit-python/test/async_client_test.py:33–46  ·  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

31
32
33def truncating_server(port_holder: list[int]) -> None:
34 """Announce a `Content-Length` larger than the body actually sent, then close the socket mid-body."""
35 server = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
36 server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
37 server.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
38 server.bind(('::', 0))
39 port_holder[0] = server.getsockname()[1]
40 server.listen(1)
41
42 conn, _ = server.accept()
43 conn.recv(1024)
44 conn.send(b'HTTP/1.1 200 OK\r\nContent-Length: 100\r\n\r\n0123456789')
45 conn.close()
46 server.close()
47
48
49@pytest.mark.asyncio

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…