107 if ( is_array( $this->postData ) ) {
111 if ( $this->parsedUrl[
'scheme'] !=
'http'
112 && $this->parsedUrl[
'scheme'] !=
'https' ) {
113 $this->status->fatal(
'http-invalid-scheme', $this->parsedUrl[
'scheme'] );
116 $this->reqHeaders[
'Accept'] =
"*/*";
117 $this->reqHeaders[
'Connection'] =
'Close';
118 if ( $this->method ==
'POST' ) {
120 $this->reqHeaders[
'Content-Length'] = strlen( $this->postData );
121 if ( !isset( $this->reqHeaders[
'Content-Type'] ) ) {
122 $this->reqHeaders[
'Content-Type'] =
"application/x-www-form-urlencoded";
131 'protocol_version' =>
'1.1',
132 'max_redirects' => $this->followRedirects ? $this->maxRedirects : 0,
133 'ignore_errors' =>
true,
136 'curl_verify_ssl_host' => $this->sslVerifyHost ? 2 : 0,
141 'SNI_enabled' =>
true,
142 'ciphers' =>
'HIGH:!SSLv2:!SSLv3:-ADH:-kDH:-kECDH:-DSS',
143 'disable_compression' =>
true,
147 if ( $this->proxy ) {
149 $options[
'http'][
'request_fulluri'] =
true;
152 if ( $this->postData ) {
156 if ( $this->sslVerifyHost ) {
159 if ( version_compare( PHP_VERSION,
'5.6.0',
'>=' ) ) {
160 $options[
'ssl'][
'peer_name'] = $this->parsedUrl[
'host'];
162 $options[
'ssl'][
'CN_match'] = $this->parsedUrl[
'host'];
170 $this->headerList = [];
176 if ( $this->profiler ) {
177 $profileSection = $this->profiler->scopedProfileIn(
178 __METHOD__ .
'-' . $this->profileName
183 $this->fopenErrors = [];
184 set_error_handler( [ $this,
'errorHandler' ] );
186 restore_error_handler();
194 if ( isset(
$options[
'ssl'][
'CN_match'] )
195 && (
$options[
'ssl'][
'CN_match'] ===
'commons.wikimedia.org'
196 ||
$options[
'ssl'][
'CN_match'] ===
'upload.wikimedia.org' )
198 $options[
'ssl'][
'CN_match'] =
'en.wikipedia.org';
205 $result = stream_get_meta_data( $fh );
206 $this->headerList = $result[
'wrapper_data'];
209 if ( !$this->followRedirects ) {
213 # Handle manual redirection
214 if ( !$this->
isRedirect() || $reqCount > $this->maxRedirects ) {
217 # Check security of URL
220 if ( !Http::isValidURI(
$url ) ) {
221 $this->logger->debug( __METHOD__ .
": insecure redirection\n" );
225 if ( $this->profiler ) {
226 $this->profiler->scopedProfileOut( $profileSection );
231 if ( $fh ===
false ) {
232 if ( $this->fopenErrors ) {
233 $this->logger->warning( __CLASS__
234 .
': error opening connection: {errstr1}', $this->fopenErrors );
236 $this->status->fatal(
'http-request-error' );
237 return Status::wrap( $this->status );
240 if ( $result[
'timed_out'] ) {
241 $this->status->fatal(
'http-timed-out', $this->url );
242 return Status::wrap( $this->status );
247 if ( $this->status->isOK() || (
int)$this->respStatus >= 300 ) {
248 while ( !feof( $fh ) ) {
249 $buf = fread( $fh, 8192 );
251 if ( $buf ===
false ) {
252 $this->status->fatal(
'http-read-error' );
256 if ( strlen( $buf ) ) {
257 call_user_func( $this->callback, $fh, $buf );
263 return Status::wrap( $this->status );