| 101 | ) |
| 102 | |
| 103 | def test_serialize(self): |
| 104 | # Example from the protocol overview in RFC 6455 |
| 105 | request = Request( |
| 106 | "/chat", |
| 107 | Headers( |
| 108 | [ |
| 109 | ("Host", "server.example.com"), |
| 110 | ("Upgrade", "websocket"), |
| 111 | ("Connection", "Upgrade"), |
| 112 | ("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="), |
| 113 | ("Origin", "http://example.com"), |
| 114 | ("Sec-WebSocket-Protocol", "chat, superchat"), |
| 115 | ("Sec-WebSocket-Version", "13"), |
| 116 | ] |
| 117 | ), |
| 118 | ) |
| 119 | self.assertEqual( |
| 120 | request.serialize(), |
| 121 | b"GET /chat HTTP/1.1\r\n" |
| 122 | b"Host: server.example.com\r\n" |
| 123 | b"Upgrade: websocket\r\n" |
| 124 | b"Connection: Upgrade\r\n" |
| 125 | b"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 126 | b"Origin: http://example.com\r\n" |
| 127 | b"Sec-WebSocket-Protocol: chat, superchat\r\n" |
| 128 | b"Sec-WebSocket-Version: 13\r\n" |
| 129 | b"\r\n", |
| 130 | ) |
| 131 | |
| 132 | |
| 133 | class ResponseTests(GeneratorTestCase): |