View
@@ -1,26 +1,25 @@
# Copyright (c) 2005 Zed A. Shaw
# Copyright (c) 2011 Evan Phoenix
# You can redistribute it and/or modify it under the same terms as Ruby.
#
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
# for more information.
require 'singleton'
require 'optparse'
require 'mongrel/gems'
Mongrel::Gems.require 'gem_plugin'
require 'puma/gems'
Puma::Gems.require 'gem_plugin'
module Mongrel
module Puma
# Contains all of the various commands that are used with
# Mongrel servers.
# Puma servers.
module Command
BANNER = "Usage: mongrel_rails <command> [options]"
BANNER = "Usage: puma_rails <command> [options]"
# A Command pattern implementation used to create the set of command available to the user
# from Mongrel. The script uses objects which implement this interface to do the
# from Puma. The script uses objects which implement this interface to do the
# user's bidding.
module Base
@@ -44,7 +43,7 @@ def options(opts)
def initialize(options={})
argv = options[:argv] || []
@opt = OptionParser.new
@opt.banner = Mongrel::Command::BANNER
@opt.banner = Puma::Command::BANNER
@valid = true
# this is retarded, but it has to be done this way because -h and -v exit
@done_validating = false
@@ -61,7 +60,7 @@ def initialize(options={})
# I need to add my own -v definition to prevent the -v from exiting by default as well.
@opt.on_tail("--version", "Show version") do
@done_validating = true
puts "Version #{Mongrel::Const::MONGREL_VERSION}"
puts "Version #{Puma::Const::PUMA_VERSION}"
end
@opt.parse! argv
@@ -153,10 +152,10 @@ def commands
# Prints a list of available commands.
def print_command_list
puts "#{Mongrel::Command::BANNER}\nAvailable commands are:\n\n"
puts "#{Puma::Command::BANNER}\nAvailable commands are:\n\n"
self.commands.each do |name|
if /mongrel::/ =~ name
if /puma::/ =~ name
name = name[9 .. -1]
end
@@ -178,14 +177,14 @@ def run(args)
print_command_list
return true
elsif cmd_name == "--version"
puts "Mongrel Web Server #{Mongrel::Const::MONGREL_VERSION}"
puts "Puma Web Server #{Puma::Const::PUMA_VERSION}"
return true
end
begin
# quick hack so that existing commands will keep working but the Mongrel:: ones can be moved
# quick hack so that existing commands will keep working but the Puma:: ones can be moved
if ["start", "stop", "restart"].include? cmd_name
cmd_name = "mongrel::" + cmd_name
cmd_name = "puma::" + cmd_name
end
command = GemPlugin::Manager.instance.create("/commands/#{cmd_name}", :argv => args)
@@ -204,7 +203,7 @@ def run(args)
# needed so the command is already valid so we can skip it.
if not command.done_validating
if not command.validate
STDERR.puts "#{cmd_name} reported an error. Use mongrel_rails #{cmd_name} -h to get help."
STDERR.puts "#{cmd_name} reported an error. Use puma_rails #{cmd_name} -h to get help."
return false
else
command.run
View
@@ -1,18 +1,18 @@
require 'yaml'
require 'etc'
module Mongrel
# Implements a simple DSL for configuring a Mongrel server for your
# purposes. More used by framework implementers to setup Mongrel
module Puma
# Implements a simple DSL for configuring a Puma server for your
# purposes. More used by framework implementers to setup Puma
# how they like, but could be used by regular folks to add more things
# to an existing mongrel configuration.
# to an existing puma configuration.
#
# It is used like this:
#
# require 'mongrel'
# config = Mongrel::Configurator.new :host => "127.0.0.1" do
# require 'puma'
# config = Puma::Configurator.new :host => "127.0.0.1" do
# listener :port => 3000 do
# uri "/app", :handler => Mongrel::DirHandler.new(".", load_mime_map("mime.yaml"))
# uri "/app", :handler => Puma::DirHandler.new(".", load_mime_map("mime.yaml"))
# end
# run
# end
@@ -22,7 +22,7 @@ module Mongrel
# specific to the servers but just a hash of default parameters that all
# server or uri calls receive.
#
# When you are inside the block after Mongrel::Configurator.new you can simply
# When you are inside the block after Puma::Configurator.new you can simply
# call functions that are part of Configurator (like server, uri, daemonize, etc)
# without having to refer to anything else. You can also call these functions on
# the resulting object directly for additional configuration.
@@ -70,7 +70,7 @@ def change_privilege(user, group)
end
rescue Errno::EPERM => e
log "Couldn't change user and group to #{user.inspect}:#{group.inspect}: #{e.to_s}."
log "Mongrel failed to start."
log "Puma failed to start."
exit 1
end
end
@@ -136,7 +136,7 @@ def listener(options={},&block)
ops[:throttle] ||= 0
ops[:timeout] ||= 60
@listener = Mongrel::HttpServer.new(ops[:host], ops[:port].to_i, ops[:num_processors].to_i, ops[:throttle].to_i, ops[:timeout].to_i)
@listener = Puma::HttpServer.new(ops[:host], ops[:port].to_i, ops[:num_processors].to_i, ops[:throttle].to_i, ops[:timeout].to_i)
@listener_name = "#{ops[:host]}:#{ops[:port]}"
@listeners[@listener_name] = @listener
@@ -239,10 +239,10 @@ def load_yaml(file, default={})
# Loads the MIME map file and checks that it is correct
# on loading. This is commonly passed to Mongrel::DirHandler
# on loading. This is commonly passed to Puma::DirHandler
# or any framework handler that uses DirHandler to serve files.
# You can also include a set of default MIME types as additional
# settings. See Mongrel::DirHandler for how the MIME types map
# settings. See Puma::DirHandler for how the MIME types map
# is organized.
def load_mime_map(file, mime={})
# configure any requested mime map
@@ -263,15 +263,15 @@ def plugin(name, options={})
GemPlugin::Manager.instance.create(name, ops)
end
# Lets you do redirects easily as described in Mongrel::RedirectHandler.
# Lets you do redirects easily as described in Puma::RedirectHandler.
# You use it inside the configurator like this:
#
# redirect("/test", "/to/there") # simple
# redirect("/to", /t/, 'w') # regexp
# redirect("/hey", /(w+)/) {|match| ...} # block
#
def redirect(from, pattern, replacement = nil, &block)
uri from, :handler => Mongrel::RedirectHandler.new(pattern, replacement, &block)
uri from, :handler => Puma::RedirectHandler.new(pattern, replacement, &block)
end
# Works like a meta run method which goes through all the
@@ -282,7 +282,7 @@ def run
s.run
}
$mongrel_sleeper_thread = Thread.new { loop { sleep 1 } }
$puma_sleeper_thread = Thread.new { loop { sleep 1 } }
end
# Calls .stop on all the configured listeners so they
@@ -315,12 +315,12 @@ def join
#
# debug "/", what = [:rails]
#
# And it will only produce the log/mongrel_debug/rails.log file.
# And it will only produce the log/puma_debug/rails.log file.
# Available options are: :access, :files, :objects, :threads, :rails
#
# NOTE: Use [:files] to get accesses dumped to stderr like with WEBrick.
def debug(location, what = [:access, :files, :objects, :threads, :rails])
require 'mongrel/debug'
require 'puma/debug'
handlers = {
:access => "/handlers/requestlog::access",
:files => "/handlers/requestlog::files",
@@ -330,11 +330,11 @@ def debug(location, what = [:access, :files, :objects, :threads, :rails])
}
# turn on the debugging infrastructure, and ObjectTracker is a pig
MongrelDbg.configure
PumaDbg.configure
# now we roll through each requested debug type, turn it on and load that plugin
what.each do |type|
MongrelDbg.begin_trace type
PumaDbg.begin_trace type
uri location, :handler => plugin(handlers[type])
end
end
@@ -352,7 +352,7 @@ def run_config(script)
# a HUP signal since this is typically framework specific.
#
# Requires a :pid_file option given to Configurator.new to indicate a file to delete.
# It sets the MongrelConfig.needs_restart attribute if
# It sets the PumaConfig.needs_restart attribute if
# the start command should reload. It's up to you to detect this
# and do whatever is needed for a "restart".
#
@@ -369,7 +369,7 @@ def setup_signals(options={})
unless RbConfig::CONFIG['host_os'] =~ /mingw|mswin/
# graceful shutdown
trap("TERM") { log "TERM signal received."; stop }
trap("USR1") { log "USR1 received, toggling $mongrel_debug_client to #{!$mongrel_debug_client}"; $mongrel_debug_client = !$mongrel_debug_client }
trap("USR1") { log "USR1 received, toggling $puma_debug_client to #{!$puma_debug_client}"; $puma_debug_client = !$puma_debug_client }
# restart
trap("USR2") { log "USR2 signal received."; stop(true) }
@@ -379,7 +379,7 @@ def setup_signals(options={})
end
end
# Logs a simple message to STDERR (or the mongrel log if in daemon mode).
# Logs a simple message to STDERR (or the puma log if in daemon mode).
def log(msg)
STDERR.print "** ", msg, "\n"
end
View
@@ -1,9 +1,9 @@
module Mongrel
module Puma
# Every standard HTTP code mapped to the appropriate message. These are
# used so frequently that they are placed directly in Mongrel for easy
# access rather than Mongrel::Const itself.
# used so frequently that they are placed directly in Puma for easy
# access rather than Puma::Const itself.
HTTP_STATUS_CODES = {
100 => 'Continue',
101 => 'Switching Protocols',
@@ -49,7 +49,7 @@ module Mongrel
# gave about a 3% to 10% performance improvement over using the strings directly.
# Symbols did not really improve things much compared to constants.
#
# While Mongrel does try to emulate the CGI/1.2 protocol, it does not use the REMOTE_IDENT,
# While Puma does try to emulate the CGI/1.2 protocol, it does not use the REMOTE_IDENT,
# REMOTE_USER, or REMOTE_HOST parameters since those are either a security problem or
# too taxing on performance.
module Const
@@ -65,12 +65,12 @@ module Const
REQUEST_URI='REQUEST_URI'.freeze
REQUEST_PATH='REQUEST_PATH'.freeze
MONGREL_VERSION = VERSION = "1.3.0".freeze
PUMA_VERSION = VERSION = "1.3.0".freeze
MONGREL_TMP_BASE="mongrel".freeze
PUMA_TMP_BASE="puma".freeze
# The standard empty 404 response for bad requests. Use Error4040Handler for custom stuff.
ERROR_404_RESPONSE="HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: Mongrel #{MONGREL_VERSION}\r\n\r\nNOT FOUND".freeze
ERROR_404_RESPONSE="HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: Puma #{PUMA_VERSION}\r\n\r\nNOT FOUND".freeze
CONTENT_LENGTH="CONTENT_LENGTH".freeze
View
@@ -1,51 +1,49 @@
# Copyright (c) 2005 Zed A. Shaw
# You can redistribute it and/or modify it under the same terms as Ruby.
#
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
# for more information.
require 'logger'
require 'set'
require 'socket'
require 'fileutils'
module MongrelDbg
module PumaDbg
SETTINGS = { :tracing => {}}
LOGGING = { }
def MongrelDbg::configure(log_dir = File.join("log","mongrel_debug"))
def PumaDbg::configure(log_dir = File.join("log","puma_debug"))
FileUtils.mkdir_p(log_dir)
@log_dir = log_dir
$objects_out=open(File.join("log","mongrel_debug","objects.log"),"w")
$objects_out=open(File.join("log","puma_debug","objects.log"),"w")
$objects_out.puts "run,classname,last,count,delta,lenmean,lensd,lenmax"
$objects_out.sync = true
$last_stat = nil
$run_count = 0
end
def MongrelDbg::trace(target, message)
def PumaDbg::trace(target, message)
if SETTINGS[:tracing][target] and LOGGING[target]
LOGGING[target].log(Logger::DEBUG, message)
end
end
def MongrelDbg::begin_trace(target)
def PumaDbg::begin_trace(target)
SETTINGS[:tracing][target] = true
if not LOGGING[target]
LOGGING[target] = Logger.new(File.join(@log_dir, "#{target.to_s}.log"))
end
MongrelDbg::trace(target, "TRACING ON #{Time.now}")
PumaDbg::trace(target, "TRACING ON #{Time.now}")
end
def MongrelDbg::end_trace(target)
def PumaDbg::end_trace(target)
SETTINGS[:tracing][target] = false
MongrelDbg::trace(target, "TRACING OFF #{Time.now}")
PumaDbg::trace(target, "TRACING OFF #{Time.now}")
LOGGING[target].close
LOGGING[target] = nil
end
def MongrelDbg::tracing?(target)
def PumaDbg::tracing?(target)
SETTINGS[:tracing][target]
end
end
@@ -84,18 +82,18 @@ def log_open_files
open_counts[args] ||= 0
open_counts[args] += 1
end
MongrelDbg::trace(:files, open_counts.to_yaml)
PumaDbg::trace(:files, open_counts.to_yaml)
end
end
module RequestLog
# Just logs whatever requests it gets to STDERR (which ends up in the mongrel
# Just logs whatever requests it gets to STDERR (which ends up in the puma
# log when daemonized).
class Access < GemPlugin::Plugin "/handlers"
include Mongrel::HttpHandlerPlugin
include Puma::HttpHandlerPlugin
def process(request,response)
p = request.params
@@ -105,18 +103,18 @@ def process(request,response)
class Files < GemPlugin::Plugin "/handlers"
include Mongrel::HttpHandlerPlugin
include Puma::HttpHandlerPlugin
def process(request, response)
MongrelDbg::trace(:files, "#{Time.now} FILES OPEN BEFORE REQUEST #{request.params['PATH_INFO']}")
PumaDbg::trace(:files, "#{Time.now} FILES OPEN BEFORE REQUEST #{request.params['PATH_INFO']}")
log_open_files
end
end
# stolen from Robert Klemme
class Objects < GemPlugin::Plugin "/handlers"
include Mongrel::HttpHandlerPlugin
include Puma::HttpHandlerPlugin
def process(request,response)
begin
@@ -127,7 +125,7 @@ def process(request,response)
begin
if o.respond_to? :length
len = o.length
lengths[o.class] ||= Mongrel::Stats.new(o.class)
lengths[o.class] ||= Puma::Stats.new(o.class)
lengths[o.class].sample(len)
end
rescue Object
@@ -160,32 +158,32 @@ def process(request,response)
end
class Params < GemPlugin::Plugin "/handlers"
include Mongrel::HttpHandlerPlugin
include Puma::HttpHandlerPlugin
def process(request, response)
MongrelDbg::trace(:rails, "#{Time.now} REQUEST #{request.params['PATH_INFO']}")
MongrelDbg::trace(:rails, request.params.to_yaml)
PumaDbg::trace(:rails, "#{Time.now} REQUEST #{request.params['PATH_INFO']}")
PumaDbg::trace(:rails, request.params.to_yaml)
end
end
class Threads < GemPlugin::Plugin "/handlers"
include Mongrel::HttpHandlerPlugin
include Puma::HttpHandlerPlugin
def process(request, response)
MongrelDbg::trace(:threads, "#{Time.now} REQUEST #{request.params['PATH_INFO']}")
PumaDbg::trace(:threads, "#{Time.now} REQUEST #{request.params['PATH_INFO']}")
begin
ObjectSpace.each_object do |obj|
begin
if obj.class == Mongrel::HttpServer
if obj.class == Puma::HttpServer
worker_list = obj.workers.list
if worker_list.length > 0
keys = "-----\n\tKEYS:"
worker_list.each {|t| keys << "\n\t\t-- #{t}: #{t.keys.inspect}" }
end
MongrelDbg::trace(:threads, "#{obj.host}:#{obj.port} -- THREADS: #{worker_list.length} #{keys}")
PumaDbg::trace(:threads, "#{obj.host}:#{obj.port} -- THREADS: #{worker_list.length} #{keys}")
end
rescue Object # Ignore since obj.class can sometimes take parameters
end
@@ -198,6 +196,6 @@ def process(request, response)
END {
MongrelDbg::trace(:files, "FILES OPEN AT EXIT")
PumaDbg::trace(:files, "FILES OPEN AT EXIT")
log_open_files
}
View
@@ -1,4 +1,4 @@
module Mongrel
module Puma
module Gems
class << self
@@ -12,11 +12,11 @@ def require(library, version = nil)
version ? gem(library, version) : gem(library)
retry
rescue Gem::LoadError, LoadError, RuntimeError
# puts "** #{library.inspect} could not be loaded" unless library == "mongrel_experimental"
# puts "** #{library.inspect} could not be loaded" unless library == "puma_experimental"
end
end
end
end
end
end
end
View
@@ -1,14 +1,12 @@
# Copyright (c) 2005 Zed A. Shaw
# You can redistribute it and/or modify it under the same terms as Ruby.
#
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
# for more information.
require 'mongrel/stats'
require 'puma/stats'
require 'zlib'
require 'yaml'
module Mongrel
module Puma
# You implement your application handler with this. It's very light giving
# just the minimum necessary for you to handle a request and shoot back
@@ -23,15 +21,15 @@ class HttpHandler
attr_reader :request_notify
attr_accessor :listener
# This will be called by Mongrel if HttpHandler.request_notify set to *true*.
# This will be called by Puma if HttpHandler.request_notify set to *true*.
# You only get the parameters for the request, with the idea that you'd "bound"
# the beginning of the request processing and the first call to process.
def request_begins(params)
end
# Called by Mongrel for each IO chunk that is received on the request socket
# Called by Puma for each IO chunk that is received on the request socket
# from the client, allowing you to track the progress of the IO and monitor
# the input. This will be called by Mongrel only if HttpHandler.request_notify
# the input. This will be called by Puma only if HttpHandler.request_notify
# set to *true*.
def request_progress(params, clen, total)
end
@@ -280,7 +278,7 @@ def DirHandler::add_mime_type(extension, type)
end
# When added to a config script (-S in mongrel_rails) it will
# When added to a config script (-S in puma_rails) it will
# look at the client's allowed response types and then gzip
# compress anything that is going out.
#
@@ -341,11 +339,11 @@ class StatisticsFilter < HttpHandler
def initialize(ops={})
@sample_rate = ops[:sample_rate] || 300
@processors = Mongrel::Stats.new("processors")
@reqsize = Mongrel::Stats.new("request Kb")
@headcount = Mongrel::Stats.new("req param count")
@respsize = Mongrel::Stats.new("response Kb")
@interreq = Mongrel::Stats.new("inter-request time")
@processors = Puma::Stats.new("processors")
@reqsize = Puma::Stats.new("request Kb")
@headcount = Puma::Stats.new("req param count")
@respsize = Puma::Stats.new("response Kb")
@interreq = Puma::Stats.new("inter-request time")
end
@@ -365,7 +363,7 @@ def dump
# The :stats_filter is basically any configured stats filter that you've added to this same
# URI. This lets the status handler print out statistics on how Mongrel is doing.
# URI. This lets the status handler print out statistics on how Puma is doing.
class StatusHandler < HttpHandler
def initialize(ops={})
@stats = ops[:stats_filter]
@@ -413,7 +411,7 @@ def describe_listener
def process(request, response)
response.start do |head,out|
out.write <<-END
<html><body><title>Mongrel Server Status</title>
<html><body><title>Puma Server Status</title>
#{describe_listener}
</body></html>
END
@@ -429,13 +427,13 @@ def process(request, response)
#
# == Examples
#
# h = Mongrel::HttpServer.new('0.0.0.0')
# h.register '/test', Mongrel::RedirectHandler.new('/to/there') # simple
# h.register '/to', Mongrel::RedirectHandler.new(/t/, 'w') # regexp
# h = Puma::HttpServer.new('0.0.0.0')
# h.register '/test', Puma::RedirectHandler.new('/to/there') # simple
# h.register '/to', Puma::RedirectHandler.new(/t/, 'w') # regexp
# # and with a block
# h.register '/hey', Mongrel::RedirectHandler.new(/(\w+)/) { |match| ... }
# h.register '/hey', Puma::RedirectHandler.new(/(\w+)/) { |match| ... }
#
class RedirectHandler < Mongrel::HttpHandler
class RedirectHandler < Puma::HttpHandler
# You set the rewrite rules when building the object.
#
# pattern => What to look for or replacement if used alone
@@ -453,14 +451,14 @@ def initialize(pattern, replacement = nil, &block)
# Process the request and return a redirect response
def process(request, response)
unless @pattern
response.socket.write(Mongrel::Const::REDIRECT % @replacement)
response.socket.write(Puma::Const::REDIRECT % @replacement)
else
if @block
new_path = request.params['REQUEST_URI'].gsub(@pattern, &@block)
else
new_path = request.params['REQUEST_URI'].gsub(@pattern, @replacement)
end
response.socket.write(Mongrel::Const::REDIRECT % new_path)
response.socket.write(Puma::Const::REDIRECT % new_path)
end
end
end
View
@@ -1,4 +1,4 @@
module Mongrel
module Puma
# This class implements a simple way of constructing the HTTP headers
# dynamically via a Hash syntax. Think of it as a write-only Hash.
# Refer to HttpResponse for information on how this is used.
View
@@ -1,5 +1,5 @@
module Mongrel
module Puma
#
# When a handler is found for a registered URI then this class is constructed
# and passed to your HttpHandler::process method. You should assume that
@@ -37,7 +37,7 @@ def initialize(params, socket, body)
# must read more data to complete body
if remain > Const::MAX_BODY
# huge body, put it in a tempfile
@body = Tempfile.new(Const::MONGREL_TMP_BASE)
@body = Tempfile.new(Const::PUMA_TMP_BASE)
@body.binmode
else
# small body, just use that
View
@@ -1,4 +1,4 @@
module Mongrel
module Puma
# Writes and controls your response to the client using the HTTP/1.1 specification.
# You use it by simply doing:
#
@@ -7,7 +7,7 @@ module Mongrel
# out.write("hello\n")
# end
#
# The parameter to start is the response code--which Mongrel will translate for you
# The parameter to start is the response code--which Puma will translate for you
# based on HTTP_STATUS_CODES. The head parameter is how you write custom headers.
# The out parameter is where you write your body. The default status code for
# HttpResponse.start is 200 so the above example is redundant.
@@ -57,7 +57,7 @@ def initialize(socket)
# body content as needed. Handlers are able to modify pretty much
# any part of the request in the chain, and can stop further processing
# by simple passing "finalize=true" to the start method. By default
# all handlers run and then mongrel finalizes the request when they're
# all handlers run and then puma finalizes the request when they're
# all done.
def start(status=200, finalize=false, reason=nil)
@status = status.to_i
@@ -75,7 +75,6 @@ def reset
elsif @header_sent
raise "You have already sent the request headers."
else
# XXX Dubious ( http://mongrel.rubyforge.org/ticket/19 )
@header.out.close
@header = HeaderOut.new(StringIO.new)
View
@@ -0,0 +1,8 @@
# Copyright (c) 2005 Zed A. Shaw
# You can redistribute it and/or modify it under the same terms as Ruby.
#
require 'puma/gems'
Puma::Gems.require 'gem_plugin'
# File is just a stub that makes sure the puma_plugins gem is loaded and ready
View
File renamed without changes.
View
@@ -1,12 +1,12 @@
require 'rack'
require 'mongrel/thread_pool'
require 'puma/thread_pool'
module Mongrel
module Puma
# Thrown at a thread when it is timed out.
class TimeoutError < RuntimeError; end
# This is the main driver of Mongrel, while the Mongrel::HttpParser and
# Mongrel::URIClassifier make up the majority of how the server functions.
# This is the main driver of Puma, while the Puma::HttpParser and
# Puma::URIClassifier make up the majority of how the server functions.
# It's a very simple class that just has a thread accepting connections and
# a simple HttpServer.process_client function to do the heavy lifting with
# the IO and Ruby.
@@ -22,13 +22,13 @@ class TimeoutError < RuntimeError; end
#
# Ruby's thread implementation is "interesting" to say the least.
# Experiments with *many* different types of IO processing simply cannot
# make a dent in it. Future releases of Mongrel will find other creative
# make a dent in it. Future releases of Puma will find other creative
# ways to make threads faster, but don't hold your breath until Ruby 1.9
# is actually finally useful.
class Server
include Mongrel::Const
include Puma::Const
attr_reader :acceptor
attr_reader :workers
@@ -81,7 +81,7 @@ def handle_request(params, client, body)
end
params[SERVER_PROTOCOL] = HTTP_11
params[SERVER_SOFTWARE] = MONGREL_VERSION
params[SERVER_SOFTWARE] = PUMA_VERSION
params[GATEWAY_INTERFACE] = CGI_VER
unless params[REQUEST_PATH]
@@ -317,7 +317,7 @@ def process(params, client, body)
# Simply registers a handler with the internal URIClassifier.
# When the URI is found in the prefix of a request then your handler's
# HttpHandler::process method is called.
# See Mongrel::URIClassifier#register for more information.
# See Puma::URIClassifier#register for more information.
#
# If you set in_front=true then the passed in handler will be put in
# the front of the list for that particular URI. Otherwise it's placed
@@ -338,7 +338,7 @@ def register(uri, handler, in_front=false)
handler.listener = self
end
# Removes any handlers registered at the given URI. See Mongrel::URIClassifier#unregister
# Removes any handlers registered at the given URI. See Puma::URIClassifier#unregister
# for more information. Remember this removes them *all* so the entire
# processing chain goes away.
def unregister(uri)
View
@@ -1,9 +1,6 @@
# Copyright (c) 2005 Zed A. Shaw
# You can redistribute it and/or modify it under the same terms as Ruby.
#
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
# for more information.
# A very simple little class for doing some basic fast statistics sampling.
# You feed it either samples of numeric data you want measured or you call
# Stats.tick to get it to add a time delta between the last time you called it.
@@ -12,7 +9,7 @@
#
# It does all of this very fast and doesn't take up any memory since the samples
# are not stored but instead all the values are calculated on the fly.
module Mongrel
module Puma
class Stats
attr_reader :sum, :sumsq, :n, :min, :max
View
@@ -1,8 +1,6 @@
# Copyright (c) 2005 Zed A. Shaw
# You can redistribute it and/or modify it under the same terms as Ruby.
#
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
# for more information.
# A modification proposed by Sean Treadway that increases the default accept
View
@@ -1,6 +1,6 @@
require 'thread'
module Mongrel
module Puma
class ThreadPool
def initialize(min, max, &blk)
@todo = Queue.new
View
@@ -1,5 +1,5 @@
module Mongrel
module Puma
class URIClassifier
class RegistrationError < RuntimeError
View
@@ -1,13 +1,11 @@
require 'hoe'
HOE = Hoe.spec 'mongrel' do
self.rubyforge_name = 'mongrel'
developer 'Zed A. Shaw', 'mongrel-users@rubyforge.org'
spec_extras[:required_ruby_version] = Gem::Requirement.new('>= 1.8.6')
HOE = Hoe.spec 'puma' do
self.rubyforge_name = 'puma'
developer 'Evan Phoenix', 'evan@phx.io'
spec_extras[:extensions] = ["ext/http11/extconf.rb"]
spec_extras[:executables] = ['mongrel_rails']
spec_extras[:executables] = ['puma_rails']
extra_rdoc_files << 'LICENSE'
View
@@ -9,12 +9,12 @@ file 'ext/http11/http11_parser.c' => ['ext/http11/http11_parser.rl'] do |t|
end
end
file 'ext/http11/org/jruby/mongrel/Http11Parser.java' => ['ext/http11/http11_parser.java.rl'] do |t|
file 'ext/http11/org/jruby/puma/Http11Parser.java' => ['ext/http11/http11_parser.java.rl'] do |t|
begin
sh "ragel #{t.prerequisites.last} -J -G2 -o #{t.name}"
rescue
fail "Could not build wrapper using Ragel (it failed or not installed?)"
end
end
task :ragel => (defined?(JRUBY_VERSION) ? 'ext/http11/org/jruby/mongrel/Http11Parser.java' : 'ext/http11/http11_parser.c')
task :ragel => (defined?(JRUBY_VERSION) ? 'ext/http11/org/jruby/puma/Http11Parser.java' : 'ext/http11/http11_parser.c')
View

This file was deleted.

Oops, something went wrong.
View
@@ -0,0 +1 @@
uri "/fromconf", :handler => Puma::Error404Handler.new("test")
View
@@ -7,7 +7,7 @@
require 'test/testhelp'
class TestCommand < GemPlugin::Plugin "/commands"
include Mongrel::Command::Base
include Puma::Command::Base
def configure
options [
@@ -47,7 +47,7 @@ def teardown
end
def run_cmd(args)
Mongrel::Command::Registry.instance.run args
Puma::Command::Registry.instance.run args
end
def test_run_command
View
@@ -6,12 +6,12 @@
require 'test/testhelp'
include Mongrel
include Puma
class ConditionalResponseTest < Test::Unit::TestCase
def setup
@server = HttpServer.new('127.0.0.1', 3501)
@server.register('/', Mongrel::DirHandler.new('.'))
@server.register('/', Puma::DirHandler.new('.'))
@server.run
@http = Net::HTTP.new(@server.host, @server.port)
View
@@ -1,15 +1,15 @@
# Copyright (c) 2005 Zed A. Shaw
# You can redistribute it and/or modify it under the same terms as Ruby.
#
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
# Additional work donated by contributors. See http://puma.rubyforge.org/attributions.html
# for more information.
require 'test/testhelp'
$test_plugin_fired = 0
class TestPlugin < GemPlugin::Plugin "/handlers"
include Mongrel::HttpHandlerPlugin
include Puma::HttpHandlerPlugin
def process(request, response)
$test_plugin_fired += 1
@@ -18,7 +18,7 @@ def process(request, response)
class Sentinel < GemPlugin::Plugin "/handlers"
include Mongrel::HttpHandlerPlugin
include Puma::HttpHandlerPlugin
def process(request, response)
raise "This Sentinel plugin shouldn't run."
@@ -32,23 +32,23 @@ def test_base_handler_config
@config = nil
redirect_test_io do
@config = Mongrel::Configurator.new :host => "localhost" do
@config = Puma::Configurator.new :host => "localhost" do
listener :port => 4501 do
# 2 in front should run, but the sentinel shouldn't since dirhandler processes the request
uri "/", :handler => plugin("/handlers/testplugin")
uri "/", :handler => plugin("/handlers/testplugin")
uri "/", :handler => Mongrel::DirHandler.new(".")
uri "/", :handler => Puma::DirHandler.new(".")
uri "/", :handler => plugin("/handlers/testplugin")
uri "/test", :handler => plugin("/handlers/testplugin")
uri "/test", :handler => plugin("/handlers/testplugin")
uri "/test", :handler => Mongrel::DirHandler.new(".")
uri "/test", :handler => Puma::DirHandler.new(".")
uri "/test", :handler => plugin("/handlers/testplugin")
debug "/"
setup_signals
run_config(File.dirname(__FILE__) + "/../test/mongrel.conf")
run_config(File.dirname(__FILE__) + "/../test/puma.conf")
load_mime_map(File.dirname(__FILE__) + "/../test/mime.yaml")
run
View
@@ -1,25 +1,25 @@
# Copyright (c) 2005 Zed A. Shaw
# You can redistribute it and/or modify it under the same terms as Ruby.
#
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
# Additional work donated by contributors. See http://puma.rubyforge.org/attributions.html
# for more information.
require 'test/testhelp'
require 'mongrel/debug'
require 'puma/debug'
class MongrelDbgTest < Test::Unit::TestCase
class PumaDbgTest < Test::Unit::TestCase
def test_tracing_to_log
FileUtils.rm_rf "log/mongrel_debug"
FileUtils.rm_rf "log/puma_debug"
MongrelDbg::configure
PumaDbg::configure
out = StringIO.new
MongrelDbg::begin_trace(:rails)
MongrelDbg::trace(:rails, "Good stuff")
MongrelDbg::end_trace(:rails)
PumaDbg::begin_trace(:rails)
PumaDbg::trace(:rails, "Good stuff")
PumaDbg::end_trace(:rails)
assert File.exist?("log/mongrel_debug"), "Didn't make logging directory"
assert File.exist?("log/puma_debug"), "Didn't make logging directory"
end
end
View
@@ -6,7 +6,7 @@
require 'test/testhelp'
class SimpleHandler < Mongrel::HttpHandler
class SimpleHandler < Puma::HttpHandler
def process(request, response)
response.start do |head,out|
head["Content-Type"] = "text/html"
@@ -16,7 +16,7 @@ def process(request, response)
end
end
class DumbHandler < Mongrel::HttpHandler
class DumbHandler < Puma::HttpHandler
def process(request, response)
response.start do |head,out|
head["Content-Type"] = "text/html"
@@ -34,19 +34,19 @@ def check_status(results, expecting)
class HandlersTest < Test::Unit::TestCase
def setup
stats = Mongrel::StatisticsFilter.new(:sample_rate => 1)
stats = Puma::StatisticsFilter.new(:sample_rate => 1)
@config = Mongrel::Configurator.new :host => '127.0.0.1', :port => 9998 do
@config = Puma::Configurator.new :host => '127.0.0.1', :port => 9998 do
listener do
uri "/", :handler => SimpleHandler.new
uri "/", :handler => stats
uri "/404", :handler => Mongrel::Error404Handler.new("Not found")
uri "/dumb", :handler => Mongrel::DeflateFilter.new
uri "/404", :handler => Puma::Error404Handler.new("Not found")
uri "/dumb", :handler => Puma::DeflateFilter.new
uri "/dumb", :handler => DumbHandler.new, :in_front => true
uri "/files", :handler => Mongrel::DirHandler.new("doc")
uri "/files_nodir", :handler => Mongrel::DirHandler.new("doc", listing_allowed=false, index_html="none")
uri "/status", :handler => Mongrel::StatusHandler.new(:stats_filter => stats)
uri "/relative", :handler => Mongrel::DirHandler.new(nil, listing_allowed=false, index_html="none")
uri "/files", :handler => Puma::DirHandler.new("doc")
uri "/files_nodir", :handler => Puma::DirHandler.new("doc", listing_allowed=false, index_html="none")
uri "/status", :handler => Puma::StatusHandler.new(:stats_filter => stats)
uri "/relative", :handler => Puma::DirHandler.new(nil, listing_allowed=false, index_html="none")
end
end
@@ -63,8 +63,8 @@ def teardown
end
def test_registration_exception_is_not_lost
assert_raises(Mongrel::URIClassifier::RegistrationError) do
@config = Mongrel::Configurator.new do
assert_raises(Puma::URIClassifier::RegistrationError) do
@config = Puma::Configurator.new do
listener do
uri "bogus", :handler => SimpleHandler.new
end
@@ -89,16 +89,16 @@ def test_nil_dirhandler
return if windows?
# Camping uses this internally
handler = Mongrel::DirHandler.new(nil, false)
handler = Puma::DirHandler.new(nil, false)
assert handler.can_serve("/tmp/testfile")
# Not a bug! A nil @file parameter is the only circumstance under which
# we are allowed to serve any existing file
assert handler.can_serve("../../../../../../../../../../tmp/testfile")
end
def test_non_nil_dirhandler_is_not_vulnerable_to_path_traversal
# The famous security bug of Mongrel 1.1.2
handler = Mongrel::DirHandler.new("/doc", false)
# The famous security bug of Puma 1.1.2
handler = Puma::DirHandler.new("/doc", false)
assert_nil handler.can_serve("/tmp/testfile")
assert_nil handler.can_serve("../../../../../../../../../../tmp/testfile")
end
View
@@ -6,7 +6,7 @@
require 'test/testhelp'
include Mongrel
include Puma
class HttpParserTest < Test::Unit::TestCase
@@ -100,7 +100,7 @@ def test_horrible_queries
# then that large header names are caught
10.times do |c|
get = "GET /#{rand_data(10,120)} HTTP/1.1\r\nX-#{rand_data(1024, 1024+(c*1024))}: Test\r\n\r\n"
assert_raises Mongrel::HttpParserError do
assert_raises Puma::HttpParserError do
parser.execute({}, get, 0)
parser.reset
end
@@ -109,7 +109,7 @@ def test_horrible_queries
# then that large mangled field values are caught
10.times do |c|
get = "GET /#{rand_data(10,120)} HTTP/1.1\r\nX-Test: #{rand_data(1024, 1024+(c*1024), false)}\r\n\r\n"
assert_raises Mongrel::HttpParserError do
assert_raises Puma::HttpParserError do
parser.execute({}, get, 0)
parser.reset
end
@@ -118,15 +118,15 @@ def test_horrible_queries
# then large headers are rejected too
get = "GET /#{rand_data(10,120)} HTTP/1.1\r\n"
get << "X-Test: test\r\n" * (80 * 1024)
assert_raises Mongrel::HttpParserError do
assert_raises Puma::HttpParserError do
parser.execute({}, get, 0)
parser.reset
end
# finally just that random garbage gets blocked all the time
10.times do |c|
get = "GET #{rand_data(1024, 1024+(c*1024), false)} #{rand_data(1024, 1024+(c*1024), false)}\r\n\r\n"
assert_raises Mongrel::HttpParserError do
assert_raises Puma::HttpParserError do
parser.execute({}, get, 0)
parser.reset
end
View
@@ -1,5 +1,5 @@
require 'test/unit'
require 'mongrel'
require 'puma'
require 'rack/lint'
require 'test/testhelp'
@@ -42,7 +42,7 @@ def call(env)
def setup
@valid_request = "GET / HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\n\r\n"
@server = Mongrel::RackServer.new("127.0.0.1", 9998)
@server = Puma::RackServer.new("127.0.0.1", 9998)
@simple = lambda { |env| [200, { "X-Header" => "Works" }, "Hello"] }
@server.app = @simple
end
View
@@ -10,7 +10,7 @@ class RedirectHandlerTest < Test::Unit::TestCase
def setup
redirect_test_io do
@server = Mongrel::HttpServer.new('127.0.0.1', 9998)
@server = Puma::HttpServer.new('127.0.0.1', 9998)
end
@server.run
@client = Net::HTTP.new('127.0.0.1', 9998)
@@ -21,7 +21,7 @@ def teardown
end
def test_simple_redirect
tester = Mongrel::RedirectHandler.new('/yo')
tester = Puma::RedirectHandler.new('/yo')
@server.register("/test", tester)
sleep(1)
@@ -31,7 +31,7 @@ def test_simple_redirect
end
def test_rewrite
tester = Mongrel::RedirectHandler.new(/(\w+)/, '+\1+')
tester = Puma::RedirectHandler.new(/(\w+)/, '+\1+')
@server.register("/test", tester)
sleep(1)
View
@@ -6,7 +6,7 @@
require 'test/testhelp'
include Mongrel
include Puma
class ResponseTest < Test::Unit::TestCase
View
@@ -11,8 +11,8 @@ class StatsTest < Test::Unit::TestCase
def test_sampling_speed
out = StringIO.new
s = Mongrel::Stats.new("test")
t = Mongrel::Stats.new("time")
s = Puma::Stats.new("test")
t = Puma::Stats.new("time")
100.times { s.sample(rand(20)); t.tick }
View
@@ -1,6 +1,6 @@
require 'test/unit'
require 'mongrel/thread_pool'
require 'puma/thread_pool'
class TestThreadPool < Test::Unit::TestCase
@@ -10,7 +10,7 @@ def teardown
def new_pool(min, max, &blk)
blk = lambda { } unless blk
@pool = Mongrel::ThreadPool.new(min, max, &blk)
@pool = Puma::ThreadPool.new(min, max, &blk)
end
def test_append_spawns
View
@@ -6,7 +6,7 @@
require 'test/testhelp'
include Mongrel
include Puma
class URIClassifierTest < Test::Unit::TestCase
View
@@ -6,9 +6,9 @@
require 'test/testhelp'
include Mongrel
include Puma
class TestHandler < Mongrel::HttpHandler
class TestHandler < Puma::HttpHandler
attr_reader :ran_test
def process(request, response)
@@ -92,9 +92,9 @@ def test_header_is_too_long
end
def test_file_streamed_request
body = "a" * (Mongrel::Const::MAX_BODY * 2)
body = "a" * (Puma::Const::MAX_BODY * 2)
long = "GET /test HTTP/1.1\r\nContent-length: #{body.length}\r\n\r\n" + body
do_test(long, Mongrel::Const::CHUNK_SIZE * 2 -400)
do_test(long, Puma::Const::CHUNK_SIZE * 2 -400)
end
end
View
@@ -1,7 +1,7 @@
# Copyright (c) 2005 Zed A. Shaw
# You can redistribute it and/or modify it under the same terms as Ruby.
#
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
# Additional work donated by contributors. See http://puma.rubyforge.org/attributions.html
# for more information.
@@ -22,8 +22,8 @@
require 'stringio'
require 'pp'
require 'mongrel'
require 'mongrel/stats'
require 'puma'
require 'puma/stats'
if ENV['DEBUG']
require 'ruby-debug'