)/i', $s ) ) { return preg_replace( '/\<(\s*)(cross-domain-policy(?=\s|\>))/i', '<$1NOT-$2', $s ); } else { return $s; } } /** * Set the Content-Length header if possible * * This sets Content-Length for the following cases: * - When the response body is meaningful (HTTP 200/404). * - On any HTTP 1.0 request response. This improves cooperation with certain CDNs. * * This assumes that HEAD requests are processed as GET requests by MediaWiki and that * the webserver is tasked with stripping out the body. * * Setting Content-Length can prevent clients from getting stuck waiting on PHP to finish * while deferred updates are running. * * @param int $length */ private static function emitContentLength( $length ) { if ( headers_sent() ) { wfDebug( __METHOD__ . "() headers already sent" ); return; } if ( in_array( http_response_code(), [ 200, 404 ], true ) || ( $_SERVER['SERVER_PROTOCOL'] ?? null ) === 'HTTP/1.0' ) { header( "Content-Length: $length" ); } } }