Skip to main content

httpresponse.send(statusCode, responseBody)

Issues the response to an incoming HTTP request




Name Type Description
statusCode Integer A valid HTTP status code
responseBody String The response body, if any




This method dispatches a reply to an incoming HTTP request. Any valid HTTP status code can be returned, but the most common one is 200, for “OK”. It is possible to really confuse the client by sending peculiar ones.

The body can be any string, but most clients will expect the contents to match that indicated by the Content-Type header, which can be added using httpresponse.header().

The Content-Length header is set automatically.

The connection between the source of the HTTP request and the agent remains open until the agent responds by calling the appropriate httpresponse object’s send() method.

Example Code

This code shows a typical HTTP request handler which modifies the automatically generated HTTP response and then sends the response back to the source of the original request.