Sha256: cd263ba229c4b23219a3876010ee7eabfe337b8c964f4e14a7974c2419854b32

Contents?: true

Size: 1.53 KB

Versions: 222

Compression:

Stored size: 1.53 KB

Contents

require 'rack/content_length'
require 'rack/rewindable_input'

module Rack
  module Handler
    class CGI
      def self.run(app, options=nil)
        $stdin.binmode
        serve app
      end

      def self.serve(app)
        env = ENV.to_hash
        env.delete "HTTP_CONTENT_LENGTH"

        env["SCRIPT_NAME"] = ""  if env["SCRIPT_NAME"] == "/"

        env.update({"rack.version" => Rack::VERSION,
                     "rack.input" => Rack::RewindableInput.new($stdin),
                     "rack.errors" => $stderr,

                     "rack.multithread" => false,
                     "rack.multiprocess" => true,
                     "rack.run_once" => true,

                     "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
                   })

        env["QUERY_STRING"] ||= ""
        env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
        env["REQUEST_PATH"] ||= "/"

        status, headers, body = app.call(env)
        begin
          send_headers status, headers
          send_body body
        ensure
          body.close  if body.respond_to? :close
        end
      end

      def self.send_headers(status, headers)
        $stdout.print "Status: #{status}\r\n"
        headers.each { |k, vs|
          vs.split("\n").each { |v|
            $stdout.print "#{k}: #{v}\r\n"
          }
        }
        $stdout.print "\r\n"
        $stdout.flush
      end

      def self.send_body(body)
        body.each { |part|
          $stdout.print part
          $stdout.flush
        }
      end
    end
  end
end

Version data entries

222 entries across 190 versions & 35 rubygems

Version Path
challah-1.0.0 vendor/bundle/gems/rack-1.5.2/lib/rack/handler/cgi.rb
classiccms-0.7.2 vendor/bundle/gems/rack-1.4.1/lib/rack/handler/cgi.rb
classiccms-0.7.1 vendor/bundle/gems/rack-1.4.1/lib/rack/handler/cgi.rb
swipe-rails-0.0.5 vendor/bundle/gems/rack-1.4.5/lib/rack/handler/cgi.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/cgi.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/cgi.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/cgi.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/cgi.rb
classiccms-0.7.0 vendor/bundle/gems/rack-1.4.1/lib/rack/handler/cgi.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/rack-1.4.5/lib/rack/handler/cgi.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/cgi.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/rack-1.4.5/lib/rack/handler/cgi.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/cgi.rb
challah-1.0.0.beta3 vendor/bundle/gems/rack-1.4.5/lib/rack/handler/cgi.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/cgi.rb
challah-1.0.0.beta2 vendor/bundle/gems/rack-1.4.5/lib/rack/handler/cgi.rb
challah-1.0.0.beta vendor/bundle/gems/rack-1.4.5/lib/rack/handler/cgi.rb
challah-1.0.0.beta vendor/bundle/gems/rack-1.4.3/lib/rack/handler/cgi.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/cgi.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/cgi.rb