|
1 | 1 | # ================================================================= |
2 | 2 | # |
3 | 3 | # Authors: Tom Kralidis <tomkralidis@gmail.com> |
| 4 | +# Francesco Bartoli <xbartolone@gmail.com> |
4 | 5 | # |
5 | 6 | # Copyright (c) 2026 Tom Kralidis |
| 7 | +# Copyright (c) 2026 Francesco Bartoli |
6 | 8 | # |
7 | 9 | # Permission is hereby granted, free of charge, to any person |
8 | 10 | # obtaining a copy of this software and associated documentation |
@@ -331,6 +333,18 @@ def test_get_choice_from_headers(): |
331 | 333 | {'accept-language': 'en_US', 'accept': '*/*'}, 'accept') == '*/*' |
332 | 334 |
|
333 | 335 |
|
| 336 | +def test_get_choice_from_headers_drops_q_zero(): |
| 337 | + # RFC 9110, section 12.4.2: q=0 means "not acceptable" |
| 338 | + _headers = {'accept': 'image/png;q=0,application/json;q=0.5'} |
| 339 | + |
| 340 | + assert util.get_choice_from_headers( |
| 341 | + _headers, 'accept', all=True) == ['application/json'] |
| 342 | + assert util.get_choice_from_headers( |
| 343 | + {'accept': 'image/png;q=0'}, 'accept') is None |
| 344 | + assert util.get_choice_from_headers( |
| 345 | + {'accept': 'image/png;q=0'}, 'accept', all=True) == [] |
| 346 | + |
| 347 | + |
334 | 348 | @pytest.mark.parametrize('url,allow_internal,result', [ |
335 | 349 | ['http://127.0.0.1/test', False, False], |
336 | 350 | ['http://127.0.0.1/test', True, True], |
|
0 commit comments