Skip to content

Commit

Permalink
Merge pull request #474 from grubberr/improve_get_matched_headers
Browse files Browse the repository at this point in the history
make order of headers repeatable
  • Loading branch information
JWCook committed Jan 1, 2022
2 parents 71ea521 + 99b7793 commit 3470482
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.md
Expand Up @@ -23,6 +23,7 @@
* Some micro-optimizations for request matching

**Bugfixes:**
* Fix regression bug causing headers used for cache key to not guarantee sort order
* Handle some additional corner cases when normalizing request data
* Add support for `BaseCache` keyword arguments passed along with a backend instance
* Fix issue with cache headers not being used correctly if `cache_control=True` is used with an `expire_after` value
Expand Down
4 changes: 3 additions & 1 deletion requests_cache/cache_keys.py
Expand Up @@ -81,7 +81,9 @@ def get_matched_headers(
else:
included = set(headers) - DEFAULT_EXCLUDE_HEADERS

return [f'{k.lower()}={headers[k]}' for k in included if k in headers]
return [
f'{k.lower()}={headers[k]}' for k in sorted(included, key=lambda x: x.lower()) if k in headers
]


def normalize_request(request: AnyRequest, ignored_parameters: ParamList) -> AnyPreparedRequest:
Expand Down

0 comments on commit 3470482

Please sign in to comment.