This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Hongli Lai (Phusion) (author)
Fri May 09 10:53:45 -0700 2008
| ad9d1365 » | Hongli Lai (Phusion) | 2008-05-09 | 1 | # Phusion Passenger - http://www.modrails.com/ | |
| 2 | # Copyright (C) 2008 Phusion | ||||
| 3 | # | ||||
| 4 | # This program is free software; you can redistribute it and/or modify | ||||
| 5 | # it under the terms of the GNU General Public License as published by | ||||
| 6 | # the Free Software Foundation; version 2 of the License. | ||||
| 7 | # | ||||
| 8 | # This program is distributed in the hope that it will be useful, | ||||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| 11 | # GNU General Public License for more details. | ||||
| 12 | # | ||||
| 13 | # You should have received a copy of the GNU General Public License along | ||||
| 14 | # with this program; if not, write to the Free Software Foundation, Inc., | ||||
| 15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
| 16 | |||||
| 17 | require 'passenger/passenger' | ||||
| 18 | module Passenger | ||||
| 19 | module Rack | ||||
| 20 | |||||
| 21 | # A request handler for Rack applications. | ||||
| 22 | class RequestHandler < AbstractRequestHandler | ||||
| 23 | # Constants which exist to relieve Ruby's garbage collector. | ||||
| 24 | RACK_VERSION = "rack.version" # :nodoc: | ||||
| 25 | RACK_VERSION_VALUE = [0, 1] # :nodoc: | ||||
| 26 | RACK_INPUT = "rack.input" # :nodoc: | ||||
| 27 | RACK_ERRORS = "rack.errors" # :nodoc: | ||||
| 28 | RACK_MULTITHREAD = "rack.multithread" # :nodoc: | ||||
| 29 | RACK_MULTIPROCESS = "rack.multiprocess" # :nodoc: | ||||
| 30 | RACK_RUN_ONCE = "rack.run_once" # :nodoc: | ||||
| 31 | RACK_URL_SCHEME = "rack.url_scheme" # :nodoc: | ||||
| 32 | HTTPS = "HTTPS" # :nodoc: | ||||
| 33 | HTTPS_DOWNCASE = "https" # :nodoc: | ||||
| 34 | HTTP = "http" # :nodoc: | ||||
| 35 | YES = "yes" # :nodoc: | ||||
| 36 | ON = "on" # :nodoc: | ||||
| 37 | ONE = "one" # :nodoc: | ||||
| 38 | CRLF = "\r\n" # :nodoc: | ||||
| 39 | |||||
| 40 | # +app+ is the Rack application object. | ||||
| 41 | def initialize(owner_pipe, app) | ||||
| 42 | super(owner_pipe) | ||||
| 43 | @app = app | ||||
| 44 | end | ||||
| 45 | |||||
| 46 | protected | ||||
| 47 | # Overrided method. | ||||
| 48 | def process_request(env, input, output) | ||||
| 49 | env[RACK_VERSION] = RACK_VERSION_VALUE | ||||
| 50 | env[RACK_INPUT] = input | ||||
| 51 | env[RACK_ERRORS] = STDERR | ||||
| 52 | env[RACK_MULTITHREAD] = false | ||||
| 53 | env[RACK_MULTIPROCESS] = true | ||||
| 54 | env[RACK_RUN_ONCE] = false | ||||
| 55 | if env[HTTPS] == YES || env[HTTPS] == ON || env[HTTPS] == ONE | ||||
| 56 | env[RACK_URL_SCHEME] = HTTPS_DOWNCASE | ||||
| 57 | else | ||||
| 58 | env[RACK_URL_SCHEME] = HTTP | ||||
| 59 | end | ||||
| 60 | |||||
| 61 | status, headers, body = @app.call(env) | ||||
| 62 | begin | ||||
| 63 | output.write("Status: #{status}\r\n") | ||||
| 64 | headers[X_POWERED_BY] = PASSENGER_HEADER | ||||
| 65 | headers.each do |k, vs| | ||||
| 66 | vs.each do |v| | ||||
| 67 | output.write("#{k}: #{v}\r\n") | ||||
| 68 | end | ||||
| 69 | end | ||||
| 70 | output.write(CRLF) | ||||
| 71 | body.each do |s| | ||||
| 72 | output.write(s) | ||||
| 73 | end | ||||
| 74 | ensure | ||||
| 75 | body.close if body.respond_to?(:close) | ||||
| 76 | end | ||||
| 77 | end | ||||
| 78 | end | ||||
| 79 | |||||
| 80 | end # module Rack | ||||
| 81 | end # module Passenger | ||||






