Prosody IM Website


file doc/developers/net/http_request_object.md in changeset be6638f8b123

View latest ↓ Download file

line wrap: on
line source

---
title: The HTTP request object
---

The request object contains the following fields:

# request.conn {#requestconn}

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

# request.handler {#requesthandler}

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

# request.write() {#requestwrite}

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

# request.host {#requesthost}

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

# request.port {#requestport}

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

# request.path {#requestpath}

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

# request.query {#requestquery}

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 {#requestonlystatus}

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

# request.method {#requestmethod}

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 {#requestcallback}

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

# request.reader {#requestreader}

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 {#requeststate}

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

# request.destroyed {#requestdestroyed}

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 {#requestbody}

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

# request.bodylength {#requestbodylength}

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 {#requesthavebodylength}

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

# request.responseheaders {#requestresponseheaders}

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 {#requestcode}

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

# request.responseversion {#requestresponseversion}

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