Skip to content

Commit

Permalink
MDL-33564 rss: on error return HTTP error status
Browse files Browse the repository at this point in the history
Also remove an unecessary debugging notice.
  • Loading branch information
danpoltawski committed Aug 28, 2015
1 parent e28004e commit 20dbcc3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ information provided here is intended especially for developers.
enrol_cohort_enrol_all_users()
enrol_cohort_search_cohorts()
* The never unused webdav_locks table was dropped.
* rss_error() now supports returning of correct HTTP status of error and will return '404 Not Found'
unless other status is specified.

=== 2.9.1 ===

Expand Down
23 changes: 13 additions & 10 deletions rss/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

// RSS feeds must be enabled site-wide.
if (empty($CFG->enablerssfeeds)) {
debugging('DISABLED (admin variables)');
rss_error();
}

Expand Down Expand Up @@ -86,14 +85,14 @@

if (empty($context)) {
// This shouldnt happen. something bad is going on.
rss_error('rsserror');
rss_error();
}

// Make sure that $CFG->siteguest is set.
if (empty($CFG->siteguest)) {
if (!$guestid = $DB->get_field('user', 'id', array('username' => 'guest', 'mnethostid' => $CFG->mnet_localhost_id))) {
// Guest does not exist yet, weird.
rss_error('rsserror');
rss_error();
}
set_config('siteguest', $guestid);
}
Expand All @@ -111,7 +110,7 @@
// Authenticate the user from the token.
$userid = rss_get_userid_from_token($token);
if (!$userid) {
rss_error('rsserrorauth');
rss_error('rsserrorauth', 'rss.xml', 0, '403 Forbidden');
}
}

Expand All @@ -134,9 +133,9 @@
require_login($course, $autologinguest, $cm, $setwantsurltome, $preventredirect);
} catch (Exception $e) {
if (isguestuser()) {
rss_error('rsserrorguest');
rss_error('rsserrorguest', 'rss.xml', 0, '403 Forbidden');
} else {
rss_error('rsserrorauth');
rss_error('rsserrorauth', 'rss.xml', 0, '403 Forbidden');
}
}

Expand Down Expand Up @@ -177,11 +176,15 @@
* @category rss
*
* @param string $error the error type, default is rsserror
* @param string $filename the name of the file to create (NOT USED)
* @param int $lifetime UNSURE (NOT USED)
* @param string $filename the name of the file to created
* @param int $unused
* @param $statuscode http 1.1 statuscode indicicating the error
* @uses exit
*/
function rss_error($error='rsserror', $filename='rss.xml', $lifetime=0) {
send_file(rss_geterrorxmlfile($error), $filename, $lifetime, false, true);
function rss_error($error='rsserror', $filename='rss.xml', $unused=0, $statuscode='404 Not Found') {
header("HTTP/1.1 $statuscode");
header('Content-Disposition: inline; filename="'.$filename.'"');
header('Content-Type: application/xml');
echo rss_geterrorxmlfile($error);
exit;
}

0 comments on commit 20dbcc3

Please sign in to comment.