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;
55 $this->curlOptions[CURLOPT_CONNECTTIMEOUT_MS] = $this->connectTimeout * 1000;
56 $this->curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
57 $this->curlOptions[CURLOPT_WRITEFUNCTION] = $this->callback;
58 $this->curlOptions[CURLOPT_HEADERFUNCTION] = [ $this,
"readHeader" ];
59 $this->curlOptions[CURLOPT_MAXREDIRS] = $this->maxRedirects;
60 $this->curlOptions[CURLOPT_ENCODING] =
""; # Enable compression
62 $this->curlOptions[CURLOPT_USERAGENT] = $this->reqHeaders[
'User-Agent'];
64 $this->curlOptions[CURLOPT_SSL_VERIFYHOST] = $this->sslVerifyHost ? 2 : 0;
65 $this->curlOptions[CURLOPT_SSL_VERIFYPEER] = $this->sslVerifyCert;
67 if ( $this->caInfo ) {
68 $this->curlOptions[CURLOPT_CAINFO] = $this->caInfo;
71 if ( $this->headersOnly ) {
72 $this->curlOptions[CURLOPT_NOBODY] =
true;
73 $this->curlOptions[CURLOPT_HEADER] =
true;
74 } elseif ( $this->method ==
'POST' ) {
75 $this->curlOptions[CURLOPT_POST] =
true;
80 $this->curlOptions[CURLOPT_SAFE_UPLOAD] =
true;
81 $this->curlOptions[CURLOPT_POSTFIELDS] =
$postData;
86 $this->reqHeaders[
'Expect'] =
'';
88 $this->curlOptions[CURLOPT_CUSTOMREQUEST] = $this->method;
91 $this->curlOptions[CURLOPT_HTTPHEADER] = $this->
getHeaderList();
93 $curlHandle = curl_init( $this->url );
95 if ( !curl_setopt_array( $curlHandle, $this->curlOptions ) ) {
96 $this->status->fatal(
'http-internal-error' );
97 throw new InvalidArgumentException(
"Error setting curl options." );
101 Wikimedia\suppressWarnings();
102 if ( !curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION,
true ) ) {
103 $this->logger->debug( __METHOD__ .
": Couldn't set CURLOPT_FOLLOWLOCATION. " .
104 "Probably open_basedir is set.\n" );
108 Wikimedia\restoreWarnings();
111 if ( $this->profiler ) {
112 $profileSection = $this->profiler->scopedProfileIn(
113 __METHOD__ .
'-' . $this->profileName
117 $curlRes = curl_exec( $curlHandle );
118 if ( curl_errno( $curlHandle ) == CURLE_OPERATION_TIMEOUTED ) {
119 $this->status->fatal(
'http-timed-out', $this->url );
120 } elseif ( $curlRes ===
false ) {
121 $this->status->fatal(
'http-curl-error', curl_error( $curlHandle ) );
123 $this->headerList = explode(
"\r\n", $this->headerText );
126 curl_close( $curlHandle );
128 if ( $this->profiler ) {
129 $this->profiler->scopedProfileOut( $profileSection );
135 return Status::wrap( $this->status );