diff --git a/docs/migration.txt b/docs/migration.txt index 20a0b9492..7062cc8ac 100644 --- a/docs/migration.txt +++ b/docs/migration.txt @@ -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'); diff --git a/lib/WebGUI/Asset/Wobject/Calendar.pm b/lib/WebGUI/Asset/Wobject/Calendar.pm index 202e62b9b..5ad58ee9b 100644 --- a/lib/WebGUI/Asset/Wobject/Calendar.pm +++ b/lib/WebGUI/Asset/Wobject/Calendar.pm @@ -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; } diff --git a/lib/WebGUI/Asset/Wobject/DataForm.pm b/lib/WebGUI/Asset/Wobject/DataForm.pm index 1e2f533da..30aae452d 100644 --- a/lib/WebGUI/Asset/Wobject/DataForm.pm +++ b/lib/WebGUI/Asset/Wobject/DataForm.pm @@ -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); diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index 1dabd5d32..b69e75c82 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -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 = (); diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index ac320b4e9..084f60d20 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -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; } diff --git a/lib/WebGUI/Asset/Wobject/SQLReport.pm b/lib/WebGUI/Asset/Wobject/SQLReport.pm index c04b19e4e..b93a64e89 100644 --- a/lib/WebGUI/Asset/Wobject/SQLReport.pm +++ b/lib/WebGUI/Asset/Wobject/SQLReport.pm @@ -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; diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index e7578b429..8fc3cf159 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -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; } diff --git a/lib/WebGUI/Session/Http.pm b/lib/WebGUI/Session/Http.pm index 7310518b1..296547a82 100644 --- a/lib/WebGUI/Session/Http.pm +++ b/lib/WebGUI/Session/Http.pm @@ -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 ) diff --git a/t/Session/Http.t b/t/Session/Http.t index 1dbbbffe3..f65d60e6e 100644 --- a/t/Session/Http.t +++ b/t/Session/Http.t @@ -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');