-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* README, lib/camping/*.rb: all docs are up-to-date.
* lib/camping/webrick.rb: added X-Sendfile support. * bin/camping: really be sure this guy has the right sqlite3.
- Loading branch information
_why
committed
May 19, 2006
1 parent
a81c8a0
commit 58318be
Showing
6 changed files
with
142 additions
and
15 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
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
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
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 |
---|---|---|
@@ -1,20 +1,66 @@ | ||
# == About camping/webrick.rb | ||
# | ||
# For many who have Ruby installed, Camping and WEBrick is a great option. | ||
# It's definitely the easiest configuration, however some performance is sacrificed. | ||
# For better speed, check out Mongrel at http://mongrel.rubyforge.org/, which comes | ||
# with Camping hooks and is supported by the Camping Tool. | ||
require 'camping' | ||
require 'webrick/httpservlet/abstract.rb' | ||
|
||
class WEBrick::CampingHandler < WEBrick::HTTPServlet::AbstractServlet | ||
# WEBrick::CampingHandler is a very simple handle for hosting Camping apps in | ||
# a WEBrick server. It's used much like any other WEBrick handler. | ||
# | ||
# == Mounting a Camping App | ||
# | ||
# Assuming Camping.goes(:Blog), the Blog application can be mounted alongside | ||
# other WEBrick mounts. | ||
# | ||
# s = WEBrick::HTTPServer.new(:BindAddress => host, :Port => port) | ||
# s.mount "/blog", WEBrick::CampingHandler, Blog | ||
# s.mount_proc("/") { ... } | ||
# | ||
# == How Does it Compare? | ||
# | ||
# Compared to other handlers, WEBrick is well-equipped in terms of features. | ||
# | ||
# * The <tt>X-Sendfile</tt> header is supported, along with etags and | ||
# modification time headers for the file served. Since this handler | ||
# is a subclass of WEBrick::HTTPServlet::DefaultFileHandler, all of its | ||
# logic is used. | ||
# * IO is streaming up and down. When you upload a file, it is streamed to | ||
# the server's filesystem. When you download a file, it is streamed to | ||
# your browser. | ||
# | ||
# While WEBrick is a bit slower than Mongrel and FastCGI options, it's | ||
# a decent choice, for sure! | ||
module WEBrick # :nodoc: | ||
class CampingHandler < WEBrick::HTTPServlet::DefaultFileHandler | ||
# Creates a CampingHandler, which answers for the application within +klass+. | ||
def initialize(server, klass) | ||
super(server, klass) | ||
@klass = klass | ||
end | ||
# Handler for WEBrick requests (also aliased as do_POST). | ||
def do_GET(req, resp) | ||
controller = @klass.run((req.body and StringIO.new(req.body)), req.meta_vars) | ||
resp.status = controller.status | ||
@local_path = nil | ||
controller.headers.each do |k, v| | ||
[*v].each do |vi| | ||
resp[k] = vi | ||
if k =~ /^X-SENDFILE$/i | ||
@local_path = v | ||
else | ||
[*v].each do |vi| | ||
resp[k] = vi | ||
end | ||
end | ||
end | ||
resp.body = controller.body | ||
|
||
if @local_path | ||
super(req, res) | ||
else | ||
resp.body = controller.body | ||
end | ||
end | ||
alias_method :do_POST, :do_GET | ||
end | ||
end |