interface Response {
    app: KoaApplication<KoaApplication.DefaultState, KoaApplication.DefaultContext>;
    body: unknown;
    ctx: KoaContext;
    etag: string;
    header: OutgoingHttpHeaders;
    headerSent: boolean;
    headers: OutgoingHttpHeaders;
    lastModified: Date;
    length: number;
    message: string;
    req: IncomingMessage;
    request: KoaApplication.Request;
    res: ServerResponse<IncomingMessage>;
    socket: Socket;
    status: number;
    type: string;
    writable: boolean;
    append(field, val): void;
    attachment(filename?, options?): void;
    flushHeaders(): void;
    get(field): string;
    inspect(): any;
    is(...types): null | string | false;
    is(types): null | string | false;
    redirect(url, alt?): void;
    remove(field): void;
    set(field): void;
    set(field, val): void;
    toJSON(): any;
    vary(field): void;
}

Hierarchy (view full)

Properties

body: unknown

Get/Set response body.

etag: string

Get/Set the ETag of a response. This will normalize the quotes if necessary.

this.response.etag = 'md5hashsum';
this.response.etag = '"md5hashsum"';
this.response.etag = 'W/"123456789"';

Param: etag

Api

public

header: OutgoingHttpHeaders

Return response header.

headerSent: boolean

Check if a header has been written to the socket.

headers: OutgoingHttpHeaders

Return response header, alias as response.header

lastModified: Date

Get the Last-Modified date in Date form, if it exists. Set the Last-Modified date using a string or a Date.

this.response.lastModified = new Date();
this.response.lastModified = '2013-09-13';
length: number

Return parsed response Content-Length when present. Set Content-Length field to n.

message: string

Get response status message

req: IncomingMessage
res: ServerResponse<IncomingMessage>
socket: Socket

Return the request socket.

Returns

Api

public

status: number

Get/Set response status code.

type: string

Return the response mime type void of parameters such as "charset".

Set Content-Type response header with type through mime.lookup() when it does not contain a charset.

Examples:

this.type = '.html';
this.type = 'html';
this.type = 'json';
this.type = 'application/json';
this.type = 'png';
writable: boolean

Checks if the request is writable. Tests for the existence of the socket as node sometimes does not set it.

Methods

  • Append additional header field with value val.

    Examples:

    this.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);
    this.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');
    this.append('Warning', '199 Miscellaneous warning');

    Parameters

    • field: string
    • val: string | string[]

    Returns void

  • Set Content-Disposition to "attachment" to signal the client to prompt for download. Optionally specify the filename of the download and some options.

    Parameters

    • Optional filename: string
    • Optional options: Options

    Returns void

  • Flush any set headers, and begin the body

    Returns void

  • Return response header. If the header is not set, will return an empty string.

    The Referrer header field is special-cased, both Referrer and Referer are interchangeable.

    Examples:

    this.get('Content-Type');
    // => "text/plain"

    this.get('content-type');
    // => "text/plain"

    this.get('Something');
    // => ''

    Parameters

    • field: string

    Returns string

  • Inspect implementation.

    Returns any

  • Check whether the response is one of the listed types. Pretty much the same as this.request.is().

    Parameters

    • Rest ...types: string[]

    Returns null | string | false

    Api

    public

  • Parameters

    • types: string[]

    Returns null | string | false

  • Perform a 302 redirect to url.

    The string "back" is special-cased to provide Referrer support, when Referrer is not present alt or "/" is used.

    Examples:

    this.redirect('back'); this.redirect('back', '/index.html'); this.redirect('/login'); this.redirect('http://google.com');

    Parameters

    • url: string
    • Optional alt: string

    Returns void

  • Remove header field.

    Parameters

    • field: string

    Returns void

  • Set header field to val, or pass an object of header fields.

    Examples:

    this.set('Foo', ['bar', 'baz']); this.set('Accept', 'application/json'); this.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });

    Parameters

    • field: {
          [key: string]: string | string[];
      }
      • [key: string]: string | string[]

    Returns void

  • Parameters

    • field: string
    • val: string | string[]

    Returns void

  • Return JSON representation.

    Returns any

  • Vary on field.

    Parameters

    • field: string | string[]

    Returns void