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: boolean
The request.aborted
property will be true
if the request has
been aborted.
Jump to headingauthority: 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']
.
Jump to headingcomplete: boolean
The request.complete
property will be true
if the request has
been completed, aborted, or destroyed.
Jump to headingconnection: 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.
// 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: 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.
Jump to headinghttpVersionMajor: number
Jump to headinghttpVersionMinor: number
Jump to headingmethod: string
The 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: string
The request scheme pseudo header field indicating the scheme portion of the target URL.
Jump to headingsocket: 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.
Jump to headingstream: ServerHttp2Stream
The Http2Stream
object backing the request.
The request/response trailers object. Only populated at the 'end'
event.
Jump to headingurl: string
Request 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,): this
Jump to headingaddListener(event: "close",listener: () => void,): this
Jump to headingaddListener(event: "data",listener: (chunk: Buffer | string) => void,): this
Jump to headingaddListener(event: "end",listener: () => void,): this
Jump to headingaddListener(event: "readable",listener: () => void,): this
Jump to headingaddListener(event: "error",listener: (err: Error) => void,): this
Jump to headingaddListener(event: string | symbol,listener: (...args: any[]) => void,): this
Jump to headingemit(event: "aborted",hadError: boolean,code: number,): boolean
Jump to headingemit(event: "close"): boolean
Jump to headingemit(event: "data",chunk: Buffer | string,): boolean
Jump to headingemit(event: "end"): boolean
Jump to headingemit(event: "readable"): boolean
Jump to headingemit(event: "error",err: Error,): boolean
Jump to headingemit(event: string | symbol,...args: any[],): boolean
Jump to headingon(event: "aborted",listener: (hadError: boolean,code: number,) => void,): this
Jump to headingon(event: "close",listener: () => void,): this
Jump to headingon(event: "data",listener: (chunk: Buffer | string) => void,): this
Jump to headingon(event: "end",listener: () => void,): this
Jump to headingon(event: "readable",listener: () => void,): this
Jump to headingon(event: "error",listener: (err: Error) => void,): this
Jump to headingon(event: string | symbol,listener: (...args: any[]) => void,): this
Jump to headingonce(event: "aborted",listener: (hadError: boolean,code: number,) => void,): this
Jump to headingonce(event: "close",listener: () => void,): this
Jump to headingonce(event: "data",listener: (chunk: Buffer | string) => void,): this
Jump to headingonce(event: "end",listener: () => void,): this
Jump to headingonce(event: "readable",listener: () => void,): this
Jump to headingonce(event: "error",listener: (err: Error) => void,): this
Jump to headingonce(event: string | symbol,listener: (...args: any[]) => void,): this
Jump to headingprependListener(event: "aborted",listener: (hadError: boolean,code: number,) => void,): this
Jump to headingprependListener(event: "close",listener: () => void,): this
Jump to headingprependListener(event: "data",listener: (chunk: Buffer | string) => void,): this
Jump to headingprependListener(event: "end",listener: () => void,): this
Jump to headingprependListener(event: "readable",listener: () => void,): this
Jump to headingprependListener(event: "error",listener: (err: Error) => void,): this
Jump to headingprependListener(event: string | symbol,listener: (...args: any[]) => void,): this
Jump to headingprependOnceListener(event: "aborted",listener: (hadError: boolean,code: number,) => void,): this
Jump to headingprependOnceListener(event: "close",listener: () => void,): this
Jump to headingprependOnceListener(event: "data",listener: (chunk: Buffer | string) => void,): this
Jump to headingprependOnceListener(event: "end",listener: () => void,): this
Jump to headingprependOnceListener(event: "readable",listener: () => void,): this
Jump to headingprependOnceListener(event: "error",listener: (err: Error) => void,): this
Jump to headingprependOnceListener(event: string | symbol,listener: (...args: any[]) => void,): this
Jump to headingread(size?: number): Buffer
| string
| null
Jump to headingsetTimeout(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.