Skip to content

Latest commit

 

History

History
108 lines (65 loc) · 2.29 KB

scripting-response-object.rst

File metadata and controls

108 lines (65 loc) · 2.29 KB

Response Object

Response objects are returned as a result of several Splash methods (like :ref:`splash-http-get` or :ref:`splash-http-post`); they are are also passed to some of the callbacks (e.g. :ref:`splash-on-response` and :ref:`splash-on-response-headers` callbacks). These objects contain information about a response.

response.url

URL of the response. In case of redirects :ref:`splash-response-url` is a last URL.

This field is read-only.

response.status

HTTP status code of the response.

This field is read-only.

response.ok

true for successful responses and false when error happened.

Example:

local reply = splash:http_get("some-bad-url")
-- reply.ok == false

This field is read-only.

response.headers

A Lua table with HTTP headers (header name => header value). Keys are header names (strings), values are header values (strings).

Lookups are case-insensitive, so response.headers['content-type'] is the same as response.headers['Content-Type'].

This field is read-only.

response.info

A Lua table with response data in HAR response format.

This field is read-only.

response.body

Raw response body (a :ref:`binary object <binary-objects>`).

If you want to process response body from Lua use :ref:`treat-as-string` to convert it to a Lua string first.

:ref:`splash-response-body` attribute is not available by default in :ref:`splash-on-response` callbacks; use :ref:`splash-response-body-enabled` or :ref:`splash-request-enable-response-body` to enable it.

response.request

A corresponding :ref:`splash-request`.

This field is read-only.

response:abort

Signature: response:abort()

Returns: nil.

Async: no.

Abort reading of the response body. This method is only available if a response is not read yet - currently you can use it only in a :ref:`splash-on-response-headers` callback.