Skip to main content
Module

x/deno_koa/response.ts>Response

A middleware framework for Deno's http serve🦕. Transplanted from Koa with ❤️
Latest
class Response
import { Response } from "https://deno.land/x/deno_koa@v1.0.4/response.ts";

Constructors

new
Response(request: Request)

Index Signatures

[key: string]: any

Properties

body: any

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"';
readonly
header: Headers

Return response header, alias as response.header

headers: Headers

Headers that will be returned in the response.

lastModified: string | Date | undefined

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

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

message: string

Get response status message

status: number

Get/Set response status code.

type: string
readonly
writable

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

Methods

append(field: string, val: string | string[])

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');
attachment(filename?: string, options?: any)

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

flushHeaders(): void

Flush any set headers, and begin the body

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

Returns true if the header identified by name is currently set in the outgoing headers. The header name matching is case-insensitive.

Examples:

this.has('Content-Type');
// => true

this.get('content-type');
// => true
is(...types: string[] | string[][]): string | boolean | null

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

redirect(url: string, alt?: string)

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(field: string)
set(field: any, val?: any)

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

Take this response and convert it to the response used by the Deno net server. Calling this will set the response to not be writable.

Most users will have no need to call this method.

vary(field: string): void

Vary on field.