Skip to content

pyFF returns cached response when it should not #281

Open
@mic4ael

Description

@mic4ael

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions