Return-Path: Delivered-To: apmail-httpd-apreq-dev-archive@www.apache.org Received: (qmail 59368 invoked from network); 3 Aug 2004 02:39:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 3 Aug 2004 02:39:10 -0000 Received: (qmail 29898 invoked by uid 500); 3 Aug 2004 02:39:10 -0000 Delivered-To: apmail-httpd-apreq-dev-archive@httpd.apache.org Received: (qmail 29852 invoked by uid 500); 3 Aug 2004 02:39:09 -0000 Mailing-List: contact apreq-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list apreq-dev@httpd.apache.org Received: (qmail 29838 invoked by uid 99); 3 Aug 2004 02:39:09 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received: from [80.91.224.249] (HELO main.gmane.org) (80.91.224.249) by apache.org (qpsmtpd/0.27.1) with ESMTP; Mon, 02 Aug 2004 19:39:08 -0700 Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1BrpCk-0005Pz-00 for ; Tue, 03 Aug 2004 04:39:06 +0200 Received: from adsl-34-76-42.mia.bellsouth.net ([67.34.76.42]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 03 Aug 2004 04:39:06 +0200 Received: from joe+gmane by adsl-34-76-42.mia.bellsouth.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 03 Aug 2004 04:39:06 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: apreq-dev@httpd.apache.org To: apreq-dev@httpd.apache.org From: Joe Schaefer Subject: Re: Error handling in latest dev snapshot Date: 02 Aug 2004 22:39:03 -0400 Lines: 58 Message-ID: <878ycx54jc.fsf@gemini.sunstarsys.com> References: <61769.69.17.66.125.1091417491.squirrel@mail.redhotpenguin.com> <87ekmp5klh.fsf@gemini.sunstarsys.com> <63347.69.17.66.125.1091492475.squirrel@mail.redhotpenguin.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: adsl-34-76-42.mia.bellsouth.net Mail-Copies-To: never User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N fred@taperfriendlymusic.org writes: [...] > If part of the data is bad or contains some information I want to > abort the upload and redirect. I thought a good approach would be to > die inside the $upload_hook sub, catch it and redirect but maybe there > is a more elegant solution. Having the upload hook die is the proper way to tell the mfd parser to immediately abort (the upload that triggered the hook to croak will not appear in the body table). However this will leave the parser in an error state, so any Apache::Request method that requires a successful parse will wind up throwing an Apache::Request::Error. To catch it, the caller can use an eval {} wrapper eval { $self->upload($r) }; # run my upload method if (ref $@ and $@->isa("Apache::Request::Error")) { # ... handle Apache::Request::Error object in $@ } or the upload method can force an immediate full parse, using say scalar $req->parse(). An error occurred if its return value is non-zero. > Any feedback on this is appreciated. > > sub upload : method { > my $self = shift; > my $r = shift; > my $upload_hook = sub { > my ($upload, $data, $data_len, $hook_data) = @_; > # do some stuff with $data > # Die and/or redirect if $data fits a certain profile > } > my $req = Apache::Request->new($r, > HOOK_DATA => 'Note', > UPLOAD_HOOK => $upload_hook, > TEMP_DIR => '/tmp' ); > my $upload = $req->upload(($req->upload)[0]); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This is a very bad idiom, and should be removed from our tests. It would be a bit safer to write this my $upload = $req->upload(scalar +($req->upload)[0]); because ($req->upload)[0] is the empty list when no uploads are sent (in that case $upload is not an undef, but an empty Apache::Upload::Table instead). -- Joe Schaefer