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 $this->status->fatal(
'http-internal-error' );
102 throw new InvalidArgumentException(
"Error setting curl options." );
106 Wikimedia\suppressWarnings();
107 if ( !curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION,
true ) ) {
108 $this->logger->debug( __METHOD__ .
": Couldn't set CURLOPT_FOLLOWLOCATION. " .
109 "Probably open_basedir is set.\n" );
113 Wikimedia\restoreWarnings();
116 if ( $this->profiler ) {
117 $profileSection = $this->profiler->scopedProfileIn(
118 __METHOD__ .
'-' . $this->profileName
122 $curlRes = curl_exec( $curlHandle );
123 if ( curl_errno( $curlHandle ) == CURLE_OPERATION_TIMEOUTED ) {
124 $this->status->fatal(
'http-timed-out', $this->url );
125 } elseif ( $curlRes ===
false ) {
126 $this->status->fatal(
'http-curl-error', curl_error( $curlHandle ) );
128 $this->headerList = explode(
"\r\n", $this->headerText );
131 curl_close( $curlHandle );
133 if ( $this->profiler ) {
134 $this->profiler->scopedProfileOut( $profileSection );
140 return Status::wrap( $this->status );