Class: Rack::Handler::FTW

Inherits:
Object
  • Object
show all
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
FTW_DOT_CONNECTION =

A string constant value (used to avoid typos).

"ftw.connection".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, config) ⇒ FTW

setup a new rack server



68
69
70
71
# File 'lib/rack/handler/ftw.rb', line 68

def initialize(app, config)
  @app = app
  @config = config
end

Class Method Details

.run(app, config) ⇒ Object

This method is invoked when rack starts this as the server.



60
61
62
63
# File 'lib/rack/handler/ftw.rb', line 60

def self.run(app, config)
  server = self.new(app, config)
  server.run
end

Instance Method Details

#runObject

Run the server.

Connections are farmed out to threads.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rack/handler/ftw.rb', line 76

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."""
  #
  server = FTW::Server.new([@config[:Host], @config[:Port]].join(":"))
  server.each_connection do |connection|
    Thread.new do
      handle_connection(connection)
    end
  end
end