From 499e5fd4877416c65d71118bff5d769b75883cb0 Mon Sep 17 00:00:00 2001 From: Tyler Anthony Romeo Date: Wed, 23 Oct 2013 15:32:13 +0000 Subject: [PATCH] Fixed stream wrapper in PhpHttpRequest Issue introduced when SSL verification was added to PHPHttpRequest. For HTTP and HTTPS stream, PHP expects "http" as the steam context name, regardless of SSL. Change-Id: I12c5d3d9aded6e704ebabe85b86e556fd0e99479 Follows-Up: 1c927b1df2a (Iab2bda1ebc) Bug: 56047 --- includes/HttpFunctions.php | 58 ++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index 9093c830aa..84d0437ae3 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -862,6 +862,7 @@ class PhpHttpRequest extends MWHttpRequest { } $this->reqHeaders['Accept'] = "*/*"; + $this->reqHeaders['Connection'] = 'Close'; if ( $this->method == 'POST' ) { // Required for HTTP 1.0 POSTs $this->reqHeaders['Content-Length'] = strlen( $this->postData ); @@ -870,52 +871,47 @@ class PhpHttpRequest extends MWHttpRequest { } } - $options = array(); - if ( $this->proxy ) { - $options['proxy'] = $this->urlToTCP( $this->proxy ); - $options['request_fulluri'] = true; - } + // Set up PHP stream context + $options = array( + 'http' => array( + 'method' => $this->method, + 'header' => implode( "\r\n", $this->getHeaderList() ), + 'protocol_version' => '1.1', + 'max_redirects' => $this->followRedirects ? $this->maxRedirects : 0, + 'ignore_errors' => true, + 'timeout' => $this->timeout, + // Curl options in case curlwrappers are installed + 'curl_verify_ssl_host' => $this->sslVerifyHost ? 2 : 0, + 'curl_verify_ssl_peer' => $this->sslVerifyCert, + ), + 'ssl' => array( + 'verify_peer' => $this->sslVerifyCert, + 'SNI_enabled' => true, + ), + ); - if ( !$this->followRedirects ) { - $options['max_redirects'] = 0; - } else { - $options['max_redirects'] = $this->maxRedirects; + if ( $this->proxy ) { + $options['http']['proxy'] = $this->urlToTCP( $this->proxy ); + $options['http']['request_fulluri'] = true; } - $options['method'] = $this->method; - $options['header'] = implode( "\r\n", $this->getHeaderList() ); - // Note that at some future point we may want to support - // HTTP/1.1, but we'd have to write support for chunking - // in version of PHP < 5.3.1 - $options['protocol_version'] = "1.0"; - - // This is how we tell PHP we want to deal with 404s (for example) ourselves. - // Only works on 5.2.10+ - $options['ignore_errors'] = true; - if ( $this->postData ) { - $options['content'] = $this->postData; + $options['http']['content'] = $this->postData; } - $options['timeout'] = $this->timeout; - if ( $this->sslVerifyHost ) { - $options['CN_match'] = $this->parsedUrl['host']; - } - if ( $this->sslVerifyCert ) { - $options['verify_peer'] = true; + $options['ssl']['CN_match'] = $this->parsedUrl['host']; } if ( is_dir( $this->caInfo ) ) { - $options['capath'] = $this->caInfo; + $options['ssl']['capath'] = $this->caInfo; } elseif ( is_file( $this->caInfo ) ) { - $options['cafile'] = $this->caInfo; + $options['ssl']['cafile'] = $this->caInfo; } elseif ( $this->caInfo ) { throw new MWException( "Invalid CA info passed: {$this->caInfo}" ); } - $scheme = $this->parsedUrl['scheme']; - $context = stream_context_create( array( "$scheme" => $options ) ); + $context = stream_context_create( $options ); $this->headerList = array(); $reqCount = 0; -- 2.20.1