49 if ( !$this->status->isOK() ) {
50 return Status::wrap( $this->status );
53 $this->curlOptions[CURLOPT_PROXY] = $this->proxy;
54 $this->curlOptions[CURLOPT_TIMEOUT] = $this->timeout;
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;
62 $this->curlOptions[CURLOPT_WRITEFUNCTION] = $this->callback;
63 $this->curlOptions[CURLOPT_HEADERFUNCTION] = [ $this,
"readHeader" ];
64 $this->curlOptions[CURLOPT_MAXREDIRS] = $this->maxRedirects;
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;
70 $this->curlOptions[CURLOPT_SSL_VERIFYPEER] = $this->sslVerifyCert;
72 if ( $this->caInfo ) {
73 $this->curlOptions[CURLOPT_CAINFO] = $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;
85 $this->curlOptions[CURLOPT_SAFE_UPLOAD] =
true;
86 $this->curlOptions[CURLOPT_POSTFIELDS] =
$postData;
91 $this->reqHeaders[
'Expect'] =
'';
93 $this->curlOptions[CURLOPT_CUSTOMREQUEST] = $this->method;
96 $this->curlOptions[CURLOPT_HTTPHEADER] = $this->
getHeaderList();
98 $curlHandle = curl_init( $this->url );
100 if ( !curl_setopt_array( $curlHandle, $this->curlOptions ) ) {
101 throw new InvalidArgumentException(
"Error setting curl options." );
105 Wikimedia\suppressWarnings();
106 if ( !curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION,
true ) ) {
107 $this->logger->debug( __METHOD__ .
": Couldn't set CURLOPT_FOLLOWLOCATION. " .
108 "Probably open_basedir is set.\n" );
112 Wikimedia\restoreWarnings();
115 if ( $this->profiler ) {
116 $profileSection = $this->profiler->scopedProfileIn(
117 __METHOD__ .
'-' . $this->profileName
121 $curlRes = curl_exec( $curlHandle );
122 if ( curl_errno( $curlHandle ) == CURLE_OPERATION_TIMEOUTED ) {
123 $this->status->fatal(
'http-timed-out', $this->url );
124 } elseif ( $curlRes ===
false ) {
125 $this->status->fatal(
'http-curl-error', curl_error( $curlHandle ) );
127 $this->headerList = explode(
"\r\n", $this->headerText );
130 curl_close( $curlHandle );
132 if ( $this->profiler ) {
133 $this->profiler->scopedProfileOut( $profileSection );
139 return Status::wrap( $this->status );