lib/merb/merb_upload_handler.rb in merb-0.0.9 vs lib/merb/merb_upload_handler.rb in merb-0.1.0

- old
+ new

@@ -1,6 +1,27 @@ -require 'mongrel' +module Mongrel + module Const + POST = 'POST'.freeze unless const_defined?(:POST) + QUERY_STRING = 'QUERY_STRING'.freeze unless const_defined?(:QUERY_STRING) + UPLOAD_ID = 'upload_id'.freeze + end + + HttpHandler.class_eval do + def request_aborted(params) + end + end + + HttpRequest.class_eval do + def initialize_with_abort(params, socket, dispatchers) + initialize_without_abort(params, socket, dispatchers) + dispatchers.each {|d| d.request_aborted(params) if @body.nil? && d } + end + + alias_method :initialize_without_abort, :initialize + alias_method :initialize, :initialize_with_abort + end +end class MerbUploadHandler < Mongrel::HttpHandler def initialize(options = {}) @@ -26,9 +47,17 @@ upload_notify(:mark, params, clen) end def process(request, response) upload_notify(:finish, request.params) + end + + def request_aborted(params) + return unless params[Mongrel::Const::PATH_INFO] == @path_info && + params[Mongrel::Const::REQUEST_METHOD] == Mongrel::Const::POST && + upload_id = Mongrel::HttpRequest.query_parse(params[Mongrel::Const::QUERY_STRING])[Mongrel::Const::UPLOAD_ID] + Mongrel::Uploads.finish(upload_id) + puts "request aborted!" end private def upload_notify(action, params, *args) return unless @path_info.include?(params['PATH_INFO']) &&