From fd8f03a1868fc144512b8bbcc4bae49d88ee4a5f Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 21 Nov 2010 22:35:26 -0800 Subject: [PATCH] Change getMimeType and setMimeType to response->content_type. --- docs/migration.txt | 9 +++++ lib/WebGUI/Account/FriendManager.pm | 2 +- lib/WebGUI/Admin.pm | 4 +- lib/WebGUI/Asset/EMSSubmission.pm | 4 +- lib/WebGUI/Asset/EMSSubmissionForm.pm | 8 ++-- lib/WebGUI/Asset/File/GalleryFile/Photo.pm | 2 +- lib/WebGUI/Asset/MatrixListing.pm | 6 +-- lib/WebGUI/Asset/Snippet.pm | 2 +- lib/WebGUI/Asset/Template.pm | 2 +- lib/WebGUI/Asset/Wobject/Calendar.pm | 2 +- lib/WebGUI/Asset/Wobject/DataTable.pm | 4 +- .../Asset/Wobject/EventManagementSystem.pm | 24 +++++------ lib/WebGUI/Asset/Wobject/Gallery.pm | 12 +++--- lib/WebGUI/Asset/Wobject/GalleryAlbum.pm | 6 +-- lib/WebGUI/Asset/Wobject/HttpProxy.pm | 4 +- lib/WebGUI/Asset/Wobject/Map.pm | 8 ++-- lib/WebGUI/Asset/Wobject/Matrix.pm | 4 +- lib/WebGUI/Asset/Wobject/Navigation.pm | 2 +- lib/WebGUI/Asset/Wobject/Survey.pm | 8 ++-- lib/WebGUI/Asset/Wobject/Thingy.pm | 14 +++---- lib/WebGUI/Content/AjaxI18N.pm | 2 +- lib/WebGUI/Content/AssetDiscovery.pm | 4 +- lib/WebGUI/Content/AssetHistory.pm | 2 +- lib/WebGUI/Content/AssetManager.pm | 2 +- lib/WebGUI/Content/SiteIndex.pm | 2 +- lib/WebGUI/Fork/Status.pm | 2 +- lib/WebGUI/Form/Keywords.pm | 2 +- lib/WebGUI/Form/ThingFieldsList.pm | 2 +- lib/WebGUI/Form/Username.pm | 2 +- lib/WebGUI/Operation/Auth.pm | 2 +- lib/WebGUI/Operation/Cron.pm | 2 +- lib/WebGUI/Operation/Spectre.pm | 4 +- lib/WebGUI/Operation/SpellCheck.pm | 2 +- lib/WebGUI/Operation/User.pm | 6 +-- lib/WebGUI/Operation/Workflow.pm | 2 +- lib/WebGUI/Role/Asset/RssFeed.pm | 6 +-- lib/WebGUI/Session.pm | 2 + lib/WebGUI/Session/Http.pm | 39 +----------------- lib/WebGUI/Session/Output.pm | 2 +- lib/WebGUI/Shop/AddressBook.pm | 4 +- lib/WebGUI/Shop/Cart.pm | 4 +- lib/WebGUI/Shop/PayDriver/ITransact.pm | 2 +- lib/WebGUI/Shop/TaxDriver/EU.pm | 4 +- lib/WebGUI/Shop/TaxDriver/Generic.pm | 2 +- lib/WebGUI/Shop/Transaction.pm | 2 +- lib/WebGUI/Shop/Vendor.pm | 6 +-- lib/WebGUI/Wizard/Setup.pm | 2 +- t/Operation/User/service.t | 40 +++++++++---------- t/Session/Http.t | 25 +++--------- t/Session/Output.t | 4 +- t/Shop/TaxDriver/Generic.t | 2 +- t/Shop/Transaction.t | 2 +- 52 files changed, 138 insertions(+), 175 deletions(-) diff --git a/docs/migration.txt b/docs/migration.txt index eaeec8b31..20a0b9492 100644 --- a/docs/migration.txt +++ b/docs/migration.txt @@ -295,3 +295,12 @@ NEW: $session->response->status(); OLD: $session->http->setStatus(200); NEW: $session->response->status(200); + +getMimeType and setMimeType have been removed. To set or get the content type of an HTTP response +generated by WebGUI, access the WebGUI::Response object in the session: + +OLD: $session->http->getMimeType(); +NEW: $session->response->content_type(); + +OLD: $session->http->setMimeType('application/json'); +NEW: $session->response->content_type('application/json'); diff --git a/lib/WebGUI/Account/FriendManager.pm b/lib/WebGUI/Account/FriendManager.pm index 8abc64fd1..426b7940f 100644 --- a/lib/WebGUI/Account/FriendManager.pm +++ b/lib/WebGUI/Account/FriendManager.pm @@ -380,7 +380,7 @@ sub www_getFriendsAsJson { $results{records} = \@records; $results{'sort'} = 'username'; $self->bare(1); - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); my $json = JSON::to_json(\%results); return $json; } diff --git a/lib/WebGUI/Admin.pm b/lib/WebGUI/Admin.pm index ef751c75e..bd06dcee0 100644 --- a/lib/WebGUI/Admin.pm +++ b/lib/WebGUI/Admin.pm @@ -599,7 +599,7 @@ sub www_getTreeData { }; } - $session->http->setMimeType( 'application/json' ); + $session->response->content_type( 'application/json' ); return to_json( $assetInfo ); } @@ -732,7 +732,7 @@ sub www_searchAssets { $assetInfo->{ sort } = $session->form->get( 'orderByColumn' ); $assetInfo->{ dir } = lc $session->form->get( 'orderByDirection' ); - $session->http->setMimeType( 'application/json' ); + $session->response->content_type( 'application/json' ); return to_json( $assetInfo ); } diff --git a/lib/WebGUI/Asset/EMSSubmission.pm b/lib/WebGUI/Asset/EMSSubmission.pm index 32a91d516..62a707871 100644 --- a/lib/WebGUI/Asset/EMSSubmission.pm +++ b/lib/WebGUI/Asset/EMSSubmission.pm @@ -434,10 +434,10 @@ sub www_editSubmission { if( $params->{asHashRef} ) { return { text => $content, title => $title, }; } elsif( $session->form->get('asJson') ) { - $session->http->setMimeType( 'application/json' ); + $session->response->content_type( 'application/json' ); return JSON->new->encode( { text => $content, title => $title, id => $assetId ne 'new' ? $assetId : 'new' . rand } ); } else { - $session->http->setMimeType( 'text/html' ); + $session->response->content_type( 'text/html' ); return $asset->processStyle( $content ); } } diff --git a/lib/WebGUI/Asset/EMSSubmissionForm.pm b/lib/WebGUI/Asset/EMSSubmissionForm.pm index 3e17a84a7..119009efc 100644 --- a/lib/WebGUI/Asset/EMSSubmissionForm.pm +++ b/lib/WebGUI/Asset/EMSSubmissionForm.pm @@ -217,11 +217,11 @@ sub www_editSubmissionForm { return { text => $content, title => $title, }; } elsif ( $session->form->get('asJson') ) { - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->encode( { text => $content, title => $title, id => 'list' . rand } ); } else { - $session->http->setMimeType('text/html'); + $session->response->content_type('text/html'); return $parent->ems->processStyle($content); } } ## end else [ if ( scalar(@$res) == ...)] @@ -292,10 +292,10 @@ sub www_editSubmissionForm { ; # not setting mimie type } elsif ( $session->form->get('asJson') ) { - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); } else { - $session->http->setMimeType('text/html'); + $session->response->content_type('text/html'); } my $content = $asset->processTemplate( { errors => $params->{errors} || [], diff --git a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm index f2e4e8156..987d923b0 100644 --- a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm +++ b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm @@ -547,7 +547,7 @@ sub www_download { my $storage = $self->getStorageLocation; - $self->session->http->setMimeType( "image/jpeg" ); + $self->session->response->content_type( "image/jpeg" ); $self->session->http->setLastModified( $self->getContentLastModified ); my $resolution = $self->session->form->get("resolution"); diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm index 5019a085f..9fe140fac 100644 --- a/lib/WebGUI/Asset/MatrixListing.pm +++ b/lib/WebGUI/Asset/MatrixListing.pm @@ -857,7 +857,7 @@ sub www_getAttributes { return $session->privilege->noAccess() unless $self->canView; - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); my @results; my @categories = keys %{$self->getParent->getCategories}; @@ -904,7 +904,7 @@ sub www_getScreenshots { return $self->session->privilege->noAccess() unless $self->canView; - $self->session->http->setMimeType('text/xml'); + $self->session->response->content_type('text/xml'); my $xml = qq | @@ -958,7 +958,7 @@ sub www_getScreenshotsConfig { return $self->session->privilege->noAccess() unless $self->canView; - $self->session->http->setMimeType('text/xml'); + $self->session->response->content_type('text/xml'); return $self->processTemplate($var,$self->getParent->get("screenshotsConfigTemplateId")); } diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm index 9d5955dbc..fb4f74b01 100644 --- a/lib/WebGUI/Asset/Snippet.pm +++ b/lib/WebGUI/Asset/Snippet.pm @@ -288,7 +288,7 @@ sub www_view { my $self = shift; return $self->session->privilege->insufficient() unless $self->canView; my $mimeType=$self->mimeType; - $self->session->http->setMimeType($mimeType || 'text/html'); + $self->session->response->content_type($mimeType || 'text/html'); $self->session->http->setCacheControl($self->cacheTimeout); my $output = $self->view(1); if (!defined $output) { diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index 1f55e6c68..53579f4bb 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -575,7 +575,7 @@ sub process { # Return a JSONinfied version of vars if JSON is the only requested content type. if ( defined $session->request && $session->request->header('Accept') eq 'application/json' ) { - $session->http->setMimeType( 'application/json' ); + $session->response->content_type( 'application/json' ); return to_json( $vars ); } diff --git a/lib/WebGUI/Asset/Wobject/Calendar.pm b/lib/WebGUI/Asset/Wobject/Calendar.pm index f28601496..202e62b9b 100644 --- a/lib/WebGUI/Asset/Wobject/Calendar.pm +++ b/lib/WebGUI/Asset/Wobject/Calendar.pm @@ -1816,7 +1816,7 @@ sub www_ical { # Set mime of text/icalendar - #$self->session->http->setMimeType("text/plain"); + #$self->session->response->content_type("text/plain"); $self->session->http->setFilename("feed.ics","text/calendar"); return $ical; } diff --git a/lib/WebGUI/Asset/Wobject/DataTable.pm b/lib/WebGUI/Asset/Wobject/DataTable.pm index 1e1adb9db..17d841efc 100644 --- a/lib/WebGUI/Asset/Wobject/DataTable.pm +++ b/lib/WebGUI/Asset/Wobject/DataTable.pm @@ -231,7 +231,7 @@ Get the data asynchronously. sub www_ajaxGetData { my $self = shift; - $self->session->http->setMimeType("application/json"); + $self->session->response->content_type("application/json"); return $self->getDataJson; } @@ -253,7 +253,7 @@ sub www_ajaxUpdateData { $data ||= $self->data; - $self->session->http->setMimeType("application/json"); + $self->session->response->content_type("application/json"); return $data; } diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index 114df0961..1dabd5d32 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -823,9 +823,9 @@ sub www_addSubmission { my $title = $i18n->get('select form to submit') ; my $asJson = $session->form->get('asJson'); if( $asJson ) { - $session->http->setMimeType( 'application/json' ); + $session->response->content_type( 'application/json' ); } else { - $session->http->setMimeType( 'text/html' ); + $session->response->content_type( 'text/html' ); } my $content = '

' . $title . '

' ; if( $asJson ) { @@ -1377,7 +1377,7 @@ sub www_getAllSubmissions { push @{ $tableInfo->{ records } }, \%fields; } - $session->http->setMimeType( 'application/json' ); + $session->response->content_type( 'application/json' ); return JSON->new->encode( $tableInfo ); } @@ -1414,7 +1414,7 @@ sub www_getBadgesAsJson { $results{'startIndex'} = 0; $results{'sort'} = undef; $results{'dir'} = "asc"; - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->encode(\%results); } @@ -1444,7 +1444,7 @@ sub www_getSubmissionById { $result->{title} = $submissionId; $result->{id} = $submissionId; } - $self->session->http->setMimeType('application/json'); + $self->session->response->content_type('application/json'); return JSON->new->encode($result); } @@ -1461,7 +1461,7 @@ sub www_getRegistrantAsJson { my $session = $self->session; my $db = $session->db; return $session->privilege->insufficient() unless $self->canView; - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); my @tickets = (); my @tokens = (); my @ribbons = (); @@ -1640,7 +1640,7 @@ sub www_getRegistrantsAsJson { $results{'dir'} = "asc"; # build json datasource - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->encode(\%results); } @@ -1675,7 +1675,7 @@ sub www_getRibbonsAsJson { $results{'startIndex'} = 0; $results{'sort'} = undef; $results{'dir'} = "asc"; - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->encode(\%results); } @@ -1788,7 +1788,7 @@ sub www_getScheduleDataJSON { $results{totalDatePages} = scalar(@dateRecords); $results{currentDatePage} = $datePageNumber; $results{dateRecords} = \@dateRecords; - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->encode(\%results); } @@ -1944,7 +1944,7 @@ className='WebGUI::Asset::Sku::EMSTicket' and state='published' and revisionDate $results{'startIndex'} = $startIndex; $results{'sort'} = undef; $results{'dir'} = "asc"; - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->encode(\%results); } @@ -1981,7 +1981,7 @@ sub www_getTokensAsJson { $results{'startIndex'} = 0; $results{'sort'} = undef; $results{'dir'} = "asc"; - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->encode(\%results); } @@ -2065,7 +2065,7 @@ sub www_importEventsSave { $|=1; # set up - $session->http->setMimeType("text/plain"); + $session->response->content_type("text/plain"); my $start = [Time::HiRes::gettimeofday]; my $i18n = WebGUI::International->new($session,'Asset_EventManagementSystem'); my $csv = Text::CSV_XS->new({ binary => 1 }); diff --git a/lib/WebGUI/Asset/Wobject/Gallery.pm b/lib/WebGUI/Asset/Wobject/Gallery.pm index 0bc1adf3b..78cbca965 100644 --- a/lib/WebGUI/Asset/Wobject/Gallery.pm +++ b/lib/WebGUI/Asset/Wobject/Gallery.pm @@ -1145,11 +1145,11 @@ sub www_addAlbumService { lastUpdated => $date->epochToHuman($album->revisionDate, '%y-%m-%d %j:%n:%s'), }; if ($as eq "xml") { - $session->http->setMimeType('text/xml'); + $session->response->content_type('text/xml'); return XML::Simple::XMLout($document, NoAttr => 1); } - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->pretty->encode($document); } @@ -1206,7 +1206,7 @@ sub www_listAlbumsRss { push @{ $var->{albums} }, $assetVar; } - $self->session->http->setMimeType('text/xml'); + $self->session->response->content_type('text/xml'); return $self->processTemplate( $var, $self->templateIdListAlbumsRss ); } @@ -1344,10 +1344,10 @@ sub www_listAlbumsService { albums => \@assets }; if ($as eq "xml") { - $session->http->setMimeType('text/xml'); + $session->response->content_type('text/xml'); return XML::Simple::XMLout($document, NoAttr => 1); } - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->pretty->encode($document); } @@ -1612,7 +1612,7 @@ sub www_listFilesForUserRss { push @{ $var->{user_files} }, $assetVar; } - $self->session->http->setMimeType('text/xml'); + $self->session->response->content_type('text/xml'); return $self->processTemplate( $var, $self->templateIdListFilesForUserRss ); } diff --git a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm index 5d94894e5..58c4f4f56 100644 --- a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm +++ b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm @@ -1159,11 +1159,11 @@ sub www_addFileService { lastUpdated => $date->epochToHuman($file->revisionDate, '%y-%m-%d %j:%n:%s'), }; if ($as eq "xml") { - $session->http->setMimeType('text/xml'); + $session->response->content_type('text/xml'); return XML::Simple::XMLout($document, NoAttr => 1); } - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->pretty->encode($document); } @@ -1739,7 +1739,7 @@ sub www_viewRss { = $self->session->datetime->epochToMail( $file->{creationDate} ); } - $self->session->http->setMimeType('text/xml'); + $self->session->response->content_type('text/xml'); return $self->processTemplate( $var, $self->getParent->templateIdViewAlbumRss ); } diff --git a/lib/WebGUI/Asset/Wobject/HttpProxy.pm b/lib/WebGUI/Asset/Wobject/HttpProxy.pm index b6b421fdb..0c234f200 100644 --- a/lib/WebGUI/Asset/Wobject/HttpProxy.pm +++ b/lib/WebGUI/Asset/Wobject/HttpProxy.pm @@ -466,7 +466,7 @@ sub view { } - $self->session->http->setMimeType($var{header}); + $self->session->response->content_type($var{header}); if($var{header} ne "text/html") { return $var{content}; @@ -494,7 +494,7 @@ sub www_view { return $self->session->privilege->noAccess() unless $self->canView; $self->prepareView; my $output = $self->view; - if ($self->session->http->getMimeType ne "text/html") { + if ($self->session->response->content_type ne "text/html") { return $output; } else { $self->session->http->sendHeader; diff --git a/lib/WebGUI/Asset/Wobject/Map.pm b/lib/WebGUI/Asset/Wobject/Map.pm index dee0898af..0d567bab7 100644 --- a/lib/WebGUI/Asset/Wobject/Map.pm +++ b/lib/WebGUI/Asset/Wobject/Map.pm @@ -482,7 +482,7 @@ sub www_ajaxDeletePoint { my $i18n = WebGUI::International->new( $session, 'Asset_Map' ); my $assetId = $session->form->get('assetId'); my $asset = WebGUI::Asset->newById( $session, $assetId ); - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->encode({error => $i18n->get('error delete unauthorized')}) unless $asset && $asset->canEdit; @@ -535,7 +535,7 @@ sub www_ajaxEditPointSave { # We're returning as HTML because application/json causes download pop-up # and text/plain causes
...
in firefox - $session->http->setMimeType("text/html"); + $session->response->content_type("text/html"); $session->log->preventDebugOutput; my $assetId = $form->get('assetId'); @@ -591,7 +591,7 @@ sub www_ajaxSetCenter { my $form = $self->session->form; my $i18n = WebGUI::International->new( $session, 'Asset_Map' ); - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); return JSON->new->encode({message => $i18n->get("error set center unauthorized")}) unless $self->canEdit; @@ -619,7 +619,7 @@ sub www_ajaxSetPointLocation { my $form = $self->session->form; my $i18n = WebGUI::International->new( $session, 'Asset_Map' ); - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); my $assetId = $form->get('assetId'); my $asset = WebGUI::Asset->newById( $session, $assetId ); diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index 5c1687c3f..ac320b4e9 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -1109,7 +1109,7 @@ sub www_getCompareFormData { my @listingIds = $session->form->checkList("listingId"); - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); my $db = $session->db; my (@searchParams,@searchParams_sorted,@searchParamList,$searchParamList); @@ -1301,7 +1301,7 @@ sub www_getCompareListData { } $jsonOutput->{ResultSet} = {Result=>\@results}; - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); return JSON->new->encode($jsonOutput); } diff --git a/lib/WebGUI/Asset/Wobject/Navigation.pm b/lib/WebGUI/Asset/Wobject/Navigation.pm index e3fdf6d24..adb950d5a 100644 --- a/lib/WebGUI/Asset/Wobject/Navigation.pm +++ b/lib/WebGUI/Asset/Wobject/Navigation.pm @@ -577,7 +577,7 @@ override www_view => sub { } else { $self->prepareView(); - $self->session->http->setMimeType($mimeType); + $self->session->response->content_type($mimeType); return $self->view(); } }; diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index 53fa3589f..e7578b429 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -1295,7 +1295,7 @@ sub www_loadSurvey { warnings => $warnings #List of warnings to display to the user }; - $self->session->http->setMimeType('application/json'); + $self->session->response->content_type('application/json'); return to_json($return); } @@ -1762,7 +1762,7 @@ sub www_loadQuestions { if(! $self->session->form->param('shownsummary')){ my ($summary,$html) = $self->getSummary(); my $json = to_json( { type => 'summary', summary => $summary, html => $html }); - $self->session->http->setMimeType('application/json'); + $self->session->response->content_type('application/json'); return $json; } } @@ -1869,7 +1869,7 @@ sub surveyEnd { $exitUrl = $exitUrl || $self->exitURL || $self->getUrl || q{/}; $exitUrl = $self->session->url->gateway($exitUrl) if($exitUrl !~ /^https?:/i); my $json = to_json( { type => 'forward', url => $exitUrl } ); - $self->session->http->setMimeType('application/json'); + $self->session->response->content_type('application/json'); return $json; } @@ -1963,7 +1963,7 @@ sub prepareShowSurveyTemplate { my $out = $self->processTemplate( $section, $self->surveyQuestionsId ); WebGUI::Macro::process($self->session, \$out); - $self->session->http->setMimeType('application/json'); + $self->session->response->content_type('application/json'); return to_json( { type => 'displayquestions', section => $section, questions => $questions, html => $out } ); } diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index 05ffbb927..3b5412237 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -1621,7 +1621,7 @@ sub www_deleteThingDataViaAjax { my $thingId = $self->session->form->process("thingId"); my $thingDataId = $self->session->form->process('thingDataId'); - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); unless ($thingId && $thingDataId) { $session->response->status(400); @@ -1635,7 +1635,7 @@ sub www_deleteThingDataViaAjax { $self->deleteThingData($thingId,$thingDataId); - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); return JSON->new->encode({message => "Data with thingDataId $thingDataId was deleted."}); } else { @@ -2704,7 +2704,7 @@ sub www_getThingViaAjax { my $self = shift; my $session = $self->session; my $thingId = shift || $session->form->process('thingId'); - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); unless ($thingId) { $session->response->status(400); @@ -2725,7 +2725,7 @@ sub www_getThingViaAjax { } $thingProperties->{field_loop} = \@field_loop; - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); return JSON->new->encode($thingProperties); } else { @@ -2747,7 +2747,7 @@ sub www_getThingsViaAjax { my $self = shift; my $session = $self->session; - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); my @visibleThings; my $things = $self->getThings; @@ -3134,7 +3134,7 @@ sub www_searchViaAjax { my $var = $self->getSearchTemplateVars($thingId,$thingProperties); - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); return JSON->new->encode($var); } else { @@ -3554,7 +3554,7 @@ sub www_viewThingDataViaAjax { my $thingId = shift || $session->form->process('thingId'); my $thingDataId = shift || $session->form->process('thingDataId'); - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); unless ($thingId && $thingDataId) { $session->response->status(400); diff --git a/lib/WebGUI/Content/AjaxI18N.pm b/lib/WebGUI/Content/AjaxI18N.pm index 4d6018526..cf51e8884 100644 --- a/lib/WebGUI/Content/AjaxI18N.pm +++ b/lib/WebGUI/Content/AjaxI18N.pm @@ -64,7 +64,7 @@ sub handler { else { $session->log->warn("User ".$session->user->username." tried to execute ajaxGetI18n but could not decode JSON string: $json"); } - $session->http->setMimeType( "application/json" ); + $session->response->content_type( "application/json" ); return JSON->new->encode( $response ); } diff --git a/lib/WebGUI/Content/AssetDiscovery.pm b/lib/WebGUI/Content/AssetDiscovery.pm index 03e648442..cd3bbfc31 100644 --- a/lib/WebGUI/Content/AssetDiscovery.pm +++ b/lib/WebGUI/Content/AssetDiscovery.pm @@ -134,10 +134,10 @@ sub handler { assets => \@assets }; if ($as eq "xml") { - $session->http->setMimeType('text/xml'); + $session->response->content_type('text/xml'); return XML::Simple::XMLout($document, NoAttr => 1); } - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->encode($document); } return undef; diff --git a/lib/WebGUI/Content/AssetHistory.pm b/lib/WebGUI/Content/AssetHistory.pm index b8ad96d52..4652441a3 100644 --- a/lib/WebGUI/Content/AssetHistory.pm +++ b/lib/WebGUI/Content/AssetHistory.pm @@ -107,7 +107,7 @@ EOSQL $results{'startIndex'} = $startIndex; $results{'sort'} = undef; $results{'dir'} = $sortDir; - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); my $json = JSON::to_json(\%results); return $json; } diff --git a/lib/WebGUI/Content/AssetManager.pm b/lib/WebGUI/Content/AssetManager.pm index e47091742..df501d93a 100644 --- a/lib/WebGUI/Content/AssetManager.pm +++ b/lib/WebGUI/Content/AssetManager.pm @@ -315,7 +315,7 @@ sub www_ajaxGetManagerPage { $assetInfo->{ sort } = $session->form->get( 'orderByColumn' ); $assetInfo->{ dir } = lc $session->form->get( 'orderByDirection' ); - $session->http->setMimeType( 'application/json' ); + $session->response->content_type( 'application/json' ); return to_json( $assetInfo ); } diff --git a/lib/WebGUI/Content/SiteIndex.pm b/lib/WebGUI/Content/SiteIndex.pm index 7d1d23d4b..a31265ada 100644 --- a/lib/WebGUI/Content/SiteIndex.pm +++ b/lib/WebGUI/Content/SiteIndex.pm @@ -93,7 +93,7 @@ sub handler { .''; - $session->http->setMimeType('text/xml'); + $session->response->content_type('text/xml'); return $xml; } diff --git a/lib/WebGUI/Fork/Status.pm b/lib/WebGUI/Fork/Status.pm index 06c2ebd3b..dd444bce6 100644 --- a/lib/WebGUI/Fork/Status.pm +++ b/lib/WebGUI/Fork/Status.pm @@ -77,7 +77,7 @@ sub handler { finished => ( $finished ? \1 : \0 ), ); $status{error} = $error if $finished; - $process->session->http->setMimeType('text/plain'); + $process->session->response->content_type('text/plain'); JSON::encode_json( \%status ); } ## end sub handler diff --git a/lib/WebGUI/Form/Keywords.pm b/lib/WebGUI/Form/Keywords.pm index 0f818f7dc..b3ecf5ec4 100644 --- a/lib/WebGUI/Form/Keywords.pm +++ b/lib/WebGUI/Form/Keywords.pm @@ -149,7 +149,7 @@ sub www_searchAsJSON { my $keyword = WebGUI::Keyword->new($session); my $keywords = $keyword->findKeywords({search => $search, limit => 20}); - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON::to_json({keywords => $keywords}); } diff --git a/lib/WebGUI/Form/ThingFieldsList.pm b/lib/WebGUI/Form/ThingFieldsList.pm index 72591335b..cc63aa704 100644 --- a/lib/WebGUI/Form/ThingFieldsList.pm +++ b/lib/WebGUI/Form/ThingFieldsList.pm @@ -82,7 +82,7 @@ sub www_getThingFields { [$thingId] ); - $session->http->setMimeType( 'application/json' ); + $session->response->content_type( 'application/json' ); return JSON->new->encode( \%fields ); } diff --git a/lib/WebGUI/Form/Username.pm b/lib/WebGUI/Form/Username.pm index 0185d611b..2493530d9 100644 --- a/lib/WebGUI/Form/Username.pm +++ b/lib/WebGUI/Form/Username.pm @@ -138,7 +138,7 @@ sub www_check { my $session = shift; my $input = $session->form->param('input'); - $session->http->setMimeType( 'application/json' ); + $session->response->content_type( 'application/json' ); my $i18n = WebGUI::International->new($session, 'Form_Username'); my $error = ''; diff --git a/lib/WebGUI/Operation/Auth.pm b/lib/WebGUI/Operation/Auth.pm index 2b96cf912..688a22a25 100644 --- a/lib/WebGUI/Operation/Auth.pm +++ b/lib/WebGUI/Operation/Auth.pm @@ -84,7 +84,7 @@ sub www_auth { my $method = $authMethod->can( 'www_' . $methodCall ) || $authMethod->can( $methodCall ); my $out = $method->( $authMethod ); - if (substr($session->http->getMimeType(),0,9) eq "text/html") { + if (substr($session->response->content_type(),0,9) eq "text/html") { return $session->style->userStyle($out); } else { diff --git a/lib/WebGUI/Operation/Cron.pm b/lib/WebGUI/Operation/Cron.pm index a9fb858ce..9ec43f656 100644 --- a/lib/WebGUI/Operation/Cron.pm +++ b/lib/WebGUI/Operation/Cron.pm @@ -269,7 +269,7 @@ Checks to ensure the requestor is who we think it is, and then executes a cron j sub www_runCronJob { my $session = shift; - $session->http->setMimeType("text/plain"); + $session->response->content_type("text/plain"); $session->http->setCacheControl("none"); unless (Net::CIDR::Lite->new(@{ $session->config->get('spectreSubnets') })->find($session->request->address) || canView($session)) { $session->log->security("make a Spectre cron job runner request, but we're only allowed to accept requests from ".join(",",@{$session->config->get("spectreSubnets")})."."); diff --git a/lib/WebGUI/Operation/Spectre.pm b/lib/WebGUI/Operation/Spectre.pm index ed7ae959a..fcc2575c6 100644 --- a/lib/WebGUI/Operation/Spectre.pm +++ b/lib/WebGUI/Operation/Spectre.pm @@ -52,7 +52,7 @@ Checks to ensure the requestor is who we think it is, and then returns a JSON st sub www_spectreGetSiteData { my $session = shift; - $session->http->setMimeType("application/json"); + $session->response->content_type("application/json"); $session->http->setCacheControl("none"); my %siteData = (); my $subnets = $session->config->get("spectreSubnets"); @@ -173,7 +173,7 @@ spectreSubnet, instead of checking the IP address of the spectre process. sub www_spectreTest { my $session = shift; - $session->http->setMimeType("text/plain"); + $session->response->content_type("text/plain"); $session->http->setCacheControl("none"); my $subnets = $session->config->get("spectreSubnets"); diff --git a/lib/WebGUI/Operation/SpellCheck.pm b/lib/WebGUI/Operation/SpellCheck.pm index 570b1645f..339749e73 100644 --- a/lib/WebGUI/Operation/SpellCheck.pm +++ b/lib/WebGUI/Operation/SpellCheck.pm @@ -222,7 +222,7 @@ sub www_spellCheck { } # add request id and send to client as JSON blob $result->{id} = $params->{id}; - $session->http->setMimeType("text/plain; charset=utf-8"); + $session->response->content_type("text/plain; charset=utf-8"); return JSON->new->encode($result); } diff --git a/lib/WebGUI/Operation/User.pm b/lib/WebGUI/Operation/User.pm index 8580cd892..04605104e 100644 --- a/lib/WebGUI/Operation/User.pm +++ b/lib/WebGUI/Operation/User.pm @@ -349,7 +349,7 @@ sub www_ajaxCreateUser { $mimeType = "application/xml"; } - $session->http->setMimeType( $mimeType ); + $session->response->content_type( $mimeType ); # Verify access if ( !canAdd($session) || !canUseService($session) ) { @@ -436,7 +436,7 @@ sub www_ajaxDeleteUser { $mimeType = "application/xml"; } - $session->http->setMimeType( $mimeType ); + $session->response->content_type( $mimeType ); # Verify access if ( !canEdit($session) || !canUseService($session) ) { @@ -503,7 +503,7 @@ sub www_ajaxUpdateUser { $mimeType = "application/xml"; } - $session->http->setMimeType( $mimeType ); + $session->response->content_type( $mimeType ); # Verify access if ( !canEdit($session) || !canUseService($session) ) { diff --git a/lib/WebGUI/Operation/Workflow.pm b/lib/WebGUI/Operation/Workflow.pm index e1a96cd91..86ee36e7e 100644 --- a/lib/WebGUI/Operation/Workflow.pm +++ b/lib/WebGUI/Operation/Workflow.pm @@ -480,7 +480,7 @@ Checks to ensure the requestor is who we think it is, and then executes a workfl sub www_runWorkflow { my $session = shift; - $session->http->setMimeType("text/plain"); + $session->response->content_type("text/plain"); $session->http->setCacheControl("none"); unless (Net::CIDR::Lite->new(@{ $session->config->get('spectreSubnets')} )->find($session->request->address) || canRunWorkflow($session)) { $session->log->security("make a Spectre workflow runner request, but we're only allowed to accept requests from ".join(",",@{$session->config->get("spectreSubnets")})."."); diff --git a/lib/WebGUI/Role/Asset/RssFeed.pm b/lib/WebGUI/Role/Asset/RssFeed.pm index 4465baec4..0f9fbe32f 100644 --- a/lib/WebGUI/Role/Asset/RssFeed.pm +++ b/lib/WebGUI/Role/Asset/RssFeed.pm @@ -559,7 +559,7 @@ Return Atom view of the syndicated items. sub www_viewAtom { my $self = shift; return $self->_httpBasicLogin unless $self->canView; - $self->session->http->setMimeType('application/atom+xml'); + $self->session->response->content_type('application/atom+xml'); return $self->getFeed( XML::FeedPP::Atom->new )->to_string; } @@ -574,7 +574,7 @@ Return Rdf view of the syndicated items. sub www_viewRdf { my $self = shift; return $self->_httpBasicLogin unless $self->canView; - $self->session->http->setMimeType('application/rdf+xml'); + $self->session->response->content_type('application/rdf+xml'); return $self->getFeed( XML::FeedPP::RDF->new )->to_string; } @@ -589,7 +589,7 @@ Return RSS view of the syndicated items. sub www_viewRss { my $self = shift; return $self->_httpBasicLogin unless $self->canView; - $self->session->http->setMimeType('application/rss+xml'); + $self->session->response->content_type('application/rss+xml'); return $self->getFeed( XML::FeedPP::RSS->new )->to_string; } diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index de414696c..0c9a77c96 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -568,7 +568,9 @@ sub open { my $request = WebGUI::Session::Request->new($env); $self->{_request} = $request; + ##Set defaults $self->{_response} = $request->new_response( 200 ); + $self->{_response}->content_type('text/html; charset=UTF-8'); # Use the WebGUI::Session::Request object to look up the sessionId from cookies, if it # wasn't given explicitly diff --git a/lib/WebGUI/Session/Http.pm b/lib/WebGUI/Session/Http.pm index 181996e5e..7310518b1 100644 --- a/lib/WebGUI/Session/Http.pm +++ b/lib/WebGUI/Session/Http.pm @@ -41,12 +41,10 @@ This package allows the manipulation of HTTP protocol information. $http->sendHeader(); - $mimetype = $http->getMimeType(); $boolean = $http->isRedirect(); $http->setCookie($name,$value); $http->setFilename($filename,$mimetype); - $http->setMimeType($mimetype); $http->setNoHeader($bool); $http->setRedirect($url); @@ -99,19 +97,6 @@ sub getLastModified { #------------------------------------------------------------------- -=head2 getMimeType ( ) - -Returns the current mime type of the document to be returned. - -=cut - -sub getMimeType { - my $self = shift; - return $self->{_http}{mimetype} || "text/html; charset=UTF-8"; -} - -#------------------------------------------------------------------- - =head2 getNoHeader ( ) Returns whether or not a HTTP header will be printed. @@ -248,7 +233,6 @@ sub sendHeader { if ($self->isRedirect()) { $response->header(Location => $self->getRedirectLocation); } else { - $response->content_type($self->getMimeType); my $cacheControl = $self->getCacheControl; my $date = ($userId eq "1") ? HTTP::Date::time2str($self->getLastModified) : HTTP::Date::time2str(); # under these circumstances, don't allow caching @@ -373,7 +357,7 @@ sub setCookie { =head2 setFilename ( filename [, mimetype] ) -Override the default filename for the document, which is usually the page url. Usually used with setMimeType(). +Override the default filename for the document, which is usually the page url. =head3 filename @@ -389,7 +373,7 @@ sub setFilename { my $self = shift; $self->{_http}{filename} = shift; my $mimetype = shift || "application/octet-stream"; - $self->setMimeType($mimetype); + $self->session->response->content_type($mimetype); } @@ -427,25 +411,6 @@ sub setLastModified { #------------------------------------------------------------------- -=head2 setMimeType ( mimetype ) - -Override mime type for the document, which is defaultly "text/html; charset=UTF-8". Also see setFilename(). - -B By setting the mime type to something other than "text/html" WebGUI will automatically not process the normal page contents. Instead it will return only the content of your Wobject function or Operation. - -=head3 mimetype - -The mime type for the document. - -=cut - -sub setMimeType { - my $self = shift; - $self->{_http}{mimetype} = shift; -} - -#------------------------------------------------------------------- - =head2 setNoHeader ( boolean ) Disables the printing of a HTTP header. Useful in situations when content is not diff --git a/lib/WebGUI/Session/Output.pm b/lib/WebGUI/Session/Output.pm index 0059301f4..470f9b41c 100644 --- a/lib/WebGUI/Session/Output.pm +++ b/lib/WebGUI/Session/Output.pm @@ -77,7 +77,7 @@ has been set to a non-text type, macros will automatically be skipped. sub print { my $self = shift; my $content = shift; - my $skipMacros = shift || !($self->session->http->getMimeType =~ /^text/); + my $skipMacros = shift || !($self->session->response->content_type =~ /^text/); WebGUI::Macro::process($self->session, \$content) unless $skipMacros; my $handle = $self->{_handle}; if (defined $handle) { diff --git a/lib/WebGUI/Shop/AddressBook.pm b/lib/WebGUI/Shop/AddressBook.pm index 802bb8082..50b8b7384 100644 --- a/lib/WebGUI/Shop/AddressBook.pm +++ b/lib/WebGUI/Shop/AddressBook.pm @@ -527,7 +527,7 @@ parameter sub www_ajaxGetAddress { my $self = shift; my $session = $self->session; - $session->http->setMimeType('text/plain'); + $session->response->content_type('text/plain'); my $addressId = $session->form->get('addressId'); my $address = $self->getAddress($addressId) or return; @@ -553,7 +553,7 @@ sub www_ajaxSave { else { $obj = $self->addAddress($address); } - $session->http->setMimeType('text/plain'); + $session->response->content_type('text/plain'); return $obj->getId; } diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index accad3fb5..b2568ecee 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -942,7 +942,7 @@ sub www_ajaxPrices { $ship->getOptions($self); } || [], }; - $session->http->setMimeType('text/plain'); + $session->response->content_type('text/plain'); return JSON->new->encode($response); } @@ -961,7 +961,7 @@ sub www_ajaxSetCartItemShippingId { my $item = $self->getItem($form->get('itemId')); my $address = $form->get('addressId') || undef; $item && $item->update({ shippingAddressId => $address }); - $session->http->setMimeType('text/plain'); + $session->response->content_type('text/plain'); return 'ok'; } diff --git a/lib/WebGUI/Shop/PayDriver/ITransact.pm b/lib/WebGUI/Shop/PayDriver/ITransact.pm index 06a7133ae..ad37c98e0 100644 --- a/lib/WebGUI/Shop/PayDriver/ITransact.pm +++ b/lib/WebGUI/Shop/PayDriver/ITransact.pm @@ -699,7 +699,7 @@ do whatever other activity a Sku purchase would allow. sub www_processRecurringTransactionPostback { my $self = shift; my $session = $self->session; - $session->http->setMimeType('text/plain'); + $session->response->content_type('text/plain'); my $form = $session->form; # Get posted data of interest diff --git a/lib/WebGUI/Shop/TaxDriver/EU.pm b/lib/WebGUI/Shop/TaxDriver/EU.pm index 94b21cd71..af616be98 100644 --- a/lib/WebGUI/Shop/TaxDriver/EU.pm +++ b/lib/WebGUI/Shop/TaxDriver/EU.pm @@ -1079,7 +1079,7 @@ sub www_getTaxGroupsAsJSON { $group->{ isDefault } = 1 if $id eq $self->get( 'defaultGroup' ); } - $self->session->http->setMimeType( 'application/json' ); + $self->session->response->content_type( 'application/json' ); return to_json( { records => $taxGroups } ); } @@ -1158,7 +1158,7 @@ sub www_getVATNumbersAsJSON { push @numbers, $number; } - $self->session->http->setMimeType( 'application/json' ); + $self->session->response->content_type( 'application/json' ); return to_json( { records => \@numbers } ); } diff --git a/lib/WebGUI/Shop/TaxDriver/Generic.pm b/lib/WebGUI/Shop/TaxDriver/Generic.pm index 6b0fd35e9..15f48a4ac 100644 --- a/lib/WebGUI/Shop/TaxDriver/Generic.pm +++ b/lib/WebGUI/Shop/TaxDriver/Generic.pm @@ -486,7 +486,7 @@ sub www_getTaxesAsJson { $results{'startIndex'} = $startIndex; $results{'sort'} = undef; $results{'dir'} = $sortDir; - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON::to_json(\%results); } diff --git a/lib/WebGUI/Shop/Transaction.pm b/lib/WebGUI/Shop/Transaction.pm index 674d41ef3..f2c6f54d8 100644 --- a/lib/WebGUI/Shop/Transaction.pm +++ b/lib/WebGUI/Shop/Transaction.pm @@ -1069,7 +1069,7 @@ sub www_getTransactionsAsJson { $results{'startIndex'} = $startIndex; $results{'sort'} = undef; $results{'dir'} = "desc"; - $session->http->setMimeType('application/json'); + $session->response->content_type('application/json'); return JSON->new->encode(\%results); } diff --git a/lib/WebGUI/Shop/Vendor.pm b/lib/WebGUI/Shop/Vendor.pm index 595480046..af0da87de 100644 --- a/lib/WebGUI/Shop/Vendor.pm +++ b/lib/WebGUI/Shop/Vendor.pm @@ -619,7 +619,7 @@ sub www_payoutDataAsJSON { results => $paginator->getPageData, }; - $session->http->setMimeType( 'application/json' ); + $session->response->content_type( 'application/json' ); return JSON::to_json( $data ); } @@ -665,7 +665,7 @@ sub www_setPayoutStatus { $item->update({ vendorPayoutStatus => $status }); } - $session->http->setMimeType( 'text/plain' ); + $session->response->content_type( 'text/plain' ); return $status; } @@ -745,7 +745,7 @@ sub www_vendorTotalsAsJSON { push @dataset, $dataset; } - $session->http->setMimeType( 'application/json' ); + $session->response->content_type( 'application/json' ); return JSON::to_json( { vendors => \@dataset } ); } diff --git a/lib/WebGUI/Wizard/Setup.pm b/lib/WebGUI/Wizard/Setup.pm index feeb4900c..503e9ad79 100644 --- a/lib/WebGUI/Wizard/Setup.pm +++ b/lib/WebGUI/Wizard/Setup.pm @@ -126,7 +126,7 @@ label.formDescription { display: block; margin-top: 1em; font-weight: bold }
' . $output . '
'; - $session->http->setMimeType("text/html"); + $session->response->content_type("text/html"); return $page; } diff --git a/t/Operation/User/service.t b/t/Operation/User/service.t index 21f7bfa65..a6032059e 100644 --- a/t/Operation/User/service.t +++ b/t/Operation/User/service.t @@ -43,7 +43,7 @@ plan tests => 56; # Increment this number for each test you create # - user $session->user({ userId => 1 }); $response = WebGUI::Operation::User::www_ajaxCreateUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" ); +is( $session->response->content_type, 'application/json', "Correct mime type (default: json)" ); cmp_deeply( JSON->new->decode( $response ), { @@ -61,7 +61,7 @@ $session->request->setup_body({ as => "xml", }); $response = WebGUI::Operation::User::www_ajaxCreateUser( $session ); -is( $session->http->getMimeType, 'application/xml', "Correct mime type (as => xml)" ); +is( $session->response->content_type, 'application/xml', "Correct mime type (as => xml)" ); cmp_deeply( XML::Simple::XMLin( $response ), { @@ -82,7 +82,7 @@ $session->request->setup_body({ }); $session->user({ userId => 3 }); $response = WebGUI::Operation::User::www_ajaxCreateUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (as => json)" ); +is( $session->response->content_type, 'application/json', "Correct mime type (as => json)" ); cmp_deeply( JSON->new->decode( $response ), { @@ -99,7 +99,7 @@ $session->request->setup_body({ firstName => 'Jake', }); $response = WebGUI::Operation::User::www_ajaxCreateUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" ); +is( $session->response->content_type, 'application/json', "Correct mime type (default: json)" ); cmp_deeply( JSON->new->decode( $response ), { @@ -121,7 +121,7 @@ $session->request->setup_body({ 'auth:LDAP:connectDN' => 'u=andy;o=block-e;dc=shawshank;dc=me', }); $response = WebGUI::Operation::User::www_ajaxCreateUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json" ); +is( $session->response->content_type, 'application/json', "Correct mime type (default: json" ); $responseObj = JSON->new->decode( $response ); cmp_deeply( $responseObj, @@ -153,7 +153,7 @@ $session->request->setup_body({ 'auth:LDAP:connectDN' => 'u=red;o=block-e;dc=shawshank;dc=me', }); $response = WebGUI::Operation::User::www_ajaxCreateUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json" ); +is( $session->response->content_type, 'application/json', "Correct mime type (default: json" ); $responseObj = JSON->new->decode( $response ); cmp_deeply( $responseObj, @@ -183,7 +183,7 @@ is( $auth->getParams->{connectDN}, 'u=red;o=block-e;dc=shawshank;dc=me', "Auth p # - user $session->user({ userId => 1 }); $response = WebGUI::Operation::User::www_ajaxUpdateUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" ); +is( $session->response->content_type, 'application/json', "Correct mime type (default: json)" ); cmp_deeply( JSON->new->decode( $response ), { @@ -201,7 +201,7 @@ $session->request->setup_body({ as => "xml", }); $response = WebGUI::Operation::User::www_ajaxUpdateUser( $session ); -is( $session->http->getMimeType, 'application/xml', "Correct mime type (as => xml)" ); +is( $session->response->content_type, 'application/xml', "Correct mime type (as => xml)" ); cmp_deeply( XML::Simple::XMLin( $response ), { @@ -222,7 +222,7 @@ $session->request->setup_body({ }); $session->user({ userId => 3 }); $response = WebGUI::Operation::User::www_ajaxUpdateUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (as => json)" ); +is( $session->response->content_type, 'application/json', "Correct mime type (as => json)" ); cmp_deeply( JSON->new->decode( $response ), { @@ -241,7 +241,7 @@ $session->request->setup_body({ }); $session->user({ userId => 3 }); $response = WebGUI::Operation::User::www_ajaxUpdateUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" ); +is( $session->response->content_type, 'application/json', "Correct mime type (default: json)" ); cmp_deeply( JSON->new->decode( $response ), { @@ -263,7 +263,7 @@ $session->request->setup_body({ 'auth:LDAP:connectDN' => 'u=rich;o=escapee;dc=shawshank;dc=me', }); $response = WebGUI::Operation::User::www_ajaxUpdateUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json" ); +is( $session->response->content_type, 'application/json', "Correct mime type (default: json" ); $responseObj = JSON->new->decode( $response ); cmp_deeply( $responseObj, @@ -294,7 +294,7 @@ $session->request->setup_body({ 'auth:LDAP:connectDN' => 'u=red;o=parollee;dc=shawshank;dc=me', }); $response = WebGUI::Operation::User::www_ajaxUpdateUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json" ); +is( $session->response->content_type, 'application/json', "Correct mime type (default: json" ); $responseObj = JSON->new->decode( $response ); cmp_deeply( $responseObj, @@ -323,7 +323,7 @@ is( $auth->getParams->{connectDN}, 'u=red;o=parollee;dc=shawshank;dc=me', "Auth # - user $session->user({ userId => 1 }); $response = WebGUI::Operation::User::www_ajaxDeleteUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" ); +is( $session->response->content_type, 'application/json', "Correct mime type (default: json)" ); cmp_deeply( JSON->new->decode( $response ), { @@ -341,7 +341,7 @@ $session->request->setup_body({ as => "xml", }); $response = WebGUI::Operation::User::www_ajaxDeleteUser( $session ); -is( $session->http->getMimeType, 'application/xml', "Correct mime type (as => xml)" ); +is( $session->response->content_type, 'application/xml', "Correct mime type (as => xml)" ); cmp_deeply( XML::Simple::XMLin( $response ), { @@ -360,7 +360,7 @@ $session->request->setup_body({ }); $session->user({ userId => 3 }); $response = WebGUI::Operation::User::www_ajaxDeleteUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (as => json)" ); +is( $session->response->content_type, 'application/json', "Correct mime type (as => json)" ); cmp_deeply( JSON->new->decode( $response ), { @@ -377,7 +377,7 @@ $session->request->setup_body({ }); $session->user({ userId => 3 }); $response = WebGUI::Operation::User::www_ajaxDeleteUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" ); +is( $session->response->content_type, 'application/json', "Correct mime type (default: json)" ); cmp_deeply( JSON->new->decode( $response ), { @@ -394,7 +394,7 @@ $session->request->setup_body({ }); $session->user({ userId => 3 }); $response = WebGUI::Operation::User::www_ajaxDeleteUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" ); +is( $session->response->content_type, 'application/json', "Correct mime type (default: json)" ); cmp_deeply( JSON->new->decode( $response ), { @@ -411,7 +411,7 @@ $session->request->setup_body({ }); $session->user({ userId => 3 }); $response = WebGUI::Operation::User::www_ajaxDeleteUser( $session ); -is( $session->http->getMimeType, 'application/json', "Correct mime type (default: json)" ); +is( $session->response->content_type, 'application/json', "Correct mime type (default: json)" ); cmp_deeply( JSON->new->decode( $response ), { @@ -427,7 +427,7 @@ $session->request->setup_body({ userId => $userAndy->getId, }); $response = WebGUI::Operation::User::www_ajaxDeleteUser( $session ); -is( $session->http->getMimeType, 'application/json', 'Correct mime type (default: json)' ); +is( $session->response->content_type, 'application/json', 'Correct mime type (default: json)' ); cmp_deeply( JSON->new->decode( $response ), { @@ -441,7 +441,7 @@ $session->request->setup_body({ userId => $userRed->getId, }); $response = WebGUI::Operation::User::www_ajaxDeleteUser( $session ); -is( $session->http->getMimeType, 'application/json', 'Correct mime type (default: json)' ); +is( $session->response->content_type, 'application/json', 'Correct mime type (default: json)' ); cmp_deeply( JSON->new->decode( $response ), { diff --git a/t/Session/Http.t b/t/Session/Http.t index 7642f7dc6..1dbbbffe3 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 => 46; +plan tests => 44; my $session = WebGUI::Test->session; @@ -55,19 +55,6 @@ $response->status('302'); ok($http->isRedirect, '... 302 is too'); $response->status('200'); -#################################################### -# -# setMimeType, getMimeType -# -#################################################### - -$http->setMimeType(''); -is($http->getMimeType, 'text/html; charset=UTF-8', 'set/get MimeType: default is text/html'); - -$http->setMimeType('image/jpeg'); -is($http->getMimeType, 'image/jpeg', 'set/get MimeType: set specific type and get it'); -$http->setMimeType(''); - #################################################### # # setStreamedFile, getStreamedFile @@ -91,13 +78,13 @@ $http->setStreamedFile(''); $http->setFilename('foo.bin'); is($http->getFilename, 'foo.bin', 'set/get Filename: filename passed'); -is($http->getMimeType(), 'application/octet-stream', 'set/get Filename: default mime type is octet/stream'); +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($http->getMimeType(), 'text/plain', 'set/get Filename: mime type set'); +is($response->content_type(), 'text/plain', 'set/get Filename: mime type set'); $http->setFilename(''); -$http->setMimeType(''); +$response->content_type(''); #################################################### # @@ -201,6 +188,7 @@ is($http->sendHeader, undef, 'sendHeader returns undef when no request object is headers_out($session1->response->headers), { 'Location' => '/here/there', + 'Content-Type' => 'text/html; charset=UTF-8', }, '... location set' ); @@ -220,7 +208,6 @@ is($http->sendHeader, undef, 'sendHeader returns undef when no request object is my $http = $session->http; my $response = $session->response; $response->status(200); - $http->setMimeType(''); $session->request->protocol(''); $http->setLastModified(1200); @@ -255,7 +242,7 @@ is($http->sendHeader, undef, 'sendHeader returns undef when no request object is my $http = $session->http; my $response = $session->response; $http->setFilename('image.png'); - $http->setMimeType('image/png'); + $response->content_type('image/png'); $http->sendHeader(); is($response->headers->content_type, 'image/png', 'sendHeader: mimetype'); cmp_deeply( diff --git a/t/Session/Output.t b/t/Session/Output.t index 15c35f897..e19441dd5 100644 --- a/t/Session/Output.t +++ b/t/Session/Output.t @@ -52,11 +52,11 @@ like($response->body->[-1], qr/3\Z/, '... macro processing'); $output->print('^#;', 1); like($response->body->[-1], qr/\^#;\Z/, '... macro processing skipped due to flag'); -$session->http->setMimeType('application/json'); +$session->response->content_type('application/json'); $output->print('^#;'); like($response->body->[-1], qr/\^#;\Z/, '... macro processing skipped due to mime type'); -$session->http->setMimeType(''); +$session->response->content_type(''); $output->setHandle($otherHandle); $output->print('New content'); is($otherHandleBuffer, 'New content', '... set to explicit handle'); diff --git a/t/Shop/TaxDriver/Generic.t b/t/Shop/TaxDriver/Generic.t index cfbad801c..8ea110a4e 100644 --- a/t/Shop/TaxDriver/Generic.t +++ b/t/Shop/TaxDriver/Generic.t @@ -596,7 +596,7 @@ is($taxer->getTaxRate( $taxableDonation, $taxFreeAddress ), 0, 'calculate: simpl $session->user({userId=>3}); my $json = $taxer->www_getTaxesAsJson(); ok($json, 'www_getTaxesAsJson returned something'); -is($session->http->getMimeType, 'application/json', 'MIME type set to application/json'); +is($session->response->content_type, 'application/json', 'MIME type set to application/json'); my $jsonTax = JSON::from_json($json); cmp_deeply( $jsonTax, diff --git a/t/Shop/Transaction.t b/t/Shop/Transaction.t index 0bda1b01d..218df6141 100644 --- a/t/Shop/Transaction.t +++ b/t/Shop/Transaction.t @@ -191,7 +191,7 @@ is(scalar @{$transaction->getItems}, 0, "can delete items"); $session->user({userId=>3}); my $json = WebGUI::Shop::Transaction->www_getTransactionsAsJson($session); ok($json, 'www_getTransactionsAsJson returned something'); -is($session->http->getMimeType, 'application/json', 'MIME type set to application/json'); +is($session->response->content_type, 'application/json', 'MIME type set to application/json'); my $jsonTransactions = JSON::from_json($json); cmp_deeply( $jsonTransactions,