utils: make sure bytes are used for URL cache key (#22203)
This commit is contained in:
parent
690bda4315
commit
53146ac618
|
@ -23,6 +23,7 @@ from requests import Response, Session as RequestsSession
|
|||
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.utils.encoding import smart_bytes
|
||||
from django.utils.http import urlencode
|
||||
|
||||
from .signature import sign_url
|
||||
|
@ -101,7 +102,7 @@ class Requests(RequestsSession):
|
|||
|
||||
if method == 'GET' and cache_duration:
|
||||
# handle cache
|
||||
cache_key = hashlib.md5(url).hexdigest()
|
||||
cache_key = hashlib.md5(smart_bytes(url)).hexdigest()
|
||||
cache_content = cache.get(cache_key)
|
||||
if cache_content and not invalidate_cache:
|
||||
response = Response()
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
import urlparse
|
||||
|
@ -143,3 +145,6 @@ def test_requests_cache():
|
|||
# check raise_if_not_cached
|
||||
with pytest.raises(NothingInCacheException):
|
||||
requests.get('http://cache.example.org/other', raise_if_not_cached=True)
|
||||
|
||||
# check with unicode url
|
||||
assert requests.get(u'http://cache.example.org/éléphant').content == 'hello second world'
|
||||
|
|
Loading…
Reference in New Issue