[Add RDocs Christian Neukirchen **20070301185301] { hunk ./lib/rack/builder.rb 2 + # Rack::Builder implements a small DSL to iteratively construct Rack + # applications. + # + # Example: + # + # app = Rack::Builder.new { + # use Rack::CommonLogger + # use Rack::ShowExceptions + # map "/lobster" do + # use Rack::Lint + # run Rack::Lobster.new + # end + # } + # + # +use+ adds a middleware to the stack, +run+ dispatches to an application. + # You can use +map+ to construct a Rack::URLMap in a convenient way. + hunk ./lib/rack/cascade.rb 2 + # Rack::Cascade tries an request on several apps, and returns the + # first response that is not 404 (or in a list of configurable + # status codes). + hunk ./lib/rack/commonlogger.rb 2 + # Rack::CommonLogger forwards every request to an +app+ given, and + # logs a line in the Apache common log format to the +logger+, or + # rack.errors by default. + hunk ./lib/rack/commonlogger.rb 24 + # By default, log to rack.errors. hunk ./lib/rack/file.rb 2 + # Rack::File serves files below the +root+ given, according to the + # path info of the Rack request. + # + # Handlers can detect if bodies are a Rack::File, and use mechanisms + # like sendfile on the +path+. + hunk ./lib/rack/file.rb 49 - # From WEBrick + # :stopdoc: + # From WEBrick. hunk ./lib/rack/file.rb 106 + # :startdoc: hunk ./lib/rack/lint.rb 2 + # Rack::Lint validates your application and the requests and + # responses according to the Rack spec. + hunk ./lib/rack/lint.rb 10 + # :stopdoc: + hunk ./lib/rack/lint.rb 384 + + # :startdoc: + hunk ./lib/rack/lobster.rb 3 -# Paste has a Pony, Rack has a Lobster! - hunk ./lib/rack/lobster.rb 4 - LobsterString = Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2 - P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0 - t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ - I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0]) + # Paste has a Pony, Rack has a Lobster! + class Lobster + LobsterString = Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2 + P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0 + t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ + I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0]) hunk ./lib/rack/lobster.rb 11 - Lobster = lambda { |env| - if env["QUERY_STRING"].include?("flip") - lobster = LobsterString.split("\n"). - map { |line| line.ljust(42).reverse }. - join("\n") - href = "?" - else - lobster = LobsterString - href = "?flip" + LambdaLobster = lambda { |env| + if env["QUERY_STRING"].include?("flip") + lobster = LobsterString.split("\n"). + map { |line| line.ljust(42).reverse }. + join("\n") + href = "?" + else + lobster = LobsterString + href = "?flip" + end + + [200, {"Content-Type" => "text/html"}, + ["Lobstericious!", + "
", lobster, "
", + "flip!"] + ] + } + + def call(env) + req = Request.new(env) + if req.GET["flip"] == "left" + lobster = LobsterString.split("\n"). + map { |line| line.ljust(42).reverse }. + join("\n") + href = "?flip=right" + elsif req.GET["flip"] == "crash" + raise "Lobster crashed" + else + lobster = LobsterString + href = "?flip=left" + end + + Response.new.finish do |res| + res.write "Lobstericious!" + res.write "
"
+        res.write lobster
+        res.write "
" + res.write "

flip!

" + res.write "

crash!

" + end hunk ./lib/rack/lobster.rb 53 - [200, {"Content-Type" => "text/html"}, - ["Lobstericious!", - "
", lobster, "
", - "flip!"] - ] - } - - Lobster2 = lambda { |env| - req = Request.new(env) - if req.GET["flip"] == "left" - lobster = LobsterString.split("\n"). - map { |line| line.ljust(42).reverse }. - join("\n") - href = "?flip=right" - elsif req.GET["flip"] == "crash" - raise "Lobster crashed" - else - lobster = LobsterString - href = "?flip=left" - end - - Response.new.finish do |res| - res.write "Lobstericious!" - res.write "
"
-      res.write lobster
-      res.write "
" - res.write "

flip!

" - res.write "

crash!

" - end - } + end hunk ./lib/rack/lobster.rb 60 - Rack::ShowExceptions.new(Rack::Lint.new(Rack::Lobster2)), + Rack::ShowExceptions.new(Rack::Lint.new(Rack::Lobster.new)), hunk ./lib/rack/mock.rb 7 + # Rack::MockRequest helps testing your Rack application without + # actually using HTTP. + # + # After performing a request on a URL with get/post/put/delete, it + # returns a MockResponse with useful helper methods for effective + # testing. + # + # You can pass a hash with additional configuration to the + # get/post/put/delete. + # :input:: A String or IO-like to be used as rack.input. + # :fatal:: Raise a FatalWarning if the app writes to rack.errors. + # :lint:: If true, wrap the application in a Rack::Lint. + hunk ./lib/rack/mock.rb 68 + # Return the Rack environment used for a request to +uri+. hunk ./lib/rack/mock.rb 103 + # Rack::MockResponse provides useful helpers for testing your apps. + # Usually, you don't create the MockResponse on your own, but use + # MockRequest. + hunk ./lib/rack/recursive.rb 4 + # Rack::ForwardRequest gets caught by Rack::Recursive and redirects + # the current request to the app at +url+. + # + # raise ForwardRequest.new("/not-found") + # + hunk ./lib/rack/recursive.rb 27 + # Rack::Recursive allows applications called down the chain to + # include data from other applications (by using + # rack['rack.recursive.include'][...] or raise a + # ForwardRequest to redirect internally. + hunk ./lib/rack/reloader.rb 4 + # Rack::Reloader checks on every request, but at most every +secs+ + # seconds, if a file loaded changed, and reloads it, logging to + # rack.errors. + # + # It is recommended you use ShowExceptions to catch SyntaxErrors etc. + hunk ./lib/rack/request.rb 4 + # Rack::Request provides a convenient interface to a Rack + # environment. It is stateless, the environment +env+ passed to the + # constructor will be directly modified. + # + # req = Rack::Request.new(env) + # req.post? + # req.params["data"] + hunk ./lib/rack/request.rb 13 + # The environment of the request. hunk ./lib/rack/request.rb 41 + # Returns the data recieved in the query string. hunk ./lib/rack/request.rb 52 + # Returns the data recieved in the request body. + # + # This method support both application/x-www-form-urlencoded and + # multipart/form-data. hunk ./lib/rack/request.rb 70 + # The union of GET and POST data. hunk ./lib/rack/request.rb 92 + # Tries to return a remake of the original request URL as a string. hunk ./lib/rack/response.rb 5 + # Rack::Request provides a convenient interface to create a Rack + # response. + # + # It allows setting of headers and cookies, and provides useful + # defaults (a OK response containing HTML). + # + # You can use Request#write to iteratively generate your response, + # but note that this is buffered by Rack::Request until you call + # +finish+. +finish+ however can take a block inside which calls to + # +write+ are syncronous with the Rack response. + # + # Your application's +call+ should end returning Request#finish. + hunk ./lib/rack/showexceptions.rb 6 + # Rack::ShowExceptions catches all exceptions raised from the app it + # wraps. It shows a useful backtrace with the sourcefile and + # clickable context, the whole Rack environment and the request + # data. + # + # Be careful when you use this on public-facing sites as it could + # reveal information helpful to attackers. + hunk ./lib/rack/showexceptions.rb 72 + # :stopdoc: + hunk ./lib/rack/showexceptions.rb 341 + + # :startdoc: hunk ./lib/rack/urlmap.rb 2 + # Rack::URLMap takes a hash mapping urls or paths to apps, and + # dispatches accordingly. Support for HTTP/1.1 host names exists if + # the URLs start with http:// or https://. + # + # URLMap modifies the SCRIPT_NAME and PATH_INFO such that the part + # relevant for dispatch is in the SCRIPT_NAME, and the rest in the + # PATH_INFO. This should be taken care of when you need to + # reconstruct the URL in order to create links. + # + # URLMap dispatches in such a way that the longest paths are tried + # first, since they are most specific. + hunk ./lib/rack/utils.rb 4 + # Rack::Utils contains a grab-bag of useful methods for writing web + # applications adopted from all kinds of Ruby libraries. + hunk ./lib/rack/utils.rb 51 + # Escape ampersands, brackets and quotes to their HTML/XML entities. hunk ./lib/rack/utils.rb 61 + # A case-normalizing Hash, adjusting on [] and []=. hunk ./lib/rack/utils.rb 84 - # Adapted from IOWA. + # A multipart form data parser, adapted from IOWA. + # + # Usually, Rack::Request#POST takes care of calling this. + hunk ./lib/rack.rb 8 + +# The Rack main module, serving as a namespace for all core Rack +# modules and classes. +# +# All modules meant for use in your application are autoloaded here, +# so it should be enough just to require rack.rb in your code. + hunk ./lib/rack.rb 16 + # The Rack version number. hunk ./lib/rack.rb 19 + # Return the Rack version as a dotted string. hunk ./lib/rack.rb 41 + # *Adapters* connect Rack with third party web frameworks. + # + # Rack includes adapters for Camping and Rails. + # + # Refer to the submodules for framework-specific calling details. + hunk ./lib/rack.rb 52 + # *Handlers* connect web servers with Rack. + # + # Rack includes Handlers for Mongrel, WEBrick, FastCGI and CGI. + # + # Handlers usually are activated by calling MyHandler.run(myapp). + # A second optional hash can be passed to include server-specific + # configuration. + }