mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 02:01:40 -05:00
fix: add url for cached response (#1355)
This commit is contained in:
parent
3b3c50a1ab
commit
cd1a4630f8
3 changed files with 14 additions and 2 deletions
|
@ -37,7 +37,11 @@ export class HTTPCache {
|
|||
|
||||
if (policy.satisfiesWithoutRevalidation(policyRequestFrom(request))) {
|
||||
const headers = policy.responseHeaders();
|
||||
return new Response(body, { status: policy._status, headers });
|
||||
return new Response(body, {
|
||||
url: policy._url,
|
||||
status: policy._status,
|
||||
headers,
|
||||
});
|
||||
} else {
|
||||
const revalidationHeaders = policy.revalidationHeaders(
|
||||
policyRequestFrom(request),
|
||||
|
@ -57,6 +61,7 @@ export class HTTPCache {
|
|||
modified
|
||||
? revalidationResponse
|
||||
: new Response(body, {
|
||||
url: revalidatedPolicy._url,
|
||||
status: revalidatedPolicy._status,
|
||||
headers: revalidatedPolicy.responseHeaders(),
|
||||
}),
|
||||
|
@ -91,6 +96,7 @@ export class HTTPCache {
|
|||
// To avoid https://github.com/bitinn/node-fetch/issues/151, we don't use
|
||||
// response.clone() but create a new response from the consumed body
|
||||
return new Response(body, {
|
||||
url: response.url,
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers: policy.responseHeaders(),
|
||||
|
|
|
@ -31,6 +31,7 @@ declare module 'http-cache-semantics' {
|
|||
static fromObject(object: object): CachePolicy;
|
||||
toObject(): object;
|
||||
|
||||
_url: string;
|
||||
_status: number;
|
||||
}
|
||||
|
||||
|
|
7
packages/apollo-server-env/src/fetch.d.ts
vendored
7
packages/apollo-server-env/src/fetch.d.ts
vendored
|
@ -78,7 +78,8 @@ export type ReferrerPolicy =
|
|||
| 'unsafe-url';
|
||||
|
||||
export declare class Response extends Body {
|
||||
constructor(body?: BodyInit, init?: ResponseInit);
|
||||
// node-fetch accepts options as the second argument instead of a pure ResponseInit
|
||||
constructor(body?: BodyInit, options?: ResponseOptions);
|
||||
static error(): Response;
|
||||
static redirect(url: string, status?: number): Response;
|
||||
|
||||
|
@ -98,4 +99,8 @@ export interface ResponseInit {
|
|||
statusText?: string;
|
||||
}
|
||||
|
||||
export interface ResponseOptions extends ResponseInit {
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export type BodyInit = ArrayBuffer | ArrayBufferView | string;
|
||||
|
|
Loading…
Add table
Reference in a new issue