Send an HTTP response. :param sock: The socket to write to. :param abort_early: If True, abort the response before sending the body.
(sock: socket.socket, abort_early: bool)
| 59 | |
| 60 | |
| 61 | def send_response(sock: socket.socket, abort_early: bool) -> None: |
| 62 | """Send an HTTP response. |
| 63 | |
| 64 | :param sock: The socket to write to. |
| 65 | :param abort_early: If True, abort the response before sending the body. |
| 66 | """ |
| 67 | if abort_early: |
| 68 | response = "HTTP/1." |
| 69 | else: |
| 70 | response = ("HTTP/1.1 200 OK\r\n" |
| 71 | "Content-Length: 0\r\n" |
| 72 | "\r\n") |
| 73 | print(f'Sending:\n{response}') |
| 74 | sock.sendall(response.encode("utf-8")) |
| 75 | |
| 76 | |
| 77 | def main() -> int: |