跳到主要内容
版本:Next

FaaSHTTPResponse

Hierarchy

  • ContextDelegatedResponse
  • Pick<Writable, write | end>
    • FaaSHTTPResponse

Index

Properties

body

body: any

Get/Set response body.

etag

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
@api

public

header

header: {}

Return response header.

headers

headers: {}

Return response header, alias as response.header

lastModified

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

length: number

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

status

status: number

Get/Set response status code.

streaming

streaming: boolean

Get/Set streaming response.

this.streaming = true;
@api

public

type

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';

Methods

append

  • append(field: string, val: string | string[]): void
  • 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');

get

  • get(field: string): string
  • 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');
    // => ''

is

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

    @api

    public

redirect

  • redirect(url: string, alt?: string): void
  • 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‘);

remove

  • remove(field: string): void
  • Remove header field.

set

  • set(field: {}): void
  • set(field: string, val: string | string[]): 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’ });