The HTTP request object

The request object contains the following fields:

request.conn

The low-level socket used for communicating with the HTTP server. May be nil if the connection has been closed.

request.handler

A slightly higher-level connection object, usually you will want to interact with this rather than conn.

request.write()

A simple function to write data to the request's underlying connection.

request.host

The HTTP server's hostname parsed from the URL passed to http.request().

request.port

The port used to connect to the HTTP server. Automatically parsed from the URL passed to http.request().

request.path

The path to the file to request from the HTTP server, automatically parsed from the URL passed to http.request().

request.query

The query part of the URL passed to http.request(). That is, any part of the URL after the '?' character appears in the path.

request.onlystatus

The caller set options.onlystatus to indicate that they are only interested in the status code of this request.

request.method

The method used by this request. Note! For efficiency the method always has a space after it. eg. "GET " and "POST ". Removing this space will cause requests to be rejected by the HTTP server.

request.callback

The callback for the request, as passed to http.request().

request.reader

An object which receives the raw data from the HTTP server, parses it, and is responsible for calling the callback when the full response is received.

request.state

An internal state variable recording what "mode" the request reader is in.

request.destroyed

A flag set to true if the request has been destroyed. Callbacks will no longer be called for this request. Don't set this flag manually… use http.destroy_request() if you must (it is usually done for you).

request.body

An array of strings, which when joined comprise the total response body received from the server so far.

request.bodylength

The anticipated response body length, when complete. As seen in the Content-Length header. May be nil if the server did not specify a Content-Length.

request.havebodylength

The current length of the received body part of the HTTP response.

request.responseheaders

A table of the headers received in the HTTP response from the server. All keys are lower-cased, eg. request.responseheaders["content-length"].

request.code

The HTTP status code received from the server. A number, not a string.

request.responseversion

The HTTP version given by the server in its response. Usually "1.0" or "1.1". A string, not a number.

 
doc/developers/net/http_request_object.txt · Last modified: 2009/12/20 17:43 (external edit)