Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Item13897: Roll back commit 4ac91aa – back to uploads as a hashref.
Plus some code cleanup: got rid of '-upload' parameter processing and
'upload_list' attribute. This is very likely to break CGI engine
compatibility once and for all but Plack::Handler::CGI must be a good
enough drop-in replacement.

- Added Foswiki::Exception::Harmless – for non-fatal, informal exceptions.

- Added support for uploads raw headers. Though they better be avoided in
favor of high-level Foswiki::Request::Upload attributes.
  • Loading branch information
vrurg committed Jul 25, 2016
1 parent 6f87695 commit 6603b85
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 70 deletions.
5 changes: 2 additions & 3 deletions core/lib/Foswiki/Engine.pm
Expand Up @@ -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

Expand Down Expand Up @@ -423,7 +422,7 @@ sub _preparePath { }
sub _prepareBodyParameters { return []; }

# Abstract initializer for uploads
sub _prepareUploads { return {}; }
sub _prepareUploads { return []; }

=begin TML
Expand Down
6 changes: 1 addition & 5 deletions core/lib/Foswiki/Engine/PSGI.pm
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
};
Expand Down
102 changes: 61 additions & 41 deletions core/lib/Foswiki/Exception.pm
Expand Up @@ -384,21 +384,79 @@ 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;
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.
Expand Down Expand Up @@ -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/
Expand Down
31 changes: 11 additions & 20 deletions core/lib/Foswiki/Request.pm
Expand Up @@ -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=
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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 } @_;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions core/lib/Foswiki/Request/Upload.pm
Expand Up @@ -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', );
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/UI/Upload.pm
Expand Up @@ -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);
}

Expand Down

0 comments on commit 6603b85

Please sign in to comment.