62 if ( !$this->status->isOK() ) {
63 return Status::wrap( $this->status );
66 $this->curlOptions[CURLOPT_PROXY] = $this->proxy;
67 $this->curlOptions[CURLOPT_TIMEOUT] = $this->timeout;
68 $this->curlOptions[CURLOPT_CONNECTTIMEOUT_MS] = $this->connectTimeout * 1000;
69 $this->curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
70 $this->curlOptions[CURLOPT_WRITEFUNCTION] = $this->callback;
71 $this->curlOptions[CURLOPT_HEADERFUNCTION] = [ $this,
"readHeader" ];
72 $this->curlOptions[CURLOPT_MAXREDIRS] = $this->maxRedirects;
73 $this->curlOptions[CURLOPT_ENCODING] =
""; # Enable compression
75 $this->curlOptions[CURLOPT_USERAGENT] = $this->reqHeaders[
'User-Agent'];
77 $this->curlOptions[CURLOPT_SSL_VERIFYHOST] = $this->sslVerifyHost ? 2 : 0;
78 $this->curlOptions[CURLOPT_SSL_VERIFYPEER] = $this->sslVerifyCert;
80 if ( $this->caInfo ) {
81 $this->curlOptions[CURLOPT_CAINFO] = $this->caInfo;
84 if ( $this->headersOnly ) {
85 $this->curlOptions[CURLOPT_NOBODY] =
true;
86 $this->curlOptions[CURLOPT_HEADER] =
true;
87 } elseif ( $this->method ==
'POST' ) {
88 $this->curlOptions[CURLOPT_POST] =
true;
93 $this->curlOptions[CURLOPT_SAFE_UPLOAD] =
true;
94 $this->curlOptions[CURLOPT_POSTFIELDS] =
$postData;
99 $this->reqHeaders[
'Expect'] =
'';
101 $this->curlOptions[CURLOPT_CUSTOMREQUEST] = $this->method;
104 $this->curlOptions[CURLOPT_HTTPHEADER] = $this->
getHeaderList();
106 $curlHandle = curl_init( $this->url );
108 if ( !curl_setopt_array( $curlHandle, $this->curlOptions ) ) {
109 $this->status->fatal(
'http-internal-error' );
110 throw new InvalidArgumentException(
"Error setting curl options." );
114 Wikimedia\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." );
121 Wikimedia\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 );
148 return Status::wrap( $this->status );