X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FWebRequest.php;h=03410ccc9f8889ad6bf8a57f9587c9fabec66262;hb=bd09564f246b961b0524d6e5310ce0f16d1b6f5e;hp=b9c9b862edd34a9922e5ba8f0058a59791916665;hpb=100675aeb5e500823b5f6d536a431a95e9e43caf;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/WebRequest.php b/includes/WebRequest.php index b9c9b862ed..03410ccc9f 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -176,6 +176,8 @@ class WebRequest { * @return string */ public static function detectServer() { + global $wgAssumeProxiesUseDefaultProtocolPorts; + $proto = self::detectProtocol(); $stdPort = $proto === 'https' ? 443 : 80; @@ -186,13 +188,15 @@ class WebRequest { if ( !isset( $_SERVER[$varName] ) ) { continue; } + $parts = IP::splitHostAndPort( $_SERVER[$varName] ); if ( !$parts ) { // Invalid, do not use continue; } + $host = $parts[0]; - if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) { + if ( $wgAssumeProxiesUseDefaultProtocolPorts && isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) { // Bug 70021: Assume that upstream proxy is running on the default // port based on the protocol. We have no reliable way to determine // the actual port in use upstream. @@ -1293,6 +1297,7 @@ class FauxRequest extends WebRequest { private $wasPosted = false; private $session = array(); private $requestUrl; + protected $cookies = array(); /** * @param array $data Array of *non*-urlencoded key => value pairs, the @@ -1367,7 +1372,38 @@ class FauxRequest extends WebRequest { } public function getCookie( $key, $prefix = null, $default = null ) { - return $default; + if ( $prefix === null ) { + global $wgCookiePrefix; + $prefix = $wgCookiePrefix; + } + $name = $prefix . $key; + return isset( $this->cookies[$name] ) ? $this->cookies[$name] : $default; + } + + /** + * @since 1.26 + * @param string $name Unprefixed name of the cookie to set + * @param string|null $value Value of the cookie to set + * @param string|null $prefix Cookie prefix. Defaults to $wgCookiePrefix + */ + public function setCookie( $key, $value, $prefix = null ) { + $this->setCookies( array( $key => $value ), $prefix ); + } + + /** + * @since 1.26 + * @param array $cookies + * @param string|null $prefix Cookie prefix. Defaults to $wgCookiePrefix + */ + public function setCookies( $cookies, $prefix = null ) { + if ( $prefix === null ) { + global $wgCookiePrefix; + $prefix = $wgCookiePrefix; + } + foreach ( $cookies as $key => $value ) { + $name = $prefix . $key; + $this->cookies[$name] = $value; + } } public function checkSessionCookie() { @@ -1398,8 +1434,18 @@ class FauxRequest extends WebRequest { * @param string $val */ public function setHeader( $name, $val ) { - $name = strtoupper( $name ); - $this->headers[$name] = $val; + $this->setHeaders( array( $name => $val ) ); + } + + /** + * @since 1.26 + * @param array $headers + */ + public function setHeaders( $headers ) { + foreach ( $headers as $name => $val ) { + $name = strtoupper( $name ); + $this->headers[$name] = $val; + } } /**