Remove setFilename, getFilename from Session::Http, and use Plack::Response methods instead.
This commit is contained in:
parent
fd8f03a186
commit
8b6bbdb9f7
9 changed files with 28 additions and 77 deletions
|
|
@ -304,3 +304,11 @@ NEW: $session->response->content_type();
|
|||
|
||||
OLD: $session->http->setMimeType('application/json');
|
||||
NEW: $session->response->content_type('application/json');
|
||||
|
||||
getFilename and setFilename have been removed. To set the filename that should be
|
||||
uploaded to the user, access the WebGUI::Response object in the session. First, set
|
||||
the header for the Content-Dispostion, then set the content type.
|
||||
|
||||
OLD: $session->http->setFilename($filename);
|
||||
NEW: $session->response->header( 'Content-Disposition' => qq{attachment; filename="}.$filename.'"');
|
||||
$session->response->content_type('application/octet-stream');
|
||||
|
|
|
|||
|
|
@ -1816,8 +1816,8 @@ sub www_ical {
|
|||
|
||||
|
||||
# Set mime of text/icalendar
|
||||
#$self->session->response->content_type("text/plain");
|
||||
$self->session->http->setFilename("feed.ics","text/calendar");
|
||||
$self->session->response->header( 'Content-Disposition' => qq{attachment; filename="feed.ics"});
|
||||
$self->session->response->content_type("text/calendar");
|
||||
return $ical;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1883,7 +1883,8 @@ sub www_exportTab {
|
|||
@exportFields,
|
||||
);
|
||||
|
||||
$session->http->setFilename($self->url.".tab","text/plain");
|
||||
$session->response->header( 'Content-Disposition' => qq{attachment; filename="}.$self->url.'.tab"');
|
||||
$session->response->content_type('text/plain');
|
||||
$session->http->sendHeader;
|
||||
$session->output->print($tsv->string, 1);
|
||||
|
||||
|
|
|
|||
|
|
@ -1258,7 +1258,8 @@ sub www_exportEvents {
|
|||
my $out = $session->output;
|
||||
|
||||
# set http header
|
||||
$self->session->http->setFilename($self->getTitle.".csv", 'application/excel');
|
||||
$session->response->header( 'Content-Disposition' => qq{attachment; filename="}.$self->getTitle().'.csv"' );
|
||||
$session->response->content_type('application/excel');
|
||||
|
||||
# add file header
|
||||
my @header = ();
|
||||
|
|
|
|||
|
|
@ -1078,8 +1078,8 @@ sub www_exportAttributes {
|
|||
$output .= "\n".WebGUI::Text::joinCSV($attribute->{name},$attribute->{description},$attribute->{category});
|
||||
}
|
||||
|
||||
my $fileName = "export_matrix_attributes.csv";
|
||||
$self->session->http->setFilename($fileName,"application/octet-stream");
|
||||
$session->response->header( 'Content-Disposition' => qq{attachment; filename="export_matrix_attributes.csv"});
|
||||
$session->response->content_type('application/octet-stream');
|
||||
$self->session->http->sendHeader;
|
||||
return $output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -699,12 +699,10 @@ sub www_download {
|
|||
unless $self->session->user->isInGroup($self->downloadUserGroup);
|
||||
|
||||
# Set filename and mimetype
|
||||
if ($self->downloadType eq "csv") {
|
||||
$self->session->http->setFilename($self->downloadFilename,"application/octet-stream");
|
||||
}
|
||||
else {
|
||||
$self->session->http->setFilename($self->downloadFilename, $self->downloadMimeType);
|
||||
}
|
||||
$self->session->response->header( 'Content-Disposition' => qq{attachment; filename="}.$self->downloadFilename().'"');
|
||||
$self->session->response->content_type(
|
||||
$self->downloadType eq 'csv' ? "application/octet-stream" : $self->downloadMimeType
|
||||
);
|
||||
|
||||
$self->session->http->sendHeader;
|
||||
|
||||
|
|
|
|||
|
|
@ -2411,7 +2411,8 @@ sub export {
|
|||
$self->clearTempReportTable;
|
||||
|
||||
my $filename = $self->session->url->escape( $self->title . "_$opts{name}.$format" );
|
||||
$self->session->http->setFilename($filename,"text/$format");
|
||||
$self->session->response->header( 'Content-Disposition' => qq{attachment; filename="}.$filename.'"');
|
||||
$self->session->response->content_type("text/$format");
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
|
@ -2542,7 +2543,8 @@ END_HTML
|
|||
my $output = join "\n", @lines;
|
||||
|
||||
my $filename = $self->session->url->escape( $self->title . "_structure.csv" );
|
||||
$self->session->http->setFilename($filename,"text/csv");
|
||||
$self->session->response->header( 'Content-Disposition' => qq{attachment; filename="}.$filename.'"');
|
||||
$self->session->response->content_type("text/csv");
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
|
@ -2667,7 +2669,8 @@ sub www_downloadDefaultQuestionTypes{
|
|||
if !$self->session->user->isInGroup( $self->groupToViewReports );
|
||||
|
||||
my $content = to_json($self->getSurveyJSON->{multipleChoiceTypes});
|
||||
$self->session->http->setFilename('WebGUI-Survey-DefaultQuestionTypes.json', "application/json");
|
||||
$self->session->response->header( 'Content-Disposition' => qq{attachment; filename="WebGUI-Survey-DefaultQuestionTypes.json"});
|
||||
$self->session->response->content_type("application/json");
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ This package allows the manipulation of HTTP protocol information.
|
|||
$boolean = $http->isRedirect();
|
||||
|
||||
$http->setCookie($name,$value);
|
||||
$http->setFilename($filename,$mimetype);
|
||||
$http->setNoHeader($bool);
|
||||
$http->setRedirect($url);
|
||||
|
||||
|
|
@ -260,9 +259,6 @@ sub sendHeader {
|
|||
$response->header( 'Expires' => $date );
|
||||
}
|
||||
}
|
||||
if ($self->getFilename) {
|
||||
$response->header( 'Content-Disposition' => qq{attachment; filename="}.$self->getFilename().'"');
|
||||
}
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
|
@ -353,46 +349,6 @@ sub setCookie {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 setFilename ( filename [, mimetype] )
|
||||
|
||||
Override the default filename for the document, which is usually the page url.
|
||||
|
||||
=head3 filename
|
||||
|
||||
The filename to set.
|
||||
|
||||
=head3 mimetype
|
||||
|
||||
The mimetype for this file. Defaults to "application/octet-stream".
|
||||
|
||||
=cut
|
||||
|
||||
sub setFilename {
|
||||
my $self = shift;
|
||||
$self->{_http}{filename} = shift;
|
||||
my $mimetype = shift || "application/octet-stream";
|
||||
$self->session->response->content_type($mimetype);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getFilename ( )
|
||||
|
||||
Returns the default filename for the document.
|
||||
|
||||
=cut
|
||||
|
||||
sub getFilename {
|
||||
my $self = shift;
|
||||
return $self->{_http}{filename};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 setLastModified ( epoch )
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ use Data::Dumper;
|
|||
use Test::More; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
|
||||
plan tests => 44;
|
||||
plan tests => 40;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
|
@ -70,22 +70,6 @@ $http->setStreamedFile('/home/streaming');
|
|||
is($http->getStreamedFile, '/home/streaming', 'set/get StreamedFile: set specific location and get it');
|
||||
$http->setStreamedFile('');
|
||||
|
||||
####################################################
|
||||
#
|
||||
# setFilename, getFilename
|
||||
#
|
||||
####################################################
|
||||
|
||||
$http->setFilename('foo.bin');
|
||||
is($http->getFilename, 'foo.bin', 'set/get Filename: filename passed');
|
||||
is($response->content_type(), 'application/octet-stream', 'set/get Filename: default mime type is octet/stream');
|
||||
|
||||
$http->setFilename('foo.txt','text/plain');
|
||||
is($http->getFilename, 'foo.txt', 'set/get Filename: filename set');
|
||||
is($response->content_type(), 'text/plain', 'set/get Filename: mime type set');
|
||||
$http->setFilename('');
|
||||
$response->content_type('');
|
||||
|
||||
####################################################
|
||||
#
|
||||
# setLastModified, getLastModified
|
||||
|
|
@ -241,7 +225,7 @@ is($http->sendHeader, undef, 'sendHeader returns undef when no request object is
|
|||
my $guard = WebGUI::Test->cleanupGuard($session);
|
||||
my $http = $session->http;
|
||||
my $response = $session->response;
|
||||
$http->setFilename('image.png');
|
||||
$response->header( 'Content-Disposition' => qq{attachment; filename="image.png"});
|
||||
$response->content_type('image/png');
|
||||
$http->sendHeader();
|
||||
is($response->headers->content_type, 'image/png', 'sendHeader: mimetype');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue