Class: Rack::Handler::FTW
- Inherits:
-
Object
- Object
- Rack::Handler::FTW
- Includes:
- FTW::CRLF, FTW::Protocol
- Defined in:
- lib/rack/handler/ftw.rb
Overview
FTW cannot fully respect the Rack 1.1 specification due to technical limitations in the Rack design, specifically:
-
rack.input must be buffered, to support IO#rewind, for the duration of each request. This is not safe if that request is an HTTP Upgrade or a long upload.
FTW::Connection does not implement #rewind. Need it? File a ticket.
To support HTTP Upgrade, CONNECT, and protocol-switching features, this server handler will set “ftw.connection” to the FTW::Connection related to this request.
The above data is based on the response to this ticket:
https://github.com/rack/rack/issues/347
Constant Summary collapse
- RACK_VERSION =
The version of the rack specification supported by this handler.
[1,1]
- REQUEST_METHOD =
A string constant value (used to avoid typos).
"REQUEST_METHOD".freeze
- SCRIPT_NAME =
A string constant value (used to avoid typos).
"SCRIPT_NAME".freeze
- PATH_INFO =
A string constant value (used to avoid typos).
"PATH_INFO".freeze
- QUERY_STRING =
A string constant value (used to avoid typos).
"QUERY_STRING".freeze
- SERVER_NAME =
A string constant value (used to avoid typos).
"SERVER_NAME".freeze
- SERVER_PORT =
A string constant value (used to avoid typos).
"SERVER_PORT".freeze
- RACK_DOT_VERSION =
A string constant value (used to avoid typos).
"rack.version".freeze
- RACK_DOT_URL_SCHEME =
A string constant value (used to avoid typos).
"rack.url_scheme".freeze
- RACK_DOT_INPUT =
A string constant value (used to avoid typos).
"rack.input".freeze
- RACK_DOT_ERRORS =
A string constant value (used to avoid typos).
"rack.errors".freeze
- RACK_DOT_MULTITHREAD =
A string constant value (used to avoid typos).
"rack.multithread".freeze
- RACK_DOT_MULTIPROCESS =
A string constant value (used to avoid typos).
"rack.multiprocess".freeze
- RACK_DOT_RUN_ONCE =
A string constant value (used to avoid typos).
"rack.run_once".freeze
- RACK_DOT_LOGGER =
A string constant value (used to avoid typos).
"rack.logger".freeze
- FTW_DOT_CONNECTION =
A string constant value (used to avoid typos).
"ftw.connection".freeze
Class Method Summary collapse
-
.run(app, config) ⇒ Object
This method is invoked when rack starts this as the server.
Instance Method Summary collapse
-
#initialize(app, config) ⇒ FTW
constructor
setup a new rack server.
-
#run ⇒ Object
Run the server.
-
#stop ⇒ Object
def run.
Constructor Details
#initialize(app, config) ⇒ FTW
setup a new rack server
72 73 74 75 76 |
# File 'lib/rack/handler/ftw.rb', line 72 def initialize(app, config) @app = app @config = config @threads = [] end |
Class Method Details
.run(app, config) ⇒ Object
This method is invoked when rack starts this as the server.
63 64 65 66 67 |
# File 'lib/rack/handler/ftw.rb', line 63 def self.run(app, config) #@logger.subscribe(STDOUT) server = self.new(app, config) server.run end |
Instance Method Details
#run ⇒ Object
Run the server.
Connections are farmed out to threads.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rack/handler/ftw.rb', line 81 def run # {:environment=>"development", :pid=>nil, :Port=>9292, :Host=>"0.0.0.0", # :AccessLog=>[], :config=>"/home/jls/projects/ruby-ftw/examples/test.ru", # :server=>"FTW"} # # listen, pass connections off # # # """A Rack application is an Ruby object (not a class) that responds to # call. It takes exactly one argument, the environment and returns an # Array of exactly three values: The status, the headers, and the body.""" # logger.info("Starting server", :config => @config) @server = FTW::Server.new([@config[:Host], @config[:Port]].join(":")) @server.each_connection do |connection| # The rack specification insists that 'rack.input' objects support # #rewind. Bleh. Just lie about it and monkeypatch it in. # This is required for Sinatra to accept 'post' requests, otherwise # it barfs. class << connection def rewind(*args) # lolrack, nothing to do here. end end @threads << Thread.new do handle_connection(connection) end end end |
#stop ⇒ Object
def run
112 113 114 115 |
# File 'lib/rack/handler/ftw.rb', line 112 def stop @server.stop unless @server.nil? @threads.each(&:join) end |