Sha256: 6797c8fda1fd8842f35b89f7c42022edadcb19b8246f90f6ca74336530fef9c4

Contents?: true

Size: 1.78 KB

Versions: 47

Compression:

Stored size: 1.78 KB

Contents

require 'scgi'
require 'stringio'

module Rack
  module Handler
    class SCGI < ::SCGI::Processor
      attr_accessor :app
      
      def self.run(app, options=nil)
        new(options.merge(:app=>app,
                          :host=>options[:Host],
                          :port=>options[:Port],
                          :socket=>options[:Socket])).listen
      end
      
      def initialize(settings = {})
        @app = settings[:app]
        @log = Object.new
        def @log.info(*args); end
        def @log.error(*args); end
        super(settings)
      end
        
      def process_request(request, input_body, socket)
        env = {}.replace(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"] = ""
        env.update({"rack.version" => [0,1],
                     "rack.input" => StringIO.new(input_body),
                     "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.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
    end
  end
end

Version data entries

47 entries across 47 versions & 12 rubygems

Version Path
relevance-castronaut-0.5.2 vendor/rack/lib/rack/handler/scgi.rb
relevance-castronaut-0.5.3 vendor/rack/lib/rack/handler/scgi.rb
relevance-castronaut-0.5.4 vendor/rack/lib/rack/handler/scgi.rb
relevance-castronaut-0.6.0 vendor/rack/lib/rack/handler/scgi.rb
relevance-castronaut-0.6.1 vendor/rack/lib/rack/handler/scgi.rb
relevance-castronaut-0.7.4 vendor/rack/lib/rack/handler/scgi.rb
relevance-castronaut-0.7.5 vendor/rack/lib/rack/handler/scgi.rb
technomancy-rack-0.3.0 lib/rack/handler/scgi.rb
nbudin-castronaut-0.7.5 vendor/rack/lib/rack/handler/scgi.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/handler/scgi.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/handler/scgi.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/handler/scgi.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/handler/scgi.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/handler/scgi.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/handler/scgi.rb
mack-0.8.2 lib/gems/rack-0.4.0/lib/rack/handler/scgi.rb
mack-0.8.3.1 lib/gems/rack-0.9.1/lib/rack/handler/scgi.rb
mack-0.8.3 lib/gems/rack-0.9.1/lib/rack/handler/scgi.rb
passenger-2.1.2 vendor/rack-0.9.1/lib/rack/handler/scgi.rb
passenger-2.2.1 vendor/rack-0.9.1/lib/rack/handler/scgi.rb