summaryrefslogtreecommitdiff
path: root/requests_cache
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2022-05-21 12:54:56 -0500
committerJordan Cook <jordan.cook@pioneer.com>2022-06-16 15:45:42 -0500
commitccaf6b0b2d9a7dc612b5129e1c2841a04a2b587c (patch)
tree77239c988cb03dd36c1ad0f65eee66584fa7675c /requests_cache
parent458990f0f3308f5c8324a5628c598e0e3f60fa12 (diff)
downloadrequests-cache-ccaf6b0b2d9a7dc612b5129e1c2841a04a2b587c.tar.gz
Normalize ordering and whitespace for multi-value request headers
Diffstat (limited to 'requests_cache')
-rw-r--r--requests_cache/cache_keys.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/requests_cache/cache_keys.py b/requests_cache/cache_keys.py
index 6038716..1652bd7 100644
--- a/requests_cache/cache_keys.py
+++ b/requests_cache/cache_keys.py
@@ -9,7 +9,17 @@ from __future__ import annotations
import json
from hashlib import blake2b
from logging import getLogger
-from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Mapping, Optional, Union
+from typing import (
+ TYPE_CHECKING,
+ Any,
+ Dict,
+ Iterable,
+ List,
+ Mapping,
+ MutableMapping,
+ Optional,
+ Union,
+)
from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse
from requests import Request, Session
@@ -107,11 +117,15 @@ def normalize_request(
def normalize_headers(
- headers: Mapping[str, str], ignored_parameters: ParamList
+ headers: MutableMapping[str, str], ignored_parameters: ParamList
) -> CaseInsensitiveDict:
- """Sort and filter request headers"""
+ """Sort and filter request headers, and normalize minor variations in multi-value headers"""
if ignored_parameters:
headers = filter_sort_dict(headers, ignored_parameters)
+ for k, v in headers.items():
+ if ',' in v:
+ values = [v.strip() for v in v.lower().split(',') if v.strip()]
+ headers[k] = ', '.join(sorted(values))
return CaseInsensitiveDict(headers)