diff options
Diffstat (limited to 'lib/mongrel')
-rw-r--r-- | lib/mongrel/http_request.rb | 21 | ||||
-rw-r--r-- | lib/mongrel/http_response.rb | 21 |
2 files changed, 31 insertions, 11 deletions
diff --git a/lib/mongrel/http_request.rb b/lib/mongrel/http_request.rb index c8d4ce4..8df3a5a 100644 --- a/lib/mongrel/http_request.rb +++ b/lib/mongrel/http_request.rb @@ -58,6 +58,25 @@ module Mongrel @body.rewind if @body end + # returns an environment which is rackable + # http://rack.rubyforge.org/doc/files/SPEC.html + def env + env = params.clone + env.delete "HTTP_CONTENT_TYPE" + env.delete "HTTP_CONTENT_LENGTH" + env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" + env.update({"rack.version" => [0,1], + "rack.input" => @body, + "rack.errors" => STDERR, + + "rack.multithread" => true, + "rack.multiprocess" => false, # ??? + "rack.run_once" => false, + + "rack.url_scheme" => "http", + }) + end + # updates all dispatchers about our progress def update_request_progress(clen, total) return if @dispatchers.nil? || @dispatchers.empty? @@ -152,4 +171,4 @@ module Mongrel return params end end -end
\ No newline at end of file +end diff --git a/lib/mongrel/http_response.rb b/lib/mongrel/http_response.rb index 3076712..08d4d75 100644 --- a/lib/mongrel/http_response.rb +++ b/lib/mongrel/http_response.rb @@ -39,12 +39,13 @@ module Mongrel attr_reader :header_sent attr_reader :status_sent - def initialize(socket) + def initialize(socket, app_responce) @socket = socket - @body = StringIO.new - @status = 404 + @app_responce = app_responce + @body = app_responce[2] + @status = app_responce[0] @reason = nil - @header = HeaderOut.new(StringIO.new) + @header = HeaderOut.new(app_responce[1]) @header[Const::DATE] = Time.now.httpdate @body_sent = false @header_sent = false @@ -59,10 +60,10 @@ module Mongrel # by simple passing "finalize=true" to the start method. By default # all handlers run and then mongrel finalizes the request when they're # all done. - def start(status=200, finalize=false, reason=nil) - @status = status.to_i - @reason = reason - yield @header, @body + # TODO: docs + def start #(status=200, finalize=false, reason=nil) + @reason = nil # TODO take this out + out.write(@body) finished if finalize end @@ -78,7 +79,7 @@ module Mongrel # XXX Dubious ( http://mongrel.rubyforge.org/ticket/19 ) @header.out.close @header = HeaderOut.new(StringIO.new) - + @body.close @body = StringIO.new end @@ -163,4 +164,4 @@ module Mongrel end end -end
\ No newline at end of file +end |