We're having a bit of trouble with an heuristic. The fact is, Heuristic classes get the raw response, (a.k.a the requests.packages.urllib3.response.HTTPResponse), which does not contain any information about the request (for example, URL ...).
If we look at the parent's build_response(...) method, we see it has both raw request and response (cache_response method takes both).
def build_response(self, request, response, from_cache=False):
"""
Build a response by making a request or using the cache.
This will end up calling send and returning a potentially
cached response
"""
if not from_cache and request.method == 'GET':
# apply any expiration heuristics
if response.status == 304:
# We must have sent an ETag request. This could mean
# that we've been expired already or that we simply
# have an etag. In either case, we want to try and
# update the cache if that is the case.
cached_response = self.controller.update_cached_response(
request, response
)
if cached_response is not response:
from_cache = True
# We are done with the server response, read a
# possible response body (compliant servers will
# not return one, but we cannot be 100% sure) and
# release the connection back to the pool.
response.read(decode_content=False)
response.release_conn()
response = cached_response
# We always cache the 301 responses
elif response.status == 301:
self.controller.cache_response(request, response)
else:
# Check for any heuristics that might update headers
# before trying to cache.
if self.heuristic:
response = self.heuristic.apply(response)
# Wrap the response file with a wrapper that will cache the
# response when the stream has been consumed.
response._fp = CallbackFileWrapper(
response._fp,
functools.partial(
self.controller.cache_response,
request,
response,
)
)
Is there any reason (other than BC, obviously) why the heuristic only gets then response, and not the request ?
We're having a bit of trouble with an heuristic. The fact is, Heuristic classes get the raw response, (a.k.a the
requests.packages.urllib3.response.HTTPResponse), which does not contain any information about the request (for example, URL ...).If we look at the parent's
build_response(...)method, we see it has both raw request and response (cache_response method takes both).Is there any reason (other than BC, obviously) why the heuristic only gets then response, and not the request ?