49 if ( !$this->status->isOK() ) {
57 if ( defined(
'CURLOPT_CONNECTTIMEOUT_MS' ) ) {
58 $this->curlOptions[CURLOPT_CONNECTTIMEOUT_MS] = $this->connectTimeout * 1000;
61 $this->curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
63 $this->curlOptions[CURLOPT_HEADERFUNCTION] = [ $this,
"readHeader" ];
65 $this->curlOptions[CURLOPT_ENCODING] =
""; # Enable compression
67 $this->curlOptions[CURLOPT_USERAGENT] = $this->reqHeaders[
'User-Agent'];
69 $this->curlOptions[CURLOPT_SSL_VERIFYHOST] = $this->sslVerifyHost ? 2 : 0;
72 if ( $this->caInfo ) {
76 if ( $this->headersOnly ) {
77 $this->curlOptions[CURLOPT_NOBODY] =
true;
78 $this->curlOptions[CURLOPT_HEADER] =
true;
79 } elseif ( $this->method ==
'POST' ) {
80 $this->curlOptions[CURLOPT_POST] =
true;
87 if ( defined(
'CURLOPT_SAFE_UPLOAD' ) ) {
88 $this->curlOptions[CURLOPT_SAFE_UPLOAD] =
true;
95 $this->curlOptions[CURLOPT_POSTFIELDS] =
$postData;
100 $this->reqHeaders[
'Expect'] =
'';
105 $this->curlOptions[CURLOPT_HTTPHEADER] = $this->
getHeaderList();
107 $curlHandle = curl_init( $this->url );
109 if ( !curl_setopt_array( $curlHandle, $this->curlOptions ) ) {
110 throw new InvalidArgumentException(
"Error setting curl options." );
114 MediaWiki\suppressWarnings();
115 if ( !curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION,
true ) ) {
116 $this->logger->debug( __METHOD__ .
": Couldn't set CURLOPT_FOLLOWLOCATION. " .
117 "Probably open_basedir is set.\n" );
121 MediaWiki\restoreWarnings();
124 if ( $this->profiler ) {
125 $profileSection = $this->profiler->scopedProfileIn(
126 __METHOD__ .
'-' . $this->profileName
130 $curlRes = curl_exec( $curlHandle );
131 if ( curl_errno( $curlHandle ) == CURLE_OPERATION_TIMEOUTED ) {
132 $this->status->fatal(
'http-timed-out', $this->url );
133 } elseif ( $curlRes ===
false ) {
134 $this->status->fatal(
'http-curl-error', curl_error( $curlHandle ) );
136 $this->headerList = explode(
"\r\n", $this->headerText );
139 curl_close( $curlHandle );
141 if ( $this->profiler ) {
142 $this->profiler->scopedProfileOut( $profileSection );
155 $curlVersionInfo = curl_version();
156 if ( $curlVersionInfo[
'version_number'] < 0x071304 ) {
157 $this->logger->debug(
"Cannot follow redirects with libcurl < 7.19.4 due to CVE-2009-0037\n" );
161 if ( version_compare( PHP_VERSION,
'5.6.0',
'<' ) ) {
162 if ( strval( ini_get(
'open_basedir' ) ) !==
'' ) {
163 $this->logger->debug(
"Cannot follow redirects when open_basedir is set\n" );