diff options
author | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-06-25 14:49:46 +0000 |
---|---|---|
committer | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-06-25 14:49:46 +0000 |
commit | f26ffd1a9112876f3508a152f6f79361a06285f7 (patch) | |
tree | 02183dd93a3a96c203d7c99e071d287214ed91ff /lib | |
parent | 49856e52b045cac75e064e498e68ce3cfa48026c (diff) | |
download | unicorn-f26ffd1a9112876f3508a152f6f79361a06285f7.tar.gz |
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@260 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mongrel.rb | 18 | ||||
-rw-r--r-- | lib/mongrel/handlers.rb | 9 |
2 files changed, 18 insertions, 9 deletions
diff --git a/lib/mongrel.rb b/lib/mongrel.rb index 08417e9..55aaa39 100644 --- a/lib/mongrel.rb +++ b/lib/mongrel.rb @@ -184,7 +184,12 @@ module Mongrel # # The HttpRequest.initialize method will convert any request that is larger than # Const::MAX_BODY into a Tempfile and use that as the body. Otherwise it uses - # a StringIO object. To be safe, you should assume it works like a file. + # a StringIO object. To be safe, you should assume it works like a file. + # + # The HttpHandler.request_notify system is implemented by having HttpRequest call + # HttpHandler.request_begins, HttpHandler.request_progress, HttpHandler.process during + # the IO processing. This adds a small amount of overhead but lets you implement + # finer controlled handlers and filters. class HttpRequest attr_reader :body, :params @@ -209,9 +214,11 @@ module Mongrel begin @body.write(initial_body) + notifier.request_begins(params) if notifier # write the odd sized chunk first clen -= @body.write(@socket.read(clen % Const::CHUNK_SIZE)) + notifier.request_progress(params, clen, total) if notifier # then stream out nothing but perfectly sized chunks while clen > 0 and !@socket.closed? @@ -227,7 +234,6 @@ module Mongrel @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 @@ -539,17 +545,11 @@ 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 + notifier = handlers[0].request_notify ? handlers[0] : 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 - notifier = handlers[0] - notifier.request_begins(params) - end - request = HttpRequest.new(params, data, client, notifier) # in the case of large file uploads the user could close the socket, so skip those requests diff --git a/lib/mongrel/handlers.rb b/lib/mongrel/handlers.rb index f7f7e74..2a72ebd 100644 --- a/lib/mongrel/handlers.rb +++ b/lib/mongrel/handlers.rb @@ -41,6 +41,12 @@ module Mongrel def request_begins(params) end + # Called by Mongrel for each IO chunk that is received on the request socket + # from the client, allowing you to track the progress of the IO and monitor + # the input. + def request_progress(params, clen, total) + end + def process(request, response) end @@ -59,6 +65,9 @@ module Mongrel def request_begins(params) end + def request_progress(params, clen, total) + end + def initialize(options={}) @options = options @header_only = false |