From ff3dd15bc2f3eca956c7dc79d7c01a5f8402af3d Mon Sep 17 00:00:00 2001 From: zedshaw Date: Sun, 25 Jun 2006 03:38:54 +0000 Subject: [PATCH] Implemented request_progress for HttpHandlers. git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@257 19e92222-5c0b-0410-8929-a290d50e31e9 --- lib/mongrel.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/mongrel.rb b/lib/mongrel.rb index d1d669f0..ae414728 100644 --- a/lib/mongrel.rb +++ b/lib/mongrel.rb @@ -193,11 +193,12 @@ module Mongrel # body data into the HttpRequest.body attribute. # # TODO: Implement tempfile removal when the request is done. - def initialize(params, initial_body, socket) + def initialize(params, initial_body, socket, notifier) @params = params @socket = socket clen = params[Const::CONTENT_LENGTH].to_i - initial_body.length + total = clen if clen > Const::MAX_BODY @body = Tempfile.new(Const::MONGREL_TMP_BASE) @@ -219,12 +220,14 @@ module Mongrel raise "Socket closed or read failure" if not data or data.length != Const::CHUNK_SIZE clen -= @body.write(data) # ASSUME: we are writing to a disk and these writes always write the requested amount + notifier.request_progress(clen, total) if notifier end # rewind to keep the world happy @body.rewind rescue Object # any errors means we should delete the file, including if the file is dumped + STDERR.puts "ERROR: #$!" @socket.close unless @socket.closed? @body.delete if @body.class == Tempfile @body = nil # signals that there was a problem @@ -536,16 +539,18 @@ module Mongrel params[Const::PATH_INFO] = path_info params[Const::SCRIPT_NAME] = script_name params[Const::REMOTE_ADDR] = params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last + notifier = nil # TODO: Find a faster/better way to carve out the range, preferably without copying. data = data[nparsed ... data.length] || "" if handlers[0].request_notify # this first handler wants to be notified when the process starts - handlers[0].request_begins(params) + notifier = handlers[0] + notifier.request_begins(params) end - request = HttpRequest.new(params, data, client) + request = HttpRequest.new(params, data, client, notifier) # in the case of large file uploads the user could close the socket, so skip those requests break if request.body == nil # nil signals from HttpRequest::initialize that the request was aborted