| 261 | |
| 262 | class HTTPHeadersTest(unittest.TestCase): |
| 263 | def test_multi_line(self): |
| 264 | # Lines beginning with whitespace are appended to the previous line |
| 265 | # with any leading whitespace replaced by a single space. |
| 266 | # Note that while multi-line headers are a part of the HTTP spec, |
| 267 | # their use is strongly discouraged. |
| 268 | data = """\ |
| 269 | Foo: bar |
| 270 | baz |
| 271 | Asdf: qwer |
| 272 | \tzxcv |
| 273 | Foo: even |
| 274 | more |
| 275 | lines |
| 276 | """.replace( |
| 277 | "\n", "\r\n" |
| 278 | ) |
| 279 | headers = HTTPHeaders.parse(data) |
| 280 | self.assertEqual(headers["asdf"], "qwer zxcv") |
| 281 | self.assertEqual(headers.get_list("asdf"), ["qwer zxcv"]) |
| 282 | self.assertEqual(headers["Foo"], "bar baz,even more lines") |
| 283 | self.assertEqual(headers.get_list("foo"), ["bar baz", "even more lines"]) |
| 284 | self.assertEqual( |
| 285 | sorted(list(headers.get_all())), |
| 286 | [("Asdf", "qwer zxcv"), ("Foo", "bar baz"), ("Foo", "even more lines")], |
| 287 | ) |
| 288 | |
| 289 | def test_malformed_continuation(self): |
| 290 | # If the first line starts with whitespace, it's a |