Http2ServerResponse
This object is created internally by an HTTP server, not by the user. It is passed as the second parameter to the 'request'
event.
Since
v8.4.0
Properties
See response.socket
.
True if headers were sent, false otherwise (read-only).
Is true
if it is safe to call writable.write()
, which means the stream has not been destroyed, errored, or ended.
A reference to the original HTTP2 request
object.
When using implicit headers (not calling response.writeHead()
explicitly), this property controls the status code that will be sent to the client when the headers get flushed.
Status message is not supported by HTTP/2 (RFC 7540 8.1.2.4). It returns an empty string.
The Http2Stream
object backing the response.
Number of times writable.uncork()
needs to be called in order to fully uncork the stream.
Is true
after writable.end()
has been called. This property does not indicate whether the data has been flushed, for this use writable.writableFinished
instead.
Is set to true
immediately before the 'finish'
event is emitted.
Return the value of highWaterMark
passed when creating this Writable
.
This property contains the number of bytes (or objects) in the queue ready to be written. The value provides introspection data regarding the status of the highWaterMark
.
Is true
if the stream's buffer has been full and stream will emit 'drain'
.
Getter for the property objectMode
of a given Writable
stream.
Functions
Event emitter The defined events on documents including:
This method adds HTTP trailing headers (a header but at the end of the message) to the response.
Append a single header value to the header object.
Call http2stream.pushStream()
with the given headers, and wrap the given Http2Stream
on a newly created Http2ServerResponse
as the callback parameter if successful. When Http2ServerRequest
is closed, the callback is called with an error ERR_HTTP2_INVALID_STREAM
.
Destroy the stream. Optionally emit an 'error'
event, and emit a 'close'
event (unless emitClose
is set to false
). After this call, the writable stream has ended and subsequent calls to write()
or end()
will result in an ERR_STREAM_DESTROYED
error. This is a destructive and immediate way to destroy a stream. Previous calls to write()
may not have drained, and may trigger an ERR_STREAM_DESTROYED
error. Use end()
instead of destroy if data should flush before close, or wait for the 'drain'
event before destroying the stream.
This method signals to the server that all of the response headers and body have been sent; that server should consider this message complete. The method, response.end()
, MUST be called on each response.
Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbol
s.
Returns an array containing the unique names of the current outgoing headers. All header names are lowercase.
Returns a shallow copy of the current outgoing headers. Since a shallow copy is used, array values may be mutated without additional calls to various header-related http module methods. The keys of the returned object are the header names and the values are the respective header values. All header names are lowercase.
Returns the current max listener value for the EventEmitter
which is either set by emitter.setMaxListeners(n)
or defaults to {@link defaultMaxListeners}.
Removes a header that has been queued for implicit sending.
The writable.setDefaultEncoding()
method sets the default encoding
for a Writable
stream.
Sets a single header value for implicit headers. If this header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings here to send multiple headers with the same name.
By default EventEmitter
s will print a warning if more than 10
listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners()
method allows the limit to be modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
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 this method is called and response.writeHead()
has not been called, it will switch to implicit header mode and flush the implicit headers.
The writable.write()
method writes some data to the stream, and calls the supplied callback
once the data has been fully handled. If an error occurs, the callback
will be called with the error as its first argument. The callback
is called asynchronously and before 'error'
is emitted.
Sends a status 100 Continue
to the client, indicating that the request body should be sent. See the 'checkContinue'
event on Http2Server
and Http2SecureServer
.
Sends a status 103 Early Hints
to the client with a Link header, indicating that the user agent can preload/preconnect the linked resources. The hints
is an object containing the values of headers to be sent with early hints message.
Sends a response header to the request. The status code is a 3-digit HTTP status code, like 404
. The last argument, headers
, are the response headers.