httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@taperfriendlymusic.org
Subject Re: Error handling in latest dev snapshot
Date Tue, 03 Aug 2004 00:21:15 GMT
> fred@taperfriendlymusic.org writes:
>
>> Using libapreq2-2.04-dev, in a upload_hook subroutine my code dies on
>> an error condition and I get the following error message:
>>
>> [Sun Aug 01 23:13:46 2004] [error] [client 127.0.0.1]
>> Apache::Request::upload: (20014) Error string not specified yet
>
> You should not call $req->upload within an upload hook.  Hooks are
> parser extensions and are *not suitable* for casual use.  Don't use
> UPLOAD_HOOK unless you absolutely must process the upload data
> *during parsing*.

My call to $req->upload is made outside of the upload_hook sub.  My
application is required to process the upload data during parsing so I
thought this was the best approach.  The other option I had in mind was to
process the data using an input filter and the bucket brigades api but
this looked easier and more like the right tool for the job.

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.  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]);
  # redirect at end of upload
}

>
> --
> Joe Schaefer
>
>


Mime
View raw message