5
5
import re
6
6
import calendar
7
7
import time
8
+ import traceback
8
9
from email .utils import parsedate_tz
9
10
10
11
from requests .structures import CaseInsensitiveDict
@@ -280,7 +281,7 @@ def cache_response(self, request, response, body=None, status_codes=None):
280
281
cc = self .parse_cache_control (response_headers )
281
282
282
283
cache_url = self .cache_url (request .url )
283
- logger .debug ('Updating cache %r with response from "%s"' , self . cache , cache_url )
284
+ logger .debug ('Updating cache with response from "%s"' , cache_url )
284
285
285
286
# Delete it from the cache if we happen to have it stored there
286
287
no_store = False
@@ -309,14 +310,14 @@ def cache_response(self, request, response, body=None, status_codes=None):
309
310
if self .cache_etags and "etag" in response_headers :
310
311
logger .debug ("Caching due to etag" )
311
312
self .cache .set (
312
- cache_url , self .serializer .dumps (request , response , body = body )
313
+ cache_url , self .serializer .dumps (request , response , body )
313
314
)
314
315
315
316
# Add to the cache any permanent redirects. We do this before looking
316
317
# that the Date headers.
317
318
elif int (response .status ) in PERMANENT_REDIRECT_STATUSES :
318
319
logger .debug ("Caching permanent redirect" )
319
- self .cache .set (cache_url , self .serializer .dumps (request , response ))
320
+ self .cache .set (cache_url , self .serializer .dumps (request , response , b'' ))
320
321
321
322
# Add to the cache if the response headers demand it. If there
322
323
# is no date header then we can't do anything about expiring
@@ -329,7 +330,7 @@ def cache_response(self, request, response, body=None, status_codes=None):
329
330
if "max-age" in cc and cc ["max-age" ] > 0 :
330
331
logger .debug ("Caching b/c date exists and max-age > 0" )
331
332
self .cache .set (
332
- cache_url , self .serializer .dumps (request , response , body = body )
333
+ cache_url , self .serializer .dumps (request , response , body )
333
334
)
334
335
335
336
# If the request can expire, it means we should cache it
@@ -338,7 +339,7 @@ def cache_response(self, request, response, body=None, status_codes=None):
338
339
if response_headers ["expires" ]:
339
340
logger .debug ("Caching b/c of expires header" )
340
341
self .cache .set (
341
- cache_url , self .serializer .dumps (request , response , body = body )
342
+ cache_url , self .serializer .dumps (request , response , body )
342
343
)
343
344
else :
344
345
logger .debug ("No combination of headers to cache." )
@@ -379,6 +380,7 @@ def update_cached_response(self, request, response):
379
380
cached_response .status = 200
380
381
381
382
# update our cache
382
- self .cache .set (cache_url , self .serializer .dumps (request , cached_response ))
383
+ body = cached_response .read (decode_content = False )
384
+ self .cache .set (cache_url , self .serializer .dumps (request , cached_response , body ))
383
385
384
386
return cached_response
0 commit comments