Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/scripting-ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2222,6 +2222,28 @@ By default, this ``response`` object doesn't have :ref:`splash-response-body`
attribute. To enable it, use :ref:`splash-response-body-enabled` option
or :ref:`splash-request-enable-response-body` method.

Example 1 - to log a response body only when requested url match a desired pattern:

.. code-block:: lua

treat = require('treat')
function main(splash, args)
splash.resource_timeout = 10.0
splash:on_request(function(request)
if string.find(request.url, "hello") ~= nil then
request.enable_response_body()
end
end)
splash:on_response(function(response)
if string.find(response.url, "hello") ~= nil then
s, content_type = treat.as_string(response.body)
end
end)

assert(splash:go(splash.args.url))
return s
end

.. note::

:ref:`splash-on-response` doesn't support named arguments.
Expand Down