This object is created internally by an HTTP server — not by the user. It is passed as the second parameter to the 'request' event.

Variables

read onlyconnection:Socket

See socket.

read onlyfinished:Bool

The finished property will be true if end() has been called.

read onlyheadersSent:Bool

Boolean (read-only). True if headers were sent, false otherwise.

sendDate:Bool

When true, the Date header will be automatically generated and sent in the response if it is not already present in the headers. Defaults to true.

This should only be disabled for testing; HTTP requires the Date header in responses.

read onlysocket:Socket

Reference to the underlying socket. Usually users will not want to access this property. In particular, the socket will not emit 'readable' events because of how the protocol parser attaches to the socket. After end(), the property is nulled. The socket may also be accessed via connection.

statusCode:Int

When using implicit headers (not calling writeHead explicitly), this property controls the status code that will be sent to the client when the headers get flushed.

After response header was sent to the client, this property indicates the status code which was sent out.

statusMessage:String

When using implicit headers (not calling writeHead() explicitly), this property controls the status message that will be sent to the client when the headers get flushed. If this is left as undefined then the standard message for the status code will be used.

After response header was sent to the client, this property indicates the status message which was sent out.

Methods

addTrailers(headers:DynamicAccess<String>):Void

addTrailers(headers:Array<Array<String>>):Void

This method adds HTTP trailing headers (a header but at the end of the message) to the response.

Trailers will only be emitted if chunked encoding is used for the response; if it is not (e.g., if the request was HTTP/1.0), they will be silently discarded.

Note that HTTP requires the 'Trailer' header to be sent if you intend to emit trailers, with a list of the header fields in its value.

flushHeaders():Void

Flushes the response headers. See also: request.flushHeaders().

getHeader(name:String):EitherType<String, Array<String>>

Reads out a header that's already been queued but not sent to the client. The name is case-insensitive. The type of the return value depends on the arguments provided to setHeader().

getHeaderNames():Array<String>

Returns an array containing the unique names of the current outgoing headers. All header names are lowercase.

getHeaders():DynamicAccess<EitherType<String, Array<String>>>

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.

The object returned by the getHeaders() method does not prototypically inherit from the JavaScript Object. This means that typical Object methods such as obj.toString(), obj.hasOwnProperty(), and others are not defined and will not work.

hasHeader(name:String):Bool

Returns true if the header identified by name is currently set in the outgoing headers. The header name matching is case-insensitive.

removeHeader(name:String):Void

Removes a header that's queued for implicit sending.

setHeader(name:String, value:String):Void

setHeader(name:String, value:Array<String>):Void

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. Non-string values will be stored without modification. Therefore, getHeader() may return non-string values. However, the non-string values will be converted to strings for network transmission.

setTimeout(msecs:Int, ?callback:() ‑> Void):Void

Sets the Socket'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 sockets 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.

writeContinue():Void

Sends a HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent. See the 'checkContinue' event on Server.

writeHead(statusCode:Int, reasonPhrase:String, ?headers:DynamicAccess<String>):Void

writeHead(statusCode:Int, ?headers:DynamicAccess<String>):Void

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. Optionally one can give a human-readable statusMessage as the second argument.

This method must only be called once on a message and it must be called before end() is called.

If write() or end() are called before calling this, the implicit/mutable headers will be calculated and call this function.

When headers have been set with setHeader(), they will be merged with any headers passed to writeHead(), with the headers passed to writeHead() given precedence.

If this method is called and setHeader() has not been called, it will directly write the supplied header values onto the network channel without caching internally, and the getHeader() on the header will not yield the expected result. If progressive population of headers is desired with potential future retrieval and modification, use setHeader() instead.

Content-Length is given in bytes not characters. The above example works because the string 'hello world' contains only single byte characters. If the body contains higher coded characters then Buffer.byteLength() should be used to determine the number of bytes in a given encoding. And Node.js does not check whether Content-Length and the length of the body which has been transmitted are equal or not.

Attempting to set a header field name or value that contains invalid characters will result in a TypeError being thrown.

writeProcessing():Void

Sends a HTTP/1.1 102 Processing message to the client, indicating that the request body should be sent.

Inherited Variables

Defined by Writable

read onlydestroyed:Bool

Is true after writable.destroy() has been called.

See also:

read onlyisTTY:Bool

Terminal write streams (i.e. process.stdout) have this property set to true. It is false for any other write streams.

See also:

read onlywritable:Bool

Is true if it is safe to call writable.write().

See also:

read onlywritableEnded:Bool

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.

See also:

read onlywritableFinished:Bool

Is set to true immediately before the 'finish' event is emitted.

See also:

read onlywritableLength:Int

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.

See also:

read onlywritableObjectMode:Bool

Getter for the property objectMode of a given Writable stream.

See also:

read onlywritablehighWaterMark:Int

Return the value of highWaterMark passed when constructing this Writable.

See also:

Inherited Methods

Defined by Writable

cork():Void

The writable.cork() method forces all written data to be buffered in memory. The buffered data will be flushed when either the stream.uncork() or stream.end() methods are called.

See also:

destroy(?error:Error):TSelf

Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event unless emitClose is set in 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. Implementors should not override this method, but instead implement writable._destroy().

See also:

end(chunk:Dynamic, ?encoding:String, ?callback:EitherType<() ‑> Void, Null<Error> ‑> Void>):Void

end(?callback:EitherType<() ‑> Void, Null<Error> ‑> Void>):Void

Calling the writable.end() method signals that no more data will be written to the Writable. The optional chunk and encoding arguments allow one final additional chunk of data to be written immediately before closing the stream. If provided, the optional callback function is attached as a listener for the 'finish' event.

See also:

setDefaultEncoding(encoding:String):TSelf

The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.

See also:

uncork():Void

The writable.uncork() method flushes all data buffered since stream.cork() was called.

See also:

write(chunk:Dynamic, ?encoding:String, ?callback:EitherType<() ‑> Void, Null<Error> ‑> Void>):Bool

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 may or may not be called with the error as its first argument. To reliably detect write errors, add a listener for the 'error' event.

See also:

Defined by EventEmitter

addListener<T>(eventName:Event<T>, listener:T):TSelf

emit<T>(eventName:Event<T>, args:Rest<Dynamic>):Bool

Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.

See also:

eventNames():Array<EitherType<String, Symbol>>

Returns an array listing the events for which the emitter has registered listeners. The values in the array will be strings or Symbols.

See also:

getMaxListeners():Int

Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to EventEmitter.defaultMaxListeners.

See also:

listenerCount<T>(eventName:Event<T>):Int

Returns the number of listeners listening to the event named eventName.

See also:

listeners<T>(eventName:Event<T>):Array<T>

Returns a copy of the array of listeners for the event named eventName.

See also:

off<T>(eventName:Event<T>, listener:T):TSelf

on<T>(eventName:Event<T>, listener:T):TSelf

Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

See also:

once<T>(eventName:Event<T>, listener:T):TSelf

Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

See also:

prependListener<T>(eventName:Event<T>, listener:T):TSelf

Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

See also:

prependOnceListener<T>(eventName:Event<T>, listener:T):TSelf

Adds a one-time listener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

See also:

rawListeners<T>(eventName:Event<T>):Array<T>

Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

See also:

removeAllListeners<T>(?eventName:Event<T>):TSelf

Removes all listeners, or those of the specified eventName.

See also:

removeListener<T>(eventName:Event<T>, listener:T):TSelf

Removes the specified listener from the listener array for the event named eventName.

See also:

setMaxListeners(n:Int):Void

By default EventEmitters 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. Obviously, not all events should be limited to just 10 listeners. 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.

See also: