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.
Hello,
We started to use
preferheader.We have a place where we perform 2 subsequent GET on the same uri, first with
prefer: return-minimalthen withprefer: return-representation. When we use the defaultForeverCache, 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: preferin 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:
Also, the
StateCacheconsumer does not validate the cached state regarding theVaryheader:Can we either:
StateCache.get()or
VaryheaderIf 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: