Chad has uploaded a new change for review. https://gerrit.wikimedia.org/r/320322
Change subject: static.php: Consolidate error headers in wmfStaticShowError() ...................................................................... static.php: Consolidate error headers in wmfStaticShowError() Reduces a bit of code duplication and standardizes the messages by using HttpStatus Change-Id: I15298f18964c6d4de0c15fc0cfb3a7ac2f8bb7a9 --- M w/static.php 1 file changed, 9 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/mediawiki-config refs/changes/22/320322/1 diff --git a/w/static.php b/w/static.php index 814c85d..1b9e49d 100644 --- a/w/static.php +++ b/w/static.php @@ -29,7 +29,8 @@ require_once './MWVersion.php'; require getMediaWiki( 'includes/WebStart.php' ); -function wmfStaticShowError( $message, $smaxage = 60 ) { +function wmfStaticShowError( $message, $status, $smaxage = 60 ) { + HttpStatus::header( $status ); header( 'Cache-Control: ' . 's-maxage=' . (int)$smaxage . ', must-revalidate, max-age=0' @@ -48,15 +49,13 @@ $ctype = StreamFile::contentTypeFromPath( $filePath, /* safe: not for upload */ false ); if ( !$ctype || $ctype === 'unknown/unknown' ) { // Directory, extension-less file or unknown extension - header( 'HTTP/1.1 400 Bad Request' ); - wmfStaticShowError( 'Invalid file type' ); + wmfStaticShowError( 'Invalid file type', 400 ); return; } $stat = stat( $filePath ); if ( !$stat ) { - header( 'HTTP/1.1 404 Not Found' ); - wmfStaticShowError( 'Unknown file path', 300 ); + wmfStaticShowError( 'Unknown file path', 404, 300 ); return; } @@ -92,16 +91,14 @@ global $wgScriptPath, $IP; if ( !isset( $_SERVER['REQUEST_URI'] ) || !isset( $_SERVER['SCRIPT_NAME'] ) ) { - header( 'HTTP/1.1 500 Internal Server Error' ); - wmfStaticShowError( 'Invalid request' ); + wmfStaticShowError( 'Invalid request', 500 ); return; } // Ignore direct request (eg. "/w/static.php" or "/w/static.php/test") // (use strpos instead of equal to ignore pathinfo and query string) if ( strpos( $_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] ) === 0 ) { - header( 'HTTP/1.1 400 Bad Request' ); - wmfStaticShowError( 'Invalid request' ); + wmfStaticShowError( 'Invalid request', 400 ); return; } @@ -111,8 +108,7 @@ // Strip prefix $urlPrefix = $wgScriptPath; if ( strpos( $uriPath, $urlPrefix ) !== 0 ) { - header( 'HTTP/1.1 400 Bad Request' ); - wmfStaticShowError( 'Bad request' ); + wmfStaticShowError( 'Bad request', 400 ); return; } $path = substr( $uriPath, strlen( $urlPrefix ) ); @@ -150,8 +146,7 @@ } if ( strpos( $filePath, $branchDir ) !== 0 ) { - header( 'HTTP/1.1 400 Bad Request' ); - wmfStaticShowError( 'Bad request' ); + wmfStaticShowError( 'Bad request', 400 ); return; } @@ -183,8 +178,7 @@ } if ( !$fallback ) { - header( 'HTTP/1.1 404 Not Found' ); - wmfStaticShowError( 'Unknown file path', 300 ); + wmfStaticShowError( 'Unknown file path', 404, 300 ); $stats->increment( 'wmfstatic.notfound' ); return; } -- To view, visit https://gerrit.wikimedia.org/r/320322 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I15298f18964c6d4de0c15fc0cfb3a7ac2f8bb7a9 Gerrit-PatchSet: 1 Gerrit-Project: operations/mediawiki-config Gerrit-Branch: master Gerrit-Owner: Chad <ch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits