Interface InterceptableResponse

Represents an intercepted HTTP response which can be modified.

interface InterceptableResponse {
    body: ResponseBody;
    closed: boolean;
    headers: HTTPHeaders;
    request: Request;
    status: number;
    statusText: string;
    url: string;
    respondWith(response: ResponseInit): void;
    waitUntil(fn: WaitUntilCallback): void;
    waitUntil(promise: PromiseLike<any>): void;
}

Properties

The response's body.

closed: boolean

Whether the response is closed.


- Response is closed by InterceptableResponse.respondWith.

headers: HTTPHeaders

The response's HTTP headers.

request: Request

The response's request.

status: number

The response's status code.

statusText: string

The response's status text.

url: string

The response's url.


- This can differ from the request.url when redirected.

Methods

  • Replaces the original response with the provided response.

    Parameters

    Returns void


    - Invocation closes the response.
    - Invocation while the response is closed will throw an error.

  • Wait until the given callback is done before closing this response.

    Returns void


    - The first argument of the callback is a done function, which must be called to resolve the callback.
    - Invocation of the done function closes the response.
    - Invocation while the response is closed will throw an error.

  • Wait until the given promise is resolved before closing this response.

    Parameters

    Returns void


    - Resolution of the promise closes the response.
    - Invocation while the response is closed will throw an error.
    - This is equivalent to:

    response.waitUntil(function (done) {
    promise.then(function () {
    done();
    }).catch(function (error) {
    done(error);
    });
    })