/usr/lib/ruby/vendor_ruby/merb-core/rack/handler/mongrel.rb is in ruby-merb-core 1.1.3+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | require 'stringio'
class Mongrel::HttpResponse
NO_CLOSE_STATUS_FORMAT = "HTTP/1.1 %d %s\r\n".freeze
# Sends the status to the client without closing the connection.
#
# ==== Parameters
# content_length<Fixnum>:: The length of the content. Defaults to body length.
def send_status_no_connection_close(content_length=@body.length)
unless @status_sent
write(NO_CLOSE_STATUS_FORMAT % [@status, Mongrel::HTTP_STATUS_CODES[@status]])
@status_sent = true
end
end
end
module Merb
module Rack
module Handler
class Mongrel < ::Mongrel::HttpHandler
# Runs the server and yields it to a block.
#
# ==== Parameters
# app<Merb::Rack::Application>:: The app that Mongrel should handle.
# options<Hash>:: Options to pass to Mongrel (see below).
#
# ==== Block parameters
# server<Mongrel::HttpServer>:: The server to run.
#
# ==== Options (options)
# :Host<String>::
# The hostname on which the app should run. Defaults to "0.0.0.0"
# :Port<Fixnum>:: The port for the app. Defaults to 8080.
#
# :api: plugin
def self.run(app, options={})
@server = ::Mongrel::HttpServer.new(options[:Host] || '0.0.0.0',
options[:Port] || 8080)
@server.register('/', ::Merb::Rack::Handler::Mongrel.new(app))
yield @server if block_given?
@server.run.join
end
# :api: private
def self.stop(block = true)
@server.stop
end
# ==== Parameters
# app<Merb::Rack::Application>:: The app that Mongrel should handle.
#
# :api: plugin
def initialize(app)
@app = app
end
# ==== Parameters
# request<Merb::Request>:: The HTTP request to handle.
# response<HTTPResponse>:: The response object to write response to.
#
# :api: plugin
def process(request, response)
env = {}.replace(request.params)
env.delete Merb::Const::HTTP_CONTENT_TYPE
env.delete Merb::Const::HTTP_CONTENT_LENGTH
env[Merb::Const::SCRIPT_NAME] = Merb::Const::EMPTY_STRING if env[Merb::Const::SCRIPT_NAME] == Merb::Const::SLASH
env.update({"rack.version" => [0,1],
"rack.input" => request.body || StringIO.new(""),
"rack.errors" => STDERR,
"rack.multithread" => true,
"rack.multiprocess" => false, # ???
"rack.run_once" => false,
"rack.url_scheme" => "http"
})
env[Merb::Const::QUERY_STRING] ||= ""
env.delete Merb::Const::PATH_INFO if env[Merb::Const::PATH_INFO] == Merb::Const::EMPTY_STRING
status, headers, body = @app.call(env)
begin
response.status = status.to_i
response.send_status(nil)
headers.each { |k, vs|
vs.split(Merb::Const::NEWLINE).each { |v|
response.header[k] = v
}
}
response.send_header
body.each { |part|
response.write(part)
response.socket.flush
}
response.done = true
ensure
body.close if body.respond_to? :close
end
end
end
end
end
end
|