-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Showing
2 changed files
with
43 additions
and
0 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
require 'rack/handler' | |||
require 'puma' | |||
|
|||
module Rack | |||
module Handler | |||
module Puma | |||
DEFAULT_OPTIONS = {:Host => '0.0.0.0', :Port => 8080, :Threads => '0:16'} | |||
|
|||
def self.run(app, options = {}) | |||
options = DEFAULT_OPTIONS.merge(options) | |||
server = ::Puma::Server.new(app) | |||
min, max = options[:Threads].split(':', 2) | |||
|
|||
server.add_tcp_listener options[:Host], options[:Port] | |||
server.min_threads = Integer(min) | |||
server.max_threads = Integer(max) | |||
yield server if block_given? | |||
|
|||
server.run.join | |||
end | |||
|
|||
def self.valid_options | |||
{ | |||
"Host=HOST" => "Hostname to listen on (default: localhost)", | |||
"Port=PORT" => "Port to listen on (default: 8080)", | |||
"Threads=MIN:MAX" => "min:max threads to use (default 0:16)" | |||
} | |||
end | |||
end | |||
|
|||
register :puma, Puma | |||
end | |||
end |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
require 'test/unit' | |||
|
|||
class TestPumaUnixSocket < Test::Unit::TestCase | |||
def test_handler | |||
handler = Rack::Handler.get(:puma) | |||
assert_equal Rack::Handler::Puma, handler | |||
handler = Rack::Handler.get('Puma') | |||
assert_equal Rack::Handler::Puma, handler | |||
end | |||
end |