61 if ( !$this->status->isOK() ) {
62 return Status::wrap( $this->status );
65 $this->curlOptions[CURLOPT_PROXY] = $this->proxy;
66 $this->curlOptions[CURLOPT_TIMEOUT] = $this->timeout;
67 $this->curlOptions[CURLOPT_CONNECTTIMEOUT_MS] = $this->connectTimeout * 1000;
68 $this->curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
69 $this->curlOptions[CURLOPT_WRITEFUNCTION] = $this->callback;
70 $this->curlOptions[CURLOPT_HEADERFUNCTION] = [ $this,
"readHeader" ];
71 $this->curlOptions[CURLOPT_MAXREDIRS] = $this->maxRedirects;
72 $this->curlOptions[CURLOPT_ENCODING] =
""; # Enable compression
74 $this->curlOptions[CURLOPT_USERAGENT] = $this->reqHeaders[
'User-Agent'];
76 $this->curlOptions[CURLOPT_SSL_VERIFYHOST] = $this->sslVerifyHost ? 2 : 0;
77 $this->curlOptions[CURLOPT_SSL_VERIFYPEER] = $this->sslVerifyCert;
79 if ( $this->caInfo ) {
80 $this->curlOptions[CURLOPT_CAINFO] = $this->caInfo;
83 if ( $this->headersOnly ) {
84 $this->curlOptions[CURLOPT_NOBODY] =
true;
85 $this->curlOptions[CURLOPT_HEADER] =
true;
86 } elseif ( $this->method ==
'POST' ) {
87 $this->curlOptions[CURLOPT_POST] =
true;
92 $this->curlOptions[CURLOPT_SAFE_UPLOAD] =
true;
93 $this->curlOptions[CURLOPT_POSTFIELDS] =
$postData;
98 $this->reqHeaders[
'Expect'] =
'';
100 $this->curlOptions[CURLOPT_CUSTOMREQUEST] = $this->method;
103 $this->curlOptions[CURLOPT_HTTPHEADER] = $this->
getHeaderList();
105 $curlHandle = curl_init( $this->url );
107 if ( !curl_setopt_array( $curlHandle, $this->curlOptions ) ) {
108 $this->status->fatal(
'http-internal-error' );
109 throw new InvalidArgumentException(
"Error setting curl options." );
113 Wikimedia\suppressWarnings();
114 if ( !curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION,
true ) ) {
115 $this->logger->debug( __METHOD__ .
": Couldn't set CURLOPT_FOLLOWLOCATION. " .
116 "Probably open_basedir is set.\n" );
120 Wikimedia\restoreWarnings();
123 if ( $this->profiler ) {
124 $profileSection = $this->profiler->scopedProfileIn(
125 __METHOD__ .
'-' . $this->profileName
129 $curlRes = curl_exec( $curlHandle );
130 if ( curl_errno( $curlHandle ) == CURLE_OPERATION_TIMEOUTED ) {
131 $this->status->fatal(
'http-timed-out', $this->url );
132 } elseif ( $curlRes ===
false ) {
133 $this->status->fatal(
'http-curl-error', curl_error( $curlHandle ) );
135 $this->headerList = explode(
"\r\n", $this->headerText );
138 curl_close( $curlHandle );
140 if ( $this->profiler ) {
141 $this->profiler->scopedProfileOut( $profileSection );
147 return Status::wrap( $this->status );