From 9c82be1259a951a8e34459b63f3ad27ea9b95a30 Mon Sep 17 00:00:00 2001 From: Ian Ownbey Date: Mon, 1 Dec 2008 15:52:42 -0800 Subject: Removed request_progress, make it a middlewear or something --- lib/mongrel/http_request.rb | 14 ------ test/unit/test_request_progress.rb | 100 ------------------------------------- 2 files changed, 114 deletions(-) delete mode 100644 test/unit/test_request_progress.rb diff --git a/lib/mongrel/http_request.rb b/lib/mongrel/http_request.rb index 0e3790f..e20434b 100644 --- a/lib/mongrel/http_request.rb +++ b/lib/mongrel/http_request.rb @@ -33,7 +33,6 @@ module Mongrel # we've got everything, pack it up @body = StringIO.new @body.write @params.http_body - update_request_progress(0, content_length) elsif remain > 0 # must read more data to complete body if remain > Const::MAX_BODY @@ -71,15 +70,6 @@ module Mongrel }) end - # updates all dispatchers about our progress - def update_request_progress(clen, total) - return if @dispatchers.nil? || @dispatchers.empty? - @dispatchers.each do |dispatcher| - dispatcher.request_progress(@params, clen, total) - end - end - private :update_request_progress - # Does the heavy lifting of properly reading the larger body requests in # small chunks. It expects @body to be an IO object, @socket to be valid, # and will set @body = nil if the request fails. It also expects any initial @@ -91,15 +81,11 @@ module Mongrel remain -= @body.write(@params.http_body) - update_request_progress(remain, total) - # then stream out nothing but perfectly sized chunks until remain <= 0 or @socket.closed? # ASSUME: we are writing to a disk and these writes always write the requested amount @params.http_body = read_socket(Const::CHUNK_SIZE) remain -= @body.write(@params.http_body) - - update_request_progress(remain, total) end rescue Object => e STDERR.puts "#{Time.now}: Error reading HTTP body: #{e.inspect}" diff --git a/test/unit/test_request_progress.rb b/test/unit/test_request_progress.rb deleted file mode 100644 index a100426..0000000 --- a/test/unit/test_request_progress.rb +++ /dev/null @@ -1,100 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'test/test_helper' - -class UploadBeginHandler < Mongrel::HttpHandler - attr_reader :request_began, :request_progressed, :request_processed - - def initialize - @request_notify = true - end - - def reset - @request_began = false - @request_progressed = false - @request_processed = false - end - - def request_begins(params) - @request_began = true - end - - def request_progress(params,len,total) - @request_progressed = true - end - - def process(request, response) - @request_processed = true - response.start do |head,body| - body.write("test") - end - end - -end - -class RequestProgressTest < Test::Unit::TestCase - def setup - @port = process_based_port - redirect_test_io do - @server = Mongrel::HttpServer.new("127.0.0.1", @port) - end - @handler = UploadBeginHandler.new - @server.register("/upload", @handler) - @server.run - end - - def teardown - @server.stop(true) - end - - def test_begin_end_progress - Net::HTTP.get("localhost", "/upload", @port) - assert @handler.request_began - assert @handler.request_progressed - assert @handler.request_processed - end - - def call_and_assert_handlers_in_turn(handlers) - # reset all handlers - handlers.each { |h| h.reset } - - # make the call - Net::HTTP.get("localhost", "/upload", @port) - - # assert that each one was fired - handlers.each { |h| - assert h.request_began && h.request_progressed && h.request_processed, - "Callbacks NOT fired for #{h}" - } - end - - def test_more_than_one_begin_end_progress - handlers = [@handler] - - second = UploadBeginHandler.new - @server.register("/upload", second) - handlers << second - call_and_assert_handlers_in_turn(handlers) - - # check three handlers - third = UploadBeginHandler.new - @server.register("/upload", third) - handlers << third - call_and_assert_handlers_in_turn(handlers) - - # remove handlers to make sure they've all gone away - @server.unregister("/upload") - handlers.each { |h| h.reset } - Net::HTTP.get("localhost", "/upload", @port) - handlers.each { |h| - assert !h.request_began && !h.request_progressed && !h.request_processed - } - - # re-register upload to the state before this test - @server.register("/upload", @handler) - end -end -- cgit v1.2.3-24-ge0c7