Mercurial > p > roundup > code
comparison test/test_liveserver.py @ 6539:f8df7fed18f6
issue2551175 - Make ETag content-encoding aware.
HTTP ETag headers now include a suffix (-gzip, -br, -zstd) indicating
the content-encoding used to send the data per rfc7232. Validate any
form of ETag by stripping a suffix (if present).
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 01 Dec 2021 19:52:54 -0500 |
| parents | 3c8322e3fe25 |
| children | c8f3ec942e29 |
comparison
equal
deleted
inserted
replaced
| 6538:28fa3798ca3d | 6539:f8df7fed18f6 |
|---|---|
| 437 # just skip comparing it. | 437 # just skip comparing it. |
| 438 del(json_dict['data']['type']) | 438 del(json_dict['data']['type']) |
| 439 | 439 |
| 440 self.assertDictEqual(json_dict, content) | 440 self.assertDictEqual(json_dict, content) |
| 441 | 441 |
| 442 # verify that ETag header ends with -gzip | |
| 443 try: | |
| 444 self.assertRegex(f.headers['ETag'], r'^"[0-9a-f]{32}-gzip"$') | |
| 445 except AttributeError: | |
| 446 # python2 no assertRegex so try substring match | |
| 447 self.assertEqual(33, f.headers['ETag'].rindex('-gzip"')) | |
| 448 | |
| 442 # use dict comprehension to remove fields like date, | 449 # use dict comprehension to remove fields like date, |
| 443 # content-length etc. from f.headers. | 450 # content-length etc. from f.headers. |
| 444 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected) | 451 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected) |
| 445 | 452 |
| 446 | 453 |
| 566 # just skip comparing it. | 573 # just skip comparing it. |
| 567 del(json_dict['data']['type']) | 574 del(json_dict['data']['type']) |
| 568 | 575 |
| 569 self.assertDictEqual(json_dict, content) | 576 self.assertDictEqual(json_dict, content) |
| 570 | 577 |
| 578 # verify that ETag header ends with -br | |
| 579 try: | |
| 580 self.assertRegex(f.headers['ETag'], r'^"[0-9a-f]{32}-br"$') | |
| 581 except AttributeError: | |
| 582 # python2 no assertRegex so try substring match | |
| 583 self.assertEqual(33, f.headers['ETag'].rindex('-br"')) | |
| 584 | |
| 571 # use dict comprehension to remove fields like date, | 585 # use dict comprehension to remove fields like date, |
| 572 # content-length etc. from f.headers. | 586 # content-length etc. from f.headers. |
| 573 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected) | 587 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected) |
| 574 | 588 |
| 575 | 589 |
| 712 # just skip comparing it. | 726 # just skip comparing it. |
| 713 del(json_dict['data']['type']) | 727 del(json_dict['data']['type']) |
| 714 | 728 |
| 715 self.assertDictEqual(json_dict, content) | 729 self.assertDictEqual(json_dict, content) |
| 716 | 730 |
| 731 # verify that ETag header ends with -zstd | |
| 732 try: | |
| 733 self.assertRegex(f.headers['ETag'], r'^"[0-9a-f]{32}-zstd"$') | |
| 734 except AttributeError: | |
| 735 # python2 no assertRegex so try substring match | |
| 736 self.assertEqual(33, f.headers['ETag'].rindex('-zstd"')) | |
| 737 | |
| 717 # use dict comprehension to remove fields like date, | 738 # use dict comprehension to remove fields like date, |
| 718 # content-length etc. from f.headers. | 739 # content-length etc. from f.headers. |
| 719 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected) | 740 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected) |
| 720 | 741 |
| 721 | 742 |
