Skip to content

StateCache consumer or the StateCache itself does not respect 'Vary' header #400

@reda-alaoui

Description

@reda-alaoui

Hello,

We started to use prefer header.
We have a place where we perform 2 subsequent GET on the same uri, first with prefer: return-minimal then with prefer: return-representation. When we use the default ForeverCache, only one request is performed (the first one), and the minimal response is always returned (which is the issue).

Please note that the server returns correctly Vary: prefer in the http response.

The StateCache implementation is unable to verify that the cached state is valid regarding the request headers, since it does not receive them:

export interface StateCache {

  // Missing request headers as parameters?
  get: (uri: string) => State | null;

}

Also, the StateCache consumer does not validate the cached state regarding the Vary header:

  /**
   * Gets the current state of the resource.
   *
   * This function will return a State object.
   */
  get(getOptions?: GetRequestOptions): Promise<State<T>> {

    const state = this.getCache();
    if (state) {
      return Promise.resolve(state);
    }

    //...
  }

Can we either:

  • add the GET request options as a second argument to StateCache.get()
    or
  • make sure the StateCache consumer validate the cached state regarding the Vary header

If we choose the first option, the StateCache would also need to access the request that lead to the creation of the State (second argument in StateCache.store() or a reference inside State object?) in order to respect https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching#varying_responses:

When a cache receives a request that has a Vary header field, it must not use a cached response by default unless all header fields specified in the Vary header match in both the original (cached) request and the new request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions