-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_incomplete_chunks.py
More file actions
executable file
·52 lines (43 loc) · 1.52 KB
/
Copy pathtest_incomplete_chunks.py
File metadata and controls
executable file
·52 lines (43 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
# filepath: test_incomplete_chunks.py
import socket
import time
def test_incomplete_chunks():
# Connect to your server
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 8022))
print("Connected to server")
# Send HTTP request headers with Content-Length
request = (
"POST /test HTTP/1.1\r\n"
"Host: localhost:8022\r\n"
"Content-Length: 1000\r\n" # Promise 1000 bytes
"Content-Type: text/plain\r\n"
"\r\n"
)
sock.send(request.encode())
print("Sent headers (promised 1000 bytes)")
# Send only partial body
partial_body = "This is only 30 bytes long!!"
sock.send(partial_body.encode())
print(f"Sent only {len(partial_body)} bytes")
print("Now waiting... Server expects 1000 bytes but won't get them.")
print("Connection should timeout after 60 seconds...")
# Keep connection open but don't send the rest
# Wait to see if server closes connection
try:
sock.settimeout(70) # Wait up to 70 seconds
response = sock.recv(4096)
if response:
print(f"Received response: {response.decode()}")
else:
print("Connection closed by server (timeout)")
except socket.timeout:
print("Socket timeout - server didn't respond")
except Exception as e:
print(f"Error: {e}")
finally:
sock.close()
print("Connection closed")
if __name__ == "__main__":
test_incomplete_chunks()