Class: Rack::Handler::SCGI
- Inherits:
-
SCGI::Processor
- Object
- SCGI::Processor
- Rack::Handler::SCGI
- Defined in:
- rack/rack/handler/scgi.rb
Instance Attribute Summary (collapse)
-
- (void) app
Returns the value of attribute app.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (SCGI) initialize(settings = {})
constructor
A new instance of SCGI.
- - (void) process_request(request, input_body, socket)
Constructor Details
- (SCGI) initialize(settings = {})
Returns a new instance of SCGI
26 27 28 29 |
# File 'rack/rack/handler/scgi.rb', line 26 def initialize(settings = {}) @app = settings[:app] super(settings) end |
Instance Attribute Details
- (void) app
Returns the value of attribute app
9 10 11 |
# File 'rack/rack/handler/scgi.rb', line 9 def app @app end |
Class Method Details
+ (void) run(app, options = nil)
11 12 13 14 15 16 17 |
# File 'rack/rack/handler/scgi.rb', line 11 def self.run(app, =nil) [:Socket] = UNIXServer.new([:File]) if [:File] new(.merge(:app=>app, :host=>[:Host], :port=>[:Port], :socket=>[:Socket])).listen end |
+ (void) valid_options
19 20 21 22 23 24 |
# File 'rack/rack/handler/scgi.rb', line 19 def self. { "Host=HOST" => "Hostname to listen on (default: localhost)", "Port=PORT" => "Port to listen on (default: 8080)", } end |
Instance Method Details
- (void) process_request(request, input_body, socket)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'rack/rack/handler/scgi.rb', line 31 def process_request(request, input_body, socket) env = Hash[request] env.delete "HTTP_CONTENT_TYPE" env.delete "HTTP_CONTENT_LENGTH" env["REQUEST_PATH"], env["QUERY_STRING"] = env["REQUEST_URI"].split('?', 2) env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] env["PATH_INFO"] = env["REQUEST_PATH"] env["QUERY_STRING"] ||= "" env["SCRIPT_NAME"] = "" rack_input = StringIO.new(input_body) rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding) env.update({"rack.version" => Rack::VERSION, "rack.input" => rack_input, "rack.errors" => $stderr, "rack.multithread" => true, "rack.multiprocess" => true, "rack.run_once" => false, "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http" }) status, headers, body = app.call(env) begin socket.write("Status: #{status}\r\n") headers.each do |k, vs| vs.split("\n").each { |v| socket.write("#{k}: #{v}\r\n")} end socket.write("\r\n") body.each {|s| socket.write(s)} ensure body.close if body.respond_to? :close end end |