Rook (version 1.1-1)

Response-class: Class Response

Description

A convenience class for creating Rook responses.

Arguments

Methods

header(key, value):

Sets an HTTP header for the response. Both key and value must be character strings. If value is missing, then the header value is returned.

redirect(target, status=302):

Sets up an HTTP redirect to the target url.

write(str):

Takes a character vector and appends it to the response body.

new(body='', status=200, headers=list()):

Create a new Response object. body is a character vector, status is an HTTP status value. headers is a named list.

set_cookie(key, value):

Sets an HTTP cookie for the response. Both key and value must be character strings.

delete_cookie(key, value):

Sends appropriate HTTP header to delete the associated cookie on the client. key and value must be character strings.

finish():

Returns the response according to the Rook specification.

See Also

Rhttpd and Request.

Examples

Run this code
s <- Rhttpd$new()
if (FALSE) {
s$start(quiet=TRUE)
}
s$add(name="response",
    app=function(env){
        req <- Request$new(env)
        res <- Response$new()
        res$write('hello')
        res$finish()
    }
)
if (FALSE) {
s$browse('response') # Opens a browser window to the app.
}
s$remove(all=TRUE)
rm(s)

Run the code above in your browser using DataLab