Splash assumes that most strings in a script are encoded to UTF-8.
This is true for HTML content - even if the original response was not UTF-8,
internally browser works with UTF-8, so splash:html result is always
UTF-8.

When you return a Lua table from the main function Splash encodes it
to JSON; JSON is a text protocol which can’t handle arbitrary binary data,
so Splash assumes all strings are UTF-8 when returning a JSON result.

But sometimes it is necessary to work with binary data: for example,
it could be raw image data returned by splash:png or a response
body of a non-UTF-8 page returned by splash:http_get.

All binary objects have content-type attached. For example, splash:png
result will have content-type image/png.

When returned directly, a binary object data is used as-is for the
response body, and Content-Type HTTP header is set to the content-type
of a binary object. So in the previous example the result will be a PNG image
with a proper Content-Type header.

To construct your own binary objects use treat.as_binary function.
For example, let’s return a 1x1px black GIF image as a response:

When main result is returned, binary object content-type takes a priority
over a value set by splash:set_result_content_type. To override
content-type of a binary object create another binary object with a required
content-type: