WebRequest: Radically simplify getRequestId() method

I don't actually think this will fix T273256, but it does help rule
out the 99.9% of possible causes that I don't currently suspect.

This is a static method meant to read global state. Rather than
accessing it through a chain of twenty global singletons and one
hundred method calls, just read the string already.

Bug: T273256
Change-Id: Ia542ac7aab7bdcbd15bdba5023be9efa9fca5c83
This commit is contained in:
Timo Tijhof 2021-01-30 00:55:36 +00:00 committed by Krinkle
parent 21dfb00fa3
commit 5ab13a054e

View file

@ -318,22 +318,21 @@ class WebRequest {
}
/**
* Get the unique request ID.
* This is either the value of the UNIQUE_ID envvar (if present) or a
* randomly-generated 24-character string.
* Get the current request ID.
*
* This is usually based on the `X-Request-Id` header, or the `UNIQUE_ID`
* environment variable, falling back to (process cached) randomly-generated string.
*
* @return string
* @since 1.27
*/
public static function getRequestId() {
// This method is called from various error handlers and should be kept simple.
// This method is called from various error handlers and MUST be kept simple and stateless.
if ( !self::$reqId ) {
global $wgAllowExternalReqID;
$id = $wgAllowExternalReqID
? RequestContext::getMain()->getRequest()->getHeader( 'X-Request-Id' )
: null;
if ( !$id ) {
if ( $wgAllowExternalReqID ) {
$id = $_SERVER['HTTP_X_REQUEST_ID'] ?? $_SERVER['UNIQUE_ID'] ?? wfRandomString( 24 );
} else {
$id = $_SERVER['UNIQUE_ID'] ?? wfRandomString( 24 );
}
self::$reqId = $id;