| 351 | ) |
| 352 | |
| 353 | def test_serialize(self): |
| 354 | # Example from the protocol overview in RFC 6455 |
| 355 | response = Response( |
| 356 | 101, |
| 357 | "Switching Protocols", |
| 358 | Headers( |
| 359 | [ |
| 360 | ("Upgrade", "websocket"), |
| 361 | ("Connection", "Upgrade"), |
| 362 | ("Sec-WebSocket-Accept", "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="), |
| 363 | ("Sec-WebSocket-Protocol", "chat"), |
| 364 | ] |
| 365 | ), |
| 366 | ) |
| 367 | self.assertEqual( |
| 368 | response.serialize(), |
| 369 | b"HTTP/1.1 101 Switching Protocols\r\n" |
| 370 | b"Upgrade: websocket\r\n" |
| 371 | b"Connection: Upgrade\r\n" |
| 372 | b"Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" |
| 373 | b"Sec-WebSocket-Protocol: chat\r\n" |
| 374 | b"\r\n", |
| 375 | ) |
| 376 | |
| 377 | def test_serialize_with_body(self): |
| 378 | response = Response( |