pyFF icon indicating copy to clipboard operation
pyFF copied to clipboard

`pyFF` returns cached response when it should not

Open mic4ael opened this issue 1 year ago • 0 comments

Code Version

2.1.2

Expected Behavior

pyFF returns correct response (cached or not) depending on the value of the Accept header.

Current Behavior

Request / response caching relies only on the request's path which is not unique enough to provide consistent results.

def request_handler(request: Request) -> Response:
    """
    The main GET request handler for pyFF. Implements caching and forwards the request to process_handler

    :param request: the HTTP request object
    :return: the data to send to the client
    """
    key = request.path_qs
    r = None
    try:
        r = request.registry.cache[key]
    except KeyError:
        pass
    if r is None:
        r = process_handler(request)
        request.registry.cache[key] = r
    return r

If I enable caching and issue two requests to the same path, with the only difference being that each request uses a different value for the Accept header, pyFF will return the same result.

Possible Solution

Cache key should include the request mimetype or we should cache something else (not the entire Response).

Steps to Reproduce

  1. Pipeline file, in my case, is heavily inspired by the examples/edugain-mdq.fd and has a couple of changes that are irrelevant to the issue.
  2. Run pyffd with caching_enabled:
pyffd --caching_enabled -f -H 0.0.0.0 -P 8080 --pid_file $PWD/tmp/pyff.pid --dir=$PWD/tmp/ $PWD/tmp/mdx.fd
  1. Send two different requests to pyFF:
http --print hH 0.0.0.0:8090 'Accept: application/json' # pyff will return JSON
http --print hH 0.0.0.0:8090 'Accept: application/xml' # pyff will return JSON instead of XML

mic4ael avatar Oct 24 '24 10:10 mic4ael