diff --git a/core/lib/Foswiki/Engine.pm b/core/lib/Foswiki/Engine.pm index 34e5c35b66..3ba4dcd5a8 100644 --- a/core/lib/Foswiki/Engine.pm +++ b/core/lib/Foswiki/Engine.pm @@ -85,8 +85,7 @@ has connectionData => Parameter attributes are arrays of hashrefs with keys =-name= and =-value= where the former is a plain string and the latter may be either a scalar or an -arrayref. In addition to those two =bodyParamaters= element hashref may contain -additional key =-upload= which value is boolean. +arrayref. =cut @@ -423,7 +422,7 @@ sub _preparePath { } sub _prepareBodyParameters { return []; } # Abstract initializer for uploads -sub _prepareUploads { return {}; } +sub _prepareUploads { return []; } =begin TML diff --git a/core/lib/Foswiki/Engine/PSGI.pm b/core/lib/Foswiki/Engine/PSGI.pm index 7189cf1266..13538fd396 100644 --- a/core/lib/Foswiki/Engine/PSGI.pm +++ b/core/lib/Foswiki/Engine/PSGI.pm @@ -147,11 +147,6 @@ around _prepareBodyParameters => sub { my $param = { -name => $upname, -value => \@values, - - # SMELL uploads are handled by dedicated psgi->uploads - # Note that we record the encoded name of the upload. It will be - # decoded in prepareUploads, which rewrites the {uploads} hash. - -upload => ( scalar( $psgi->upload($pname) ) ? 1 : 0 ), }; push @params, $param; } @@ -197,6 +192,7 @@ around _prepareUploads => sub { filename => $upload->filename, basename => $upload->basename, tmpname => $upload->path, + headers => $upload->headers, contentType => $upload->content_type, size => $upload->size, }; diff --git a/core/lib/Foswiki/Exception.pm b/core/lib/Foswiki/Exception.pm index df58eb802b..e43fbad546 100644 --- a/core/lib/Foswiki/Exception.pm +++ b/core/lib/Foswiki/Exception.pm @@ -384,11 +384,11 @@ sub errorStr { return $str; } -package Foswiki::Exception::ASSERT; +package Foswiki::Exception::Harmless; use Moo; extends qw(Foswiki::Exception); -# This class is only for distinguishing ASSERT-generated exceptions. +# For informational exceptions. package Foswiki::Exception::Fatal; use Moo; @@ -396,9 +396,67 @@ extends qw(Foswiki::Exception); # To cover perl/system errors. +package Foswiki::Exception::ASSERT; +use Moo; +extends qw(Foswiki::Exception::Fatal); + +# This class is only for distinguishing ASSERT-generated exceptions. + +=begin TML + +---++ Exception Foswiki::Exception::CB + +Root of callback support exception tree. + +=cut + +package Foswiki::Exception::CB; +use Moo; +extends qw(Foswiki::Exception); + +=begin TML + +---+ Exception Foswiki::Exception::CB::Last + +Must be raised by a callback code to signal it wants to be the last on the +execution chain. + +=cut + +package Foswiki::Exception::CB::Last; +use Moo; +extends qw(Foswiki::Exception::CB); + +=begin TML + +---++ ObjectAttribute returnValue + +The value to be returned by =Foswiki::Aux::Callbacks::callback()= method. + +=cut + +has returnValue => ( + is => 'ro', + predicate => 1, +); + +=begin TML + +---+ Exception Foswiki::Exception::Cfg::InvalidKeyName + +If configuration key doesn't pass validation. + +=cut + +package Foswiki::Exception::Cfg::InvalidKeyName; +use Moo; +extends qw(Foswiki::Exception::Fatal); + +has keyName => ( is => 'rw', required => 1, ); + =begin TML ----++ Exception Foswiki::Exception::HTTPResponse +---+ Exception Foswiki::Exception::HTTPResponse Used to send HTTP status responses to the user. @@ -526,44 +584,6 @@ around BUILDARGS => sub { return $orig->( $class, %params ); }; -=begin TML - ----++ Exception Foswiki::Exception::CB - -Root of callback support exception tree. - -=cut - -package Foswiki::Exception::CB; -use Moo; -extends qw(Foswiki::Exception); - -=begin TML - ----++ Exception Foswiki::Exception::CB::Last - -Must be raised by a callback code to signal it wants to be the last on the -execution chain. - -=cut - -package Foswiki::Exception::CB::Last; -use Moo; -extends qw(Foswiki::Exception::CB); - -=begin TML - ----++ ObjectAttribute returnValue - -The value to be returned by =Foswiki::Aux::Callbacks::callback()= method. - -=cut - -has returnValue => ( - is => 'ro', - predicate => 1, -); - 1; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/lib/Foswiki/Request.pm b/core/lib/Foswiki/Request.pm index ce59f16176..79bdd42523 100644 --- a/core/lib/Foswiki/Request.pm +++ b/core/lib/Foswiki/Request.pm @@ -19,7 +19,7 @@ Fields: * =remote_user= Remote HTTP authenticated user * =secure= Boolean value about use of encryption * =server_port= Port that the webserver listens on - * =uploads= arrayref of Foswiki::Request::Upload objects + * =uploads= hashref of Foswiki::Request::Upload objects * =uri= the request uri The following fields are parsed from the =pathInfo= @@ -155,7 +155,7 @@ has _param => ( is => 'rw', lazy => 1, default => sub { {} }, ); =begin TML ----++ ObjectAttribute uploads( [ \%uploads ] ) -> $hashref +---++ ObjectAttribute uploads -> $hashref Gets/Sets request uploads field. Keys are uploaded file names, as sent by browser, and values are Foswiki::Request::Upload objects. @@ -166,18 +166,9 @@ has uploads => ( is => 'rw', lazy => 1, builder => '_establishUploads', - isa => Foswiki::Object::isaARRAY( 'uploads', noUndef => 1 ), + isa => Foswiki::Object::isaHASH( 'uploads', noUndef => 1 ), ); -# upload_list attribute keeps list of request uploads. Used to initialize -# uploads attribute with corresponding =Foswiki::Request::Upload= instances. -# SMELL Isn't it needed for engine code only? -has upload_list => ( - is => 'rw', - lazy => 1, - default => sub { [] }, - isa => Foswiki::Object::isaARRAY( 'upload_list', noUndef => 1, ), -); has param_list => ( is => 'rw', predicate => 1, @@ -685,6 +676,10 @@ sub delete { my $this = shift; foreach my $p (@_) { next unless exists $this->_param->{$p}; + my $pval = $this->param($p); + if ( exists $this->uploads->{$pval} ) { + CORE::delete $this->uploads->{$pval}; + } CORE::delete $this->_param->{$p}; } my %deleted_key = map { $_ => 1 } @_; @@ -1268,10 +1263,6 @@ sub _establishParamList { # Process body parameters individually to take care of uploads. foreach my $param ( @{ $engine->bodyParameters } ) { - if ( $param->{-upload} ) { - push @{ $this->upload_list }, $param->{-name}; - delete $param->{-upload}; - } push @params, $param; } $this->param($_) foreach @params; @@ -1298,12 +1289,12 @@ sub _establishMethod { sub _establishUploads { my $this = shift; my $rawUploads = $this->app->engine->uploads; - my @reqUploads; + my %reqUploads; foreach my $upload (@$rawUploads) { - push @reqUploads, - $this->create( 'Foswiki::Request::Upload', %$upload, ); + $reqUploads{ $upload->{filename} } = + $this->create( 'Foswiki::Request::Upload', %$upload ); } - return \@reqUploads; + return \%reqUploads; } =begin TML diff --git a/core/lib/Foswiki/Request/Upload.pm b/core/lib/Foswiki/Request/Upload.pm index 7ed3fb8031..c0376b66e7 100644 --- a/core/lib/Foswiki/Request/Upload.pm +++ b/core/lib/Foswiki/Request/Upload.pm @@ -19,6 +19,7 @@ use Moo; use namespace::clean; extends qw(Foswiki::Object); +has headers => ( is => 'ro', ); has filename => ( is => 'ro', ); has size => ( is => 'ro', ); has contentType => ( is => 'ro', ); diff --git a/core/lib/Foswiki/UI/Upload.pm b/core/lib/Foswiki/UI/Upload.pm index 284f869384..35d0b4a6b8 100644 --- a/core/lib/Foswiki/UI/Upload.pm +++ b/core/lib/Foswiki/UI/Upload.pm @@ -114,7 +114,7 @@ sub _upload { my $this = shift; my @msgs; - foreach my $upload ( @{ $this->app->request->uploads } ) { + foreach my $upload ( values %{ $this->app->request->uploads } ) { push @msgs, $this->_upload_file($upload); }