Exemple #1
0
def create_key(self, request):
    """A new cache_key algo is required as the authentication token
    changes with each run. Also there are other header params which
    also change with each request (e.g. timestamp). Excluding all
    headers means that Accept-Language is excluded which means
    different language requests will return the cached response from
    the wrong language.

    The _loadurl part checks the cache before a get is performed so
    that an auth token can be obtained. If the response is already in
    the cache, the auth token is not required. This prevents the need
    to do a get which may access the host and fail because the session
    is not yet not authorized. It is not necessary to authorize if the
    cache is to be used thus saving host and network traffic.
    """

    if self._ignored_parameters:
        url, body = self._remove_ignored_parameters(request)
    else:
        url, body = request.url, request.body
    key = hashlib.sha256()
    key.update(_to_bytes(request.method.upper()))
    key.update(_to_bytes(url))
    if request.body:
        key.update(_to_bytes(body))
    else:
        if self._include_get_headers and request.headers != _DEFAULT_HEADERS:
            for name, value in sorted(request.headers.items()):
                # include only Accept-Language as it is important for context
                if name in ['Accept-Language']:
                    key.update(_to_bytes(name))
                    key.update(_to_bytes(value))
    return key.hexdigest()
Exemple #2
0
def create_key(self, request):
    """A new cache_key algo is required as the authentication token
    changes with each run. Also there are other header params which
    also change with each request (e.g. timestamp). Excluding all
    headers means that Accept-Language is excluded which means
    different language requests will return the cached response from
    the wrong language.

    The _loadurl part checks the cache before a get is performed so
    that an auth token can be obtained. If the response is already in
    the cache, the auth token is not required. This prevents the need
    to do a get which may access the host and fail because the session
    is not yet not authorized. It is not necessary to authorize if the
    cache is to be used thus saving host and network traffic.
    """

    if self._ignored_parameters:
        url, body = self._remove_ignored_parameters(request)
    else:
        url, body = request.url, request.body
    key = hashlib.sha256()
    key.update(_to_bytes(request.method.upper()))
    key.update(_to_bytes(url))
    if request.body:
        key.update(_to_bytes(body))
    else:
        if self._include_get_headers and request.headers != _DEFAULT_HEADERS:
            for name, value in sorted(request.headers.items()):
                # include only Accept-Language as it is important for context
                if name in ['Accept-Language']:
                    key.update(_to_bytes(name))
                    key.update(_to_bytes(value))
    return key.hexdigest()
def create_key(self, request):
    key = hashlib.sha256()
    key.update(_to_bytes(request.method.upper()))
    key.update(_to_bytes(request.url))
    if request.body:
        key.update(_to_bytes(request.body))
    if request.headers and 'Accept' in request.headers:
        key.update(_to_bytes(request.headers['Accept']))
    return key.hexdigest()
def create_key(self, request):
    key = hashlib.sha256()
    key.update(_to_bytes(request.method.upper()))
    key.update(_to_bytes(request.url))
    if request.body:
        key.update(_to_bytes(request.body))
    if request.headers and 'Accept' in request.headers:
        key.update(_to_bytes(request.headers['Accept']))
    return key.hexdigest()
Exemple #5
0
def create_key(self, request):
    if self._ignored_parameters:
        url, body = self._remove_ignored_parameters(request)
    else:
        url, body = request.url, request.body
    key = hashlib.sha256()
    key.update(_to_bytes(request.method.upper()))
    key.update(_to_bytes(url))
    if request.body:
        key.update(_to_bytes(body))
    else:
        if self._include_get_headers and request.headers != _DEFAULT_HEADERS:
            for name, value in sorted(request.headers.items()):
                # include only Accept-Language as it is important for context
                if name in ['Accept-Language']:
                    key.update(_to_bytes(name))
                    key.update(_to_bytes(value))
    return key.hexdigest()