Server closes the connection when receiving non-HTTP request from client.
(self)
| 454 | writer.close() |
| 455 | |
| 456 | async def test_junk_handshake(self): |
| 457 | """Server closes the connection when receiving non-HTTP request from client.""" |
| 458 | with self.assertLogs("websockets", logging.ERROR) as logs: |
| 459 | async with serve(*args) as server: |
| 460 | reader, writer = await asyncio.open_connection(*get_host_port(server)) |
| 461 | writer.write(b"HELO relay.invalid\r\n") |
| 462 | try: |
| 463 | # Wait for the server to close the connection. |
| 464 | self.assertEqual(await reader.read(4096), b"") |
| 465 | finally: |
| 466 | writer.close() |
| 467 | |
| 468 | self.assertEqual( |
| 469 | [record.getMessage() for record in logs.records], |
| 470 | ["opening handshake failed"], |
| 471 | ) |
| 472 | self.assertEqual( |
| 473 | [str(record.exc_info[1]) for record in logs.records], |
| 474 | ["did not receive a valid HTTP request"], |
| 475 | ) |
| 476 | self.assertEqual( |
| 477 | [str(record.exc_info[1].__cause__) for record in logs.records], |
| 478 | ["invalid HTTP request line: HELO relay.invalid"], |
| 479 | ) |
| 480 | |
| 481 | async def test_close_server_rejects_connecting_connections(self): |
| 482 | """Server rejects connecting connections with HTTP 503 when closing.""" |
nothing calls this directly
no test coverage detected