Represents a server response.
Callback to be used when the response is finished. See the
endevent on the
Chains the response given as a parameter to the current
object. This means that as data is written to the current
object, that same data will be written in the parameter (ie. it
honours and replicates streaming). It's similar to
but with the following differences:
chainis called on the source object, not the target.
chainis to be used before any data is written to the source object.
chainwill write data as it's received, instead of everything at once.
Response object to chain to the current object.
Copies the response given as a parameter into the current response object. This is intended to be used when the response given as a parameter is already finished.
Response object to copy.
Marks the response as complete and calls the 'end' callback. When called in the response object provided by RoboHydra, this closes the connection.
Follows the given response: as data is written to the given
response object, that same data will be written in the calling
object (ie. it honours and replicates streaming). It's similar
copyFrom, but with the following differences:
followis to be used before any data is written to the source object (ie. the parameter).
followwill write data as it is received, instead of everything at once.
Response object to follow.
Forwards the response given as a parameter. That is, copies the given response in the current object, then marks the given object as finished.
The response object to forward.
Adds a callback to the given event. An event can have more than one callback. All callbacks for an event will be called in order when the event is triggered.
The callback function will receive a single parameter,
an object with the property
type set to the event type, plus
different properties according to the event fired. It returns
the response object.
The list of response object events is:
head: Fired when the header is written. Event objects for this event contain two properties,
data: Fired when there is data written in the response object. Event objects for this event contain a single property,
data, an instance of
end: Fired when the response is finished. Event objects for this event contain a single property,
response, the response object that fired the event.
For responses you have created yourself to pass to the
end event would typically be used to inspect or
modify the response contents, then write data to the response
object you received, possibly with the help of the methods
The name of the event to attach the callback to. Possible event names are
The callback to attach to the given event.
Appends the given data to the response body and closes
it. Equivalent to calling the
write method, then
to add to the response body.
Appends data to the response body. This method allows a RoboHydra head to write the response body in chunks, and the response will be sent in chunks to the client (so you could, say, send data, then wait, then send more data, wait, then close the connection).
Data to add to the current response body. This parameter can be a string, too.
Sets and writes the response headers.
The response's status code.
The response's headers.