-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9449cc2
commit 18894e0
Showing
22 changed files
with
826 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
\name{App-class} | ||
\Rdversion{1.1} | ||
\docType{class} | ||
\alias{App-class} | ||
\alias{App} | ||
|
||
\title{Class \code{App}} | ||
\description{ | ||
Abstract class from which \code{Middleware} and \code{Builder} inherit. Provides the \code{app} field. | ||
|
||
\code{App} can also be used to instantiate reference classed applications wrapped around a function. See \code{\link{Middleware}} for an example. | ||
} | ||
\section{Fields}{ | ||
\describe{ | ||
\item{\code{app}:}{A Rack application.} | ||
} | ||
} | ||
\section{Methods}{ | ||
\describe{ | ||
\item{\code{new(app=NULL)}:}{ Creates a new \code{App} object. \code{app} is any \code{Rack} aware R object.} | ||
} | ||
} | ||
\seealso{ | ||
\code{\link{is_rackable}}, \code{\link{Builder}}, and \code{\link{Middleware}}. | ||
} | ||
\keyword{classes} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
\name{Brewery-class} | ||
\Rdversion{1.1} | ||
\docType{class} | ||
\alias{Brewery-class} | ||
\alias{Brewery} | ||
|
||
\title{Class \code{Brewery}} | ||
\description{ | ||
A \code{\link{Middleware}} class for mapping URLs to a directory of files that are subsequently passed to \code{\link{brew}}. When a file is brewed, the two variables \code{req} (an object of class \code{\link{Request}}) and \code{res} (an object of class \code{\link{Response}}) are available for use. | ||
|
||
} | ||
\section{Methods}{ | ||
\describe{ | ||
\item{\code{new(url,root,...):}}{ | ||
\code{url} is a character string or \code{\link{regexp}} on which to match, \code{root} is the name of the directory where brew files reside. Named arguments can be passed in via \code{...} and will be available within the scope of each brewed file. | ||
} | ||
}} | ||
|
||
\examples{ | ||
|
||
# | ||
# This application runs any file found in tempdir() through brew. | ||
# | ||
s <- Rhttpd$new() | ||
s$start(quiet=TRUE) | ||
cat("<h1>Random Number: <\%=rnorm(1)\%></h1>", | ||
file=file.path(tempdir(),"index.html")) | ||
s$add(name="random", | ||
app=Builder$new( | ||
Brewery$new(url="/",root=tempdir()), | ||
Redirect$new("/index.html") | ||
) | ||
) | ||
\dontrun{ | ||
s$browse('random') # Opens a browser window to the app. | ||
} | ||
file.remove(file.path(tempdir(),"index.html")) | ||
rm(s) | ||
} | ||
|
||
\seealso{ | ||
\code{\link{Rhttpd}}, \code{\link{Builder}}, \code{\link{Redirect}}, and \code{\link{brew}}. | ||
} | ||
\keyword{classes} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
\name{Builder-class} | ||
\Rdversion{1.1} | ||
\docType{class} | ||
\alias{Builder-class} | ||
\alias{Builder} | ||
|
||
\title{Class \code{Builder}} | ||
\description{ | ||
A convenience object for combining various \code{Middleware} with a default application to create a more complex Rack application. | ||
} | ||
\examples{ | ||
|
||
# The following is the Hmisc example. Explore the folder | ||
# system.file('exampleApps/Hmisc',package='Rack') for more information. | ||
s <- Rhttpd$new() | ||
\dontrun{ | ||
library(Hmisc) | ||
dir.create(file.path(tempdir(),'plots'),showWarnings=FALSE) | ||
s$add( name="Hmisc", | ||
app=Builder$new( | ||
Static$new( | ||
urls = c('/css','/images','/javascript'), | ||
root = system.file('exampleApps/Hmisc',package='Rack') | ||
), | ||
Static$new(urls='/plots',root=tempdir()), | ||
Brewery$new( | ||
url='/brew', | ||
root= system.file('exampleApps/Hmisc',package='Rack'), | ||
imagepath=file.path(tempdir(),'plots'), | ||
imageurl='../plots/' | ||
), | ||
Redirect$new('/brew/useR2007.rhtml') | ||
) | ||
) | ||
s$start(quiet=TRUE) | ||
s$browse('Hmisc') # Opens a browser window to the application. | ||
} | ||
s$remove(all=TRUE) | ||
s$stop() | ||
} | ||
\seealso{ | ||
\code{\link{Rhttpd}}, \code{\link{Static}}, \code{\link{Brewery}}, and \code{\link{Redirect}}. | ||
} | ||
\keyword{classes} | ||
\section{Methods}{ | ||
\describe{ | ||
\item{\code{new(...)}:}{ Arguments can be any \code{Middleware} object while the last argument in the list must be a valid \code{Rack} application. That is, it will handle the incoming request without deferring to another application. } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
\name{File-class} | ||
\Rdversion{1.1} | ||
\docType{class} | ||
\alias{File-class} | ||
\alias{File} | ||
|
||
\title{Class \code{File}} | ||
\description{ | ||
A Rack application that serves static files from a root directory, according to the path info of the Rack request. | ||
} | ||
\examples{ | ||
# This example serves all your files in /etc (on UNIX and Mac only). | ||
# | ||
# Note that when you open the application, you will see the word | ||
# 'Forbidden'. "File" doesn's serve directories, so you must amend the | ||
# url in the location bar with the file you want to view. Try adding /passwd. | ||
|
||
s <- Rhttpd$new() | ||
s$start(quiet=TRUE) | ||
s$add(name="etc",app=File$new('/etc')) | ||
\dontrun{ | ||
s$browse('etc') # Opens a browser window to the app. | ||
} | ||
s$remove(all=TRUE) | ||
rm(s) | ||
} | ||
\section{Methods}{ | ||
\describe{ | ||
\item{\code{new(root):}}{ | ||
\code{root} is the name of the directory from where to serve files. | ||
} | ||
}} | ||
\seealso{ | ||
\code{\link{Rhttpd}}. | ||
} | ||
\keyword{classes} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
\name{Middleware-class} | ||
\Rdversion{1.1} | ||
\docType{class} | ||
\alias{Middleware-class} | ||
\alias{Middleware} | ||
|
||
\title{Class \code{Middleware}} | ||
\description{ | ||
An abstract class for building Rack Middleware applications. \code{Middleware} applications either handle the incoming web request or hand off the request to the Rack app defined in the field of the same name. | ||
} | ||
\examples{ | ||
# Middleware applications are typically instantiated in the argument list of | ||
# Builder$new(), but here is stand-alone example. | ||
# | ||
# Once your browser loads the app, you will see something like this in | ||
# your location bar: http://127.0.0.1:28649/custom/middle. Add '/foo' | ||
# onto the end of that and reload. | ||
|
||
setRefClass( | ||
'FooBar', | ||
contains = 'Middleware', | ||
methods = list( | ||
initialize = function(...){ | ||
# app to defer to. | ||
callSuper(app=App$new(function(env){ | ||
res <- Response$new() | ||
res$write("<h1>I'm the deferred app.</h1>") | ||
res$finish() | ||
})) | ||
}, | ||
call = function(env){ | ||
req <- Request$new(env) | ||
res <- Response$new() | ||
if (length(grep('foo',req$path_info()))){ | ||
res$write("<h1>I'm the middleware app.</h1>") | ||
return(res$finish()) | ||
} else { | ||
app$call(env) | ||
} | ||
} | ||
) | ||
) | ||
s <- Rhttpd$new() | ||
s$start(quiet=TRUE) | ||
s$add(name="middle",app=getRefClass('FooBar')$new()) | ||
\dontrun{ | ||
s$browse('middle') # Opens a browser window to the app. | ||
} | ||
s$remove(all=TRUE) | ||
rm(s) | ||
} | ||
\seealso{ | ||
The following classes implement Middleware: | ||
\code{\link{Brewery}} and \code{\link{Static}}. | ||
} | ||
\section{Methods}{ | ||
\describe{ | ||
\item{\code{set_app(app)}:}{ \code{app} is a \code{\link{Rack}} application that will handle the request if this Middleware app does not. } | ||
} | ||
} | ||
\keyword{classes} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
\name{Mime-class} | ||
\Rdversion{1.1} | ||
\docType{class} | ||
\alias{Mime-class} | ||
\alias{Mime} | ||
|
||
\title{Class \code{Mime} and object \code{Mime}} | ||
\description{ | ||
A convenience object for determining the MIME type of a file name. | ||
} | ||
\examples{ | ||
Mime$file_extname('foo.png') | ||
Mime$mime_type('.png') | ||
} | ||
\keyword{classes} | ||
\section{Methods}{ | ||
\describe{ | ||
\item{\code{file_extname(fname=NULL)}:}{ Returns the file extentions for the given file.} | ||
\item{\code{mime_type(ext=NULL, fallback='application/octet-stream')}:}{ Returns the MIME type given the file extension. Besure to include the dot character in \code{ext}. If no match is found, then the fallback MIME type is returned.} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
\name{Multipart-class} | ||
\Rdversion{1.1} | ||
\docType{class} | ||
\alias{Multipart-class} | ||
\alias{Multipart} | ||
|
||
\title{Class \code{Multipart} and object \code{Multipart}} | ||
\description{ | ||
A convenience object for parsing multipart/form-data POST payloads. | ||
} | ||
\examples{ | ||
s <- Rhttpd$new() | ||
s$start(quiet=TRUE) | ||
s$add(name="multi", | ||
app=function(env){ | ||
req <- Request$new(env) | ||
res <- Response$new() | ||
res$write('<form enctype="multipart/form-data" method=POST>') | ||
res$write('Upload a file: <input type=file name=fileUpload>') | ||
res$write('<input type=submit></form><br>') | ||
post <- Multipart$parse(env) | ||
if (length(post)){ | ||
poststr <- paste(capture.output(str(post),file=NULL),collapse='\n') | ||
res$write(c('<pre>',poststr,'</pre>')) | ||
} | ||
res$finish() | ||
} | ||
) | ||
\dontrun{ | ||
s$browse('multi') # Opens a browser window to the app. | ||
} | ||
s$remove(all=TRUE) | ||
rm(s) | ||
} | ||
\seealso{ | ||
\code{\link{Rhttpd}}, \code{\link{Request}}, and \code{\link{Response}}. | ||
} | ||
\section{Methods}{ | ||
\describe{ | ||
\item{\code{parse(env)}:}{ Returns parsed POST payload as a named list. \code{env} is an environment created by \code{Rhttpd} and conforms to the \code{\link{Rack}} specification.} | ||
} | ||
} | ||
\keyword{classes} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.