diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-06-26 10:32:50 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-06-26 16:14:15 +0200 |
commit | 79d9841bce94c0e9abf5e53c845236296a8999de (patch) | |
tree | b676ba133dbf68ad0d64ba21bf192bdb4308294a /lib | |
parent | d9d557a5ef31d63a8807feac1c530c36a077607f (diff) | |
download | nextcloud-server-79d9841bce94c0e9abf5e53c845236296a8999de.tar.gz nextcloud-server-79d9841bce94c0e9abf5e53c845236296a8999de.zip |
Replace hardcoded status headers with calls to http_response_code()
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 23 | ||||
-rw-r--r-- | lib/private/legacy/api.php | 4 | ||||
-rw-r--r-- | lib/private/legacy/files.php | 8 | ||||
-rw-r--r-- | lib/private/legacy/response.php | 34 |
4 files changed, 14 insertions, 55 deletions
diff --git a/lib/base.php b/lib/base.php index 60a4c03bc41..598e3ed5757 100644 --- a/lib/base.php +++ b/lib/base.php @@ -287,8 +287,7 @@ class OC { // Allow ajax update script to execute without being stopped if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { // send http status 503 - header('HTTP/1.1 503 Service Temporarily Unavailable'); - header('Status: 503 Service Temporarily Unavailable'); + http_response_code(503); header('Retry-After: 120'); // render error page @@ -344,8 +343,7 @@ class OC { if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { // send http status 503 - header('HTTP/1.1 503 Service Temporarily Unavailable'); - header('Status: 503 Service Temporarily Unavailable'); + http_response_code(503); header('Retry-After: 120'); // render error page @@ -600,9 +598,7 @@ class OC { } catch (\RuntimeException $e) { if (!self::$CLI) { - $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); - $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); + http_response_code(503); } // we can't use the template error page here, because this needs the // DI container which isn't available yet @@ -689,7 +685,7 @@ class OC { } exit(1); } else { - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); + http_response_code(503); OC_Util::addStyle('guest'); OC_Template::printGuestPage('', 'error', array('errors' => $errors)); exit; @@ -778,16 +774,14 @@ class OC { } if(substr($request->getRequestUri(), -11) === '/status.php') { - OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); - header('Status: 400 Bad Request'); + http_response_code(400); header('Content-Type: application/json'); echo '{"error": "Trusted domain error.", "code": 15}'; exit(); } if (!$isScssRequest) { - OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); - header('Status: 400 Bad Request'); + http_response_code(400); \OC::$server->getLogger()->info( 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', @@ -997,7 +991,7 @@ class OC { } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { //header('HTTP/1.0 404 Not Found'); } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { - OC_Response::setStatus(405); + http_response_code(405); return; } } @@ -1007,8 +1001,7 @@ class OC { // not allowed any more to prevent people // mounting this root directly. // Users need to mount remote.php/webdav instead. - header('HTTP/1.1 405 Method Not Allowed'); - header('Status: 405 Method Not Allowed'); + http_response_code(405); return; } diff --git a/lib/private/legacy/api.php b/lib/private/legacy/api.php index fde1d99e79d..40bf6132e28 100644 --- a/lib/private/legacy/api.php +++ b/lib/private/legacy/api.php @@ -88,7 +88,7 @@ class OC_API { } else { header('WWW-Authenticate: Basic realm="Authorisation Required"'); } - header('HTTP/1.0 401 Unauthorized'); + http_response_code(401); } foreach($result->getHeaders() as $name => $value) { @@ -101,7 +101,7 @@ class OC_API { $statusCode = self::mapStatusCodes($result->getStatusCode()); if (!is_null($statusCode)) { $meta['statuscode'] = $statusCode; - OC_Response::setStatus($statusCode); + http_response_code($statusCode); } } diff --git a/lib/private/legacy/files.php b/lib/private/legacy/files.php index f4474197d86..159e18c7754 100644 --- a/lib/private/legacy/files.php +++ b/lib/private/legacy/files.php @@ -83,7 +83,7 @@ class OC_Files { $type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename)); if ($fileSize > -1) { if (!empty($rangeArray)) { - header('HTTP/1.1 206 Partial Content', true); + http_response_code(206); header('Accept-Ranges: bytes', true); if (count($rangeArray) > 1) { $type = 'multipart/byteranges; boundary='.self::getBoundary(); @@ -286,12 +286,12 @@ class OC_Files { if (\OC\Files\Filesystem::isReadable($filename)) { self::sendHeaders($filename, $name, $rangeArray); } elseif (!\OC\Files\Filesystem::file_exists($filename)) { - header("HTTP/1.1 404 Not Found"); + http_response_code(404); $tmpl = new OC_Template('', '404', 'guest'); $tmpl->printPage(); exit(); } else { - header("HTTP/1.1 403 Forbidden"); + http_response_code(403); die('403 Forbidden'); } if (isset($params['head']) && $params['head']) { @@ -321,7 +321,7 @@ class OC_Files { // file is unseekable header_remove('Accept-Ranges'); header_remove('Content-Range'); - header("HTTP/1.1 200 OK"); + http_response_code(200); self::sendHeaders($filename, $name, array()); $view->readfile($filename); } diff --git a/lib/private/legacy/response.php b/lib/private/legacy/response.php index 4186822c269..2fc7b934d86 100644 --- a/lib/private/legacy/response.php +++ b/lib/private/legacy/response.php @@ -41,40 +41,6 @@ class OC_Response { const STATUS_SERVICE_UNAVAILABLE = 503; /** - * Set response status - * @param int $status a HTTP status code, see also the STATUS constants - */ - static public function setStatus($status) { - $protocol = \OC::$server->getRequest()->getHttpProtocol(); - switch($status) { - case self::STATUS_NOT_MODIFIED: - $status = $status . ' Not Modified'; - break; - case self::STATUS_TEMPORARY_REDIRECT: - if ($protocol == 'HTTP/1.0') { - $status = self::STATUS_FOUND; - // fallthrough - } else { - $status = $status . ' Temporary Redirect'; - break; - } - case self::STATUS_FOUND; - $status = $status . ' Found'; - break; - case self::STATUS_NOT_FOUND; - $status = $status . ' Not Found'; - break; - case self::STATUS_INTERNAL_SERVER_ERROR; - $status = $status . ' Internal Server Error'; - break; - case self::STATUS_SERVICE_UNAVAILABLE; - $status = $status . ' Service Unavailable'; - break; - } - header($protocol.' '.$status); - } - - /** * Sets the content disposition header (with possible workarounds) * @param string $filename file name * @param string $type disposition type, either 'attachment' or 'inline' |