app
: The presser_app
object itself.
req
: The request object.
headers_sent
: Whether the response headers were already sent out.
locals
: Local variables, the are shared between the handler
functions. This is for the end user, and not for the middlewares.
delay(secs)
: delay the response for a number of seconds. If a
handler calls delay()
, the same handler will be called again,
after the specified number of seconds have passed. Use the locals
environment to distinguish between the calls. If you are using
delay()
, and want to serve requests in parallel, then you probably
need a multi-threaded server, see server_opts()
.
add_header(field, value)
: Add a response header. Note that
add_header()
may create duplicate headers. You usually want
set_header()
.
get_header(field)
: Query the currently set response headers. If
field
is not present it return NULL
.
on_response(fun)
: Run the fun
handler function just before the
response is sent out. At this point the headers and the body are
already properly set.
redirect(path, status = 302)
: Send a redirect response. It sets
the Location
header, and also sends a text/plain
body.
render(view, locals = list())
: Render a template page. Searches
for the view
template page, using all registered engine extensions,
and calls the first matching template engine. Returns the filled
template.
send(body)
. Send the specified body. body
can be a raw vector,
or HTML or other text. For raw vectors it sets the content type to
application/octet-stream
.
send_json(object = NULL, text = NULL, ...)
: Send a JSON response.
Either object
or text
must be given. object
will be converted
to JSON using jsonlite::toJSON()
. ...
are passed to
jsonlite::toJSON()
. It sets the content type appropriately.
send_file(path, root = ".")
: Send a file. Set root = "/"
for
absolute file names. It sets the content type automatically, based
on the extension of the file, if it is not set already.
send_status(status)
: Send the specified HTTP status code, without
a response body.
send_chunk(data)
: Send a chunk of a response in chunked encoding.
The first chunk will automatically send the HTTP response headers.
Presser will automatically send a final zero-lengh chunk, unless
$delay()
is called.
set_header(field, value)
: Set a response header. If the headers have
been sent out already, then it throws a warning, and does nothing.
set_status(status)
: Set the response status code. If the headers
have been sent out already, then it throws a warning, and does nothing.
set_type(type)
: Set the response content type. If it contains a /
character then it is set as is, otherwise it is assumed to be a file
extension, and the corresponding MIME type is set. If the headers have
been sent out already, then it throws a warning, and does nothing.
write(data)
: writes (part of) the body of the response. It also
sends out the response headers, if they haven't been sent out before.