Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyFF returns cached response when it should not #281

Open
mic4ael opened this issue Oct 24, 2024 · 0 comments
Open

pyFF returns cached response when it should not #281

mic4ael opened this issue Oct 24, 2024 · 0 comments

Comments

@mic4ael
Copy link

mic4ael commented Oct 24, 2024

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 mic4ael changed the title pyff returns cached response when it should not pyFF returns cached response when it should not Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant