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 Jump to heading
Jump to headingHttp2ServerRequest(stream: ServerHttp2Stream,headers: IncomingHttpHeaders,options: stream.ReadableOptions,rawHeaders: readonly string[],)Properties Jump to heading
Jump to headingaborted: booleanThe request.aborted property will be true if the request has
been aborted.
Jump to headingauthority: stringThe 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'].
Jump to headingcomplete: booleanThe request.complete property will be true if the request has
been completed, aborted, or destroyed.
Jump to headingconnection: net.Socket | tls.TLSSocketSee request.socket.
The request/response headers object.
Key-value pairs of header names and values. Header names are lower-cased.
// 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:
removeAllHeaders(request.headers);
assert(request.url); // Fails because the :path header has been removed
Jump to headinghttpVersion: stringIn 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.
Jump to headinghttpVersionMajor: numberJump to headinghttpVersionMinor: numberJump to headingmethod: stringThe request method as a string. Read-only. Examples: 'GET', 'DELETE'.
Jump to headingrawHeaders: 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.
// 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);
Jump to headingrawTrailers: string[]The raw request/response trailer keys and values exactly as they were
received. Only populated at the 'end' event.
Jump to headingscheme: stringThe request scheme pseudo header field indicating the scheme portion of the target URL.
Jump to headingsocket: net.Socket | tls.TLSSocketReturns 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.
Jump to headingstream: ServerHttp2StreamThe Http2Stream object backing the request.
The request/response trailers object. Only populated at the 'end' event.
Jump to headingurl: stringRequest URL string. This contains only the URL that is present in the actual HTTP request. If the request is:
GET /status?name=ryan HTTP/1.1
Accept: text/plain
Then request.url will be:
'/status?name=ryan'
To parse the url into its parts, new URL() can be used:
$ 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 Jump to heading
Jump to headingaddListener(event: "aborted",listener: (hadError: boolean,code: number,) => void,): thisJump to headingaddListener(event: "close",listener: () => void,): thisJump to headingaddListener(event: "data",listener: (chunk: Buffer | string) => void,): thisJump to headingaddListener(event: "end",listener: () => void,): thisJump to headingaddListener(event: "readable",listener: () => void,): thisJump to headingaddListener(event: "error",listener: (err: Error) => void,): thisJump to headingaddListener(event: string | symbol,listener: (...args: any[]) => void,): thisJump to headingemit(event: "aborted",hadError: boolean,code: number,): booleanJump to headingemit(event: "close"): booleanJump to headingemit(event: "data",chunk: Buffer | string,): booleanJump to headingemit(event: "end"): booleanJump to headingemit(event: "readable"): booleanJump to headingemit(event: "error",err: Error,): booleanJump to headingemit(event: string | symbol,...args: any[],): booleanJump to headingon(event: "aborted",listener: (hadError: boolean,code: number,) => void,): thisJump to headingon(event: "close",listener: () => void,): thisJump to headingon(event: "data",listener: (chunk: Buffer | string) => void,): thisJump to headingon(event: "end",listener: () => void,): thisJump to headingon(event: "readable",listener: () => void,): thisJump to headingon(event: "error",listener: (err: Error) => void,): thisJump to headingon(event: string | symbol,listener: (...args: any[]) => void,): thisJump to headingonce(event: "aborted",listener: (hadError: boolean,code: number,) => void,): thisJump to headingonce(event: "close",listener: () => void,): thisJump to headingonce(event: "data",listener: (chunk: Buffer | string) => void,): thisJump to headingonce(event: "end",listener: () => void,): thisJump to headingonce(event: "readable",listener: () => void,): thisJump to headingonce(event: "error",listener: (err: Error) => void,): thisJump to headingonce(event: string | symbol,listener: (...args: any[]) => void,): thisJump to headingprependListener(event: "aborted",listener: (hadError: boolean,code: number,) => void,): thisJump to headingprependListener(event: "close",listener: () => void,): thisJump to headingprependListener(event: "data",listener: (chunk: Buffer | string) => void,): thisJump to headingprependListener(event: "end",listener: () => void,): thisJump to headingprependListener(event: "readable",listener: () => void,): thisJump to headingprependListener(event: "error",listener: (err: Error) => void,): thisJump to headingprependListener(event: string | symbol,listener: (...args: any[]) => void,): thisJump to headingprependOnceListener(event: "aborted",listener: (hadError: boolean,code: number,) => void,): thisJump to headingprependOnceListener(event: "close",listener: () => void,): thisJump to headingprependOnceListener(event: "data",listener: (chunk: Buffer | string) => void,): thisJump to headingprependOnceListener(event: "end",listener: () => void,): thisJump to headingprependOnceListener(event: "readable",listener: () => void,): thisJump to headingprependOnceListener(event: "error",listener: (err: Error) => void,): thisJump to headingprependOnceListener(event: string | symbol,listener: (...args: any[]) => void,): thisJump to headingread(size?: number): Buffer
| string
| nullJump to headingsetTimeout(msecs: number,callback?: () => void,): voidSets 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 Http2Streams 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.