Make a simple HTTP request and return the response body.
(host, port, path='/')
| 57 | |
| 58 | |
| 59 | def make_request(host, port, path='/'): |
| 60 | """Make a simple HTTP request and return the response body.""" |
| 61 | with socket.create_connection((host, port), timeout=5) as sock: |
| 62 | request = f'GET {path} HTTP/1.1\r\nHost: {host}\r\nConnection: close\r\n\r\n' |
| 63 | sock.sendall(request.encode()) |
| 64 | response = b'' |
| 65 | while True: |
| 66 | chunk = sock.recv(4096) |
| 67 | if not chunk: |
| 68 | break |
| 69 | response += chunk |
| 70 | return response |
| 71 | |
| 72 | |
| 73 | @pytest.fixture |
no test coverage detected