Skip to main content
Http2ServerRequest - node__http2.d.ts - Node documentation
class Http2ServerRequest
extends stream.Readable

Usage in Deno

```typescript import { Http2ServerRequest } from "node:node__http2.d.ts"; ```
A `Http2ServerRequest` object is created by Server or SecureServer and passed as the first argument to the `'request'` event. It may be used to access a request status, headers, and data.

Constructors

new
Http2ServerRequest(
options: stream.ReadableOptions,
rawHeaders: readonly string[],
)

Properties

readonly
aborted: boolean
The `request.aborted` property will be `true` if the request has been aborted.
readonly
authority: string
The request authority pseudo header field. Because HTTP/2 allows requests to set either `:authority` or `host`, this value is derived from `req.headers[':authority']` if present. Otherwise, it is derived from `req.headers['host']`.
readonly
complete: boolean
The `request.complete` property will be `true` if the request has been completed, aborted, or destroyed.
deprecated
readonly
connection: net.Socket | tls.TLSSocket
See `request.socket`.
The request/response headers object. Key-value pairs of header names and values. Header names are lower-cased. ```js // Prints something like: // // { 'user-agent': 'curl/7.22.0', // host: '127.0.0.1:8000', // accept: '*' } console.log(request.headers); ``` See `HTTP/2 Headers Object`. In HTTP/2, the request path, host name, protocol, and method are represented as special headers prefixed with the `:` character (e.g. `':path'`). These special headers will be included in the `request.headers` object. Care must be taken not to inadvertently modify these special headers or errors may occur. For instance, removing all headers from the request will cause errors to occur: ```js removeAllHeaders(request.headers); assert(request.url); // Fails because the :path header has been removed ```
readonly
httpVersion: string
In case of server request, the HTTP version sent by the client. In the case of client response, the HTTP version of the connected-to server. Returns `'2.0'`. Also `message.httpVersionMajor` is the first integer and `message.httpVersionMinor` is the second.
readonly
httpVersionMajor: number
readonly
httpVersionMinor: number
readonly
method: string
The request method as a string. Read-only. Examples: `'GET'`, `'DELETE'`.
readonly
rawHeaders: string[]
The raw request/response headers list exactly as they were received. The keys and values are in the same list. It is _not_ a list of tuples. So, the even-numbered offsets are key values, and the odd-numbered offsets are the associated values. Header names are not lowercased, and duplicates are not merged. ```js // Prints something like: // // [ 'user-agent', // 'this is invalid because there can be only one', // 'User-Agent', // 'curl/7.22.0', // 'Host', // '127.0.0.1:8000', // 'ACCEPT', // '*' ] console.log(request.rawHeaders); ```
readonly
rawTrailers: string[]
The raw request/response trailer keys and values exactly as they were received. Only populated at the `'end'` event.
readonly
scheme: string
The request scheme pseudo header field indicating the scheme portion of the target URL.
readonly
socket: net.Socket | tls.TLSSocket
Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but applies getters, setters, and methods based on HTTP/2 logic. `destroyed`, `readable`, and `writable` properties will be retrieved from and set on `request.stream`. `destroy`, `emit`, `end`, `on` and `once` methods will be called on `request.stream`. `setTimeout` method will be called on `request.stream.session`. `pause`, `read`, `resume`, and `write` will throw an error with code `ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for more information. All other interactions will be routed directly to the socket. With TLS support, use `request.socket.getPeerCertificate()` to obtain the client's authentication details.
The `Http2Stream` object backing the request.
The request/response trailers object. Only populated at the `'end'` event.
url: string
Request URL string. This contains only the URL that is present in the actual HTTP request. If the request is: ```http GET /status?name=ryan HTTP/1.1 Accept: text/plain ``` Then `request.url` will be: ```js '/status?name=ryan' ``` To parse the url into its parts, `new URL()` can be used: ```console $ node > new URL('/status?name=ryan', 'http://example.com') URL { href: 'http://example.com/status?name=ryan', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/status', search: '?name=ryan', searchParams: URLSearchParams { 'name' => 'ryan' }, hash: '' } ```

Methods

addListener(
event: "aborted",
listener: (
hadError: boolean,
code: number,
) => void
,
): this
addListener(
event: "close",
listener: () => void,
): this
addListener(
event: "data",
listener: (chunk: Buffer | string) => void,
): this
addListener(
event: "end",
listener: () => void,
): this
addListener(
event: "readable",
listener: () => void,
): this
addListener(
event: "error",
listener: (err: Error) => void,
): this
addListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
emit(
event: "aborted",
hadError: boolean,
code: number,
): boolean
emit(event: "close"): boolean
emit(
event: "data",
chunk: Buffer | string,
): boolean
emit(event: "end"): boolean
emit(event: "readable"): boolean
emit(
event: "error",
err: Error,
): boolean
emit(
event: string | symbol,
...args: any[],
): boolean
on(
event: "aborted",
listener: (
hadError: boolean,
code: number,
) => void
,
): this
on(
event: "close",
listener: () => void,
): this
on(
event: "data",
listener: (chunk: Buffer | string) => void,
): this
on(
event: "end",
listener: () => void,
): this
on(
event: "readable",
listener: () => void,
): this
on(
event: "error",
listener: (err: Error) => void,
): this
on(
event: string | symbol,
listener: (...args: any[]) => void,
): this
once(
event: "aborted",
listener: (
hadError: boolean,
code: number,
) => void
,
): this
once(
event: "close",
listener: () => void,
): this
once(
event: "data",
listener: (chunk: Buffer | string) => void,
): this
once(
event: "end",
listener: () => void,
): this
once(
event: "readable",
listener: () => void,
): this
once(
event: "error",
listener: (err: Error) => void,
): this
once(
event: string | symbol,
listener: (...args: any[]) => void,
): this
prependListener(
event: "aborted",
listener: (
hadError: boolean,
code: number,
) => void
,
): this
prependListener(
event: "close",
listener: () => void,
): this
prependListener(
event: "data",
listener: (chunk: Buffer | string) => void,
): this
prependListener(
event: "end",
listener: () => void,
): this
prependListener(
event: "readable",
listener: () => void,
): this
prependListener(
event: "error",
listener: (err: Error) => void,
): this
prependListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
prependOnceListener(
event: "aborted",
listener: (
hadError: boolean,
code: number,
) => void
,
): this
prependOnceListener(
event: "close",
listener: () => void,
): this
prependOnceListener(
event: "data",
listener: (chunk: Buffer | string) => void,
): this
prependOnceListener(
event: "end",
listener: () => void,
): this
prependOnceListener(
event: "readable",
listener: () => void,
): this
prependOnceListener(
event: "error",
listener: (err: Error) => void,
): this
prependOnceListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this
read(size?: number):
Buffer
| string
| null
setTimeout(
msecs: number,
callback?: () => void,
): void
Sets the `Http2Stream`'s timeout value to `msecs`. If a callback is provided, then it is added as a listener on the `'timeout'` event on the response object. If no `'timeout'` listener is added to the request, the response, or the server, then `Http2Stream`s are destroyed when they time out. If a handler is assigned to the request, the response, or the server's `'timeout'`events, timed out sockets must be handled explicitly.