Request-class function

Class Request

Class Request

A convenience class for working with a Rook environment. Be sure to see the example at the end of this help file. 1.1

class

Examples

# # The following example prints out the result of each method. # ls_str <- function(s) paste(capture.output(str(s),file=NULL),collapse='\n') s <- Rhttpd$new() ## Not run: s$start(quiet=TRUE) ## End(Not run) s$add(name="request", app=function(env){ req <- Request$new(env) res <- Response$new() res$set_cookie('imacookie','42') action <- req$to_url('/foo',bar=1,baz='three') res$write('<form enctype="multipart/form-data" method=POST action="') res$write(action) res$write('">') res$write('Upload a file: <input type=file name=fileUpload>') res$write('<input type=submit></form><br><pre>') res$write(c('parseable_data: ',req$parseable_data(),'\n')) res$write(c('url: ',req$url(),'\n')) res$write(c('request_method: ',req$request_method(),'\n')) res$write(c('GET: ',ls_str(req$GET()),'\n')) res$write(c('post: ',req$post(),'\n')) res$write(c('media_type: ',req$media_type(),'\n')) res$write(c('query_string: ',req$query_string(),'\n')) res$write(c('fullpath: ',req$fullpath(),'\n')) res$write(c('referer: ',req$referer(),'\n')) res$write(c('cookies: ',ls_str(req$cookies()),'\n')) res$write(c('content_charset: ',req$content_charset(),'\n')) res$write(c('head: ',req$head(),'\n')) res$write(c('accept_encoding: ',req$accept_encoding(),'\n')) res$write(c('content_length: ',req$content_length(),'\n')) res$write(c('form_data: ',req$form_data(),'\n')) res$write(c('xhr: ',req$xhr(),'\n')) res$write(c('params: ',ls_str(req$params()),'\n')) res$write(c('media_type_params:\n',ls_str(req$media_type_params()),'\n')) res$write(c('user_agent: ',req$user_agent(),'\n')) res$write(c('put: ',req$put(),'\n')) res$write(c('get: ',req$get(),'\n')) res$write(c('path: ',req$path(),'\n')) res$write(c('body: ',ls_str(req$body()),'\n')) res$write(c('port: ',req$port(),'\n')) res$write(c('host_with_port: ',req$host_with_port(),'\n')) res$write(c('scheme: ',req$scheme(),'\n')) res$write(c('ip: ',req$ip(),'\n')) res$write(c('options: ',req$options(),'\n')) res$write(c('to_url: ',req$to_url('foo',bar=1,baz='two'),'\n')) res$write(c('host: ',req$host(),'\n')) res$write(c('POST: ',ls_str(req$POST()),'\n')) res$write(c('trace: ',req$trace(),'\n')) res$write(c('script_name: ',req$script_name(),'\n')) res$write(c('content_type: ',req$content_type(),'\n')) res$write(c('delete: ',req$delete(),'\n')) res$write(c('path_info: ',req$path_info(),'\n')) res$write(c('\nRac env: ',ls_str(as.list(env)),'\n')) res$finish() } ) ## Not run: s$browse('request') # Opens a browser window to the app. ## End(Not run) s$remove(all=TRUE) rm(s)

Methods

  • parseable_data():: Returns a boolean value determining if the POST payload is parseable.
  • url():: Returns url as a character string containing the scheme, host, port, and possibly the GET query string if supplied.
  • request_method():: Returns the HTTP method as a character string, e.g. 'GET', 'POST', etc.
  • GET():: Returns a named list containing the variables parsed from the query string.
  • post():: Returns TRUE if the current request method is 'POST', FALSE otherwise.
  • new(env):: Instantiates a new Request object for the given Rook environment.
  • media_type():: Returns the media type for the current request as a character string.
  • query_string():: Returns the unparsed query string.
  • fullpath():: Returns the same string as url() but without the scheme, host, and port.
  • referer() or referrer():: Returns the referring url.
  • cookies():: Returns any cookies in the request as a named list.
  • content_charset():: Returns the content charset as a character string.
  • head():: Returns TRUE if the HTTP method is 'HEAD', FALSE otherwise.
  • accept_encoding():: Returns the accept encoding header as a character string.
  • content_length():: Returns content length header value as a string.
  • form_data():: Returns TRUE if there's form data, e.g. POST data with the request, FALSE otherwise.
  • xhr():: Returns the x-requested-with header value as a character string.
  • params():: Returns the combination of POST() and GET() in one named list.
  • media_type_params():: Returns any media type parameters from the content type as a named list.
  • user_agent():: Returns the user-agent header value as a character string.
  • put():: Returns TRUE if the current request is a 'PUT'.
  • get():: Returns TRUE if the current request is a 'GET'.
  • path():: Returns a character string like fullpath() but without the query string.
  • body():: Returns the 'rook.input' object from the environment. See RhttpdInputStream for more information.
  • port():: Returns the server port as an integer.e
  • host_with_port():: Returns the host and port as a character string separated by ':'.
  • scheme():: Returns the scheme, e.g. 'http' or 'https', as a character string.
  • ip():: Returns the remote IP address as a character string.
  • options():: Returns TRUE if the current request is 'OPTIONS'.
  • to_url(url, ...):: Concatenates the script name with the url argument along with any named parameters passed via ... .
  • host():: Returns the server host as a character string.
  • POST():: Returns a named list containing the variables parsed from the POST payload.
  • trace():: Returns TRUE if the current request is 'TRACE'.
  • script_name(s=NULL):: Returns the script name of the application, e.g. '/custom/multi'. Also, if s is not NULL, sets the script name to s.
  • content_type():: Returns the content-type header value as a character string.
  • delete():: Returns TRUE if the current request is 'DELETE'.
  • path_info(s=NULL):: Returns the portion of the url after the script name as a character string. If s is not NULL, sets the path info to s.

See Also

Rhttpd and Response.

  • Maintainer: Evan Biederstedt
  • License: GPL-2
  • Last published: 2022-11-07