Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Request

import { Request } from "https://raw.githubusercontent.com/oakserver/oak/master/request.ts";

An interface which provides information about the current request. The instance related to the current request is available on the {@link Context}'s .request property.

The interface contains several properties to get information about the request as well as several methods, which include content negotiation and the ability to decode a request body.

class Request {
constructor(serverRequest: ServerRequest, { proxy, secure, jsonBodyReviver }?: OakRequestOptions);
get body(): Body;
get hasBody(): boolean;
get headers(): Headers;
get ip(): string;
get ips(): string[];
get method(): HTTPMethods;
get secure(): boolean;
get originalRequest(): ServerRequest;
get source(): globalThis.Request | undefined;
get url(): URL;
get userAgent(): UserAgent;
 
accepts(): string[] | undefined;
accepts(...types: string[]): string | undefined;
accepts(...types: string[]): string | string[] | undefined;
acceptsEncodings(): string[] | undefined;
acceptsEncodings(...encodings: string[]): string | undefined;
acceptsEncodings(...encodings: string[]): string[] | string | undefined;
acceptsLanguages(): string[] | undefined;
acceptsLanguages(...langs: string[]): string | undefined;
acceptsLanguages(...langs: string[]): string[] | string | undefined;
async sendEvents(options?: ServerSentEventTargetOptions, init?: RequestInit): Promise<ServerSentEventTarget>;
upgrade(options?: UpgradeWebSocketOptions): WebSocket;
[Symbol.for("Deno.customInspect")](inspect: (value: unknown) => string): string;
[Symbol.for("nodejs.util.inspect.custom")](
depth: number,
options: any,
inspect: (value: unknown, options?: unknown) => string,
): any;
}

§Constructors

§
new Request(serverRequest: ServerRequest, { proxy, secure, jsonBodyReviver }?: OakRequestOptions)
[src]

§Properties

§
body: Body readonly
[src]

An interface to access the body of the request. This provides an API that aligned to the Fetch Request API, but in a dedicated API.

§
hasBody: boolean readonly
[src]

Is true if the request might have a body, otherwise false.

WARNING this is an unreliable API. In HTTP/2 in many situations you cannot determine if a request has a body or not unless you attempt to read the body, due to the streaming nature of HTTP/2. As of Deno 1.16.1, for HTTP/1.1, Deno also reflects that behaviour. The only reliable way to determine if a request has a body or not is to attempt to read the body.

§
headers: Headers readonly
[src]

The Headers supplied in the request.

§
ip: string readonly
[src]

Request remote address. When the application's .proxy is true, the X-Forwarded-For will be used to determine the requesting remote address.

§
ips: string[] readonly
[src]

When the application's .proxy is true, this will be set to an array of IPs, ordered from upstream to downstream, based on the value of the header X-Forwarded-For. When false an empty array is returned.

§
method: HTTPMethods readonly
[src]

The HTTP Method used by the request.

§
secure: boolean readonly
[src]

Shortcut to request.url.protocol === "https:".

§
originalRequest: ServerRequest readonly deprecated
[src]

Set to the value of the low level oak server request abstraction.

@deprecated

this will be removed in future versions of oak. Accessing this abstraction is not useful to end users and is now a bit of a misnomer.

§
source: globalThis.Request | undefined readonly
[src]

Returns the original Fetch API Request if available.

This should be set with requests on Deno, but will not be set when running on Node.js.

§
url: URL readonly
[src]

A parsed URL for the request which complies with the browser standards. When the application's .proxy is true, this value will be based off of the X-Forwarded-Proto and X-Forwarded-Host header values if present in the request.

§
userAgent: UserAgent readonly
[src]

An object representing the requesting user agent. If the User-Agent header isn't defined in the request, all the properties will be undefined.

See std/http/user_agent#UserAgent for more information.

§Methods

§
accepts(): string[] | undefined
[src]

Returns an array of media types, accepted by the requestor, in order of preference. If there are no encodings supplied by the requestor, then accepting any is implied is returned.

accepts(...types: string[]): string | undefined
[src]

For a given set of media types, return the best match accepted by the requestor. If there are no encoding that match, then the method returns undefined.

accepts(...types: string[]): string | string[] | undefined
[src]
§
acceptsEncodings(): string[] | undefined
[src]

Returns an array of encodings, accepted by the requestor, in order of preference. If there are no encodings supplied by the requestor, then ["*"] is returned, matching any.

acceptsEncodings(...encodings: string[]): string | undefined
[src]

For a given set of encodings, return the best match accepted by the requestor. If there are no encodings that match, then the method returns undefined.

NOTE: You should always supply identity as one of the encodings to ensure that there is a match when the Accept-Encoding header is part of the request.

acceptsEncodings(...encodings: string[]): string[] | string | undefined
[src]
§
acceptsLanguages(): string[] | undefined
[src]

Returns an array of languages, accepted by the requestor, in order of preference. If there are no languages supplied by the requestor, ["*"] is returned, indicating any language is accepted.

acceptsLanguages(...langs: string[]): string | undefined
[src]

For a given set of languages, return the best match accepted by the requestor. If there are no languages that match, then the method returns undefined.

acceptsLanguages(...langs: string[]): string[] | string | undefined
[src]
§
sendEvents(options?: ServerSentEventTargetOptions, init?: RequestInit): Promise<ServerSentEventTarget>
[src]

Take the current request and initiate server sent event connection.

![WARNING] This is not intended for direct use, as it will not manage the target in the overall context or ensure that additional middleware does not attempt to respond to the request.

§
upgrade(options?: UpgradeWebSocketOptions): WebSocket
[src]

Take the current request and upgrade it to a web socket, returning a web standard WebSocket object.

If the underlying server abstraction does not support upgrades, this will throw.

![WARNING] This is not intended for direct use, as it will not manage the websocket in the overall context or ensure that additional middleware does not attempt to respond to the request.

§
[Symbol.for("Deno.customInspect")](inspect: (value: unknown) => string): string
[src]
§
[Symbol.for("nodejs.util.inspect.custom")](depth: number, options: any, inspect: (value: unknown, options?: unknown) => string): any
[src]