Send an Expect: 100-Continue request. :param sock: The socket to send the request on. :param server_hostname: The hostname of the server to connect to.
(sock: socket.socket, server_hostname: str)
| 55 | |
| 56 | |
| 57 | def send_expect_request(sock: socket.socket, server_hostname: str) -> None: |
| 58 | """Send an Expect: 100-Continue request. |
| 59 | |
| 60 | :param sock: The socket to send the request on. |
| 61 | :param server_hostname: The hostname of the server to connect to. |
| 62 | """ |
| 63 | # Send the POST request. |
| 64 | host_header: bytes = f'Host: {server_hostname}\r\n'.encode() |
| 65 | request: bytes = ( |
| 66 | b"GET /api/1 HTTP/1.1\r\n" + host_header + b"Connection: keep-alive\r\n" |
| 67 | b"Content-Length: 3\r\n" |
| 68 | b"uuid: expect\r\n" |
| 69 | b"Expect: 100-Continue\r\n" |
| 70 | b"\r\n") |
| 71 | sock.sendall(request) |
| 72 | print('Sent Expect: 100-Continue request:') |
| 73 | print(request.decode()) |
| 74 | drain_response(sock) |
| 75 | print('Got 100-Continue response.') |
| 76 | sock.sendall(b'rst') |
| 77 | print('Sent "rst" body.') |
| 78 | |
| 79 | |
| 80 | def drain_response(sock: socket.socket) -> None: |
no test coverage detected