Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../includes/Google/IO
File: Curl.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* Copyright 2014 Google Inc.
[2] Fix | Delete
*
[3] Fix | Delete
* Licensed under the Apache License, Version 2.0 (the "License");
[4] Fix | Delete
* you may not use this file except in compliance with the License.
[5] Fix | Delete
* You may obtain a copy of the License at
[6] Fix | Delete
*
[7] Fix | Delete
* http://www.apache.org/licenses/LICENSE-2.0
[8] Fix | Delete
*
[9] Fix | Delete
* Unless required by applicable law or agreed to in writing, software
[10] Fix | Delete
* distributed under the License is distributed on an "AS IS" BASIS,
[11] Fix | Delete
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
[12] Fix | Delete
* See the License for the specific language governing permissions and
[13] Fix | Delete
* limitations under the License.
[14] Fix | Delete
*/
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Curl based implementation of Google_IO.
[18] Fix | Delete
*
[19] Fix | Delete
* @author Stuart Langley <slangley@google.com>
[20] Fix | Delete
*/
[21] Fix | Delete
[22] Fix | Delete
if (!class_exists('UDP_Google_Client')) {
[23] Fix | Delete
require_once dirname(__FILE__) . '/../autoload.php';
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
class UDP_Google_IO_Curl extends UDP_Google_IO_Abstract
[27] Fix | Delete
{
[28] Fix | Delete
// cURL hex representation of version 7.30.0
[29] Fix | Delete
const NO_QUIRK_VERSION = 0x071E00;
[30] Fix | Delete
[31] Fix | Delete
private $options = array();
[32] Fix | Delete
[33] Fix | Delete
public function __construct(UDP_Google_Client $client)
[34] Fix | Delete
{
[35] Fix | Delete
if (!extension_loaded('curl')) {
[36] Fix | Delete
$error = 'The cURL IO handler requires the cURL extension to be enabled';
[37] Fix | Delete
$client->getLogger()->critical($error);
[38] Fix | Delete
throw new UDP_Google_IO_Exception($error);
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
parent::__construct($client);
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Execute an HTTP Request
[46] Fix | Delete
*
[47] Fix | Delete
* @param Google_Http_Request $request the http request to be executed
[48] Fix | Delete
* @return array containing response headers, body, and http code
[49] Fix | Delete
* @throws UDP_Google_IO_Exception on curl or IO error
[50] Fix | Delete
*/
[51] Fix | Delete
public function executeRequest(UDP_Google_Http_Request $request)
[52] Fix | Delete
{
[53] Fix | Delete
$curl = curl_init();
[54] Fix | Delete
[55] Fix | Delete
if ($request->getPostBody()) {
[56] Fix | Delete
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getPostBody());
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
$requestHeaders = $request->getRequestHeaders();
[60] Fix | Delete
if ($requestHeaders && is_array($requestHeaders)) {
[61] Fix | Delete
$curlHeaders = array();
[62] Fix | Delete
foreach ($requestHeaders as $k => $v) {
[63] Fix | Delete
$curlHeaders[] = "$k: $v";
[64] Fix | Delete
}
[65] Fix | Delete
curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeaders);
[66] Fix | Delete
}
[67] Fix | Delete
curl_setopt($curl, CURLOPT_URL, $request->getUrl());
[68] Fix | Delete
[69] Fix | Delete
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getRequestMethod());
[70] Fix | Delete
curl_setopt($curl, CURLOPT_USERAGENT, $request->getUserAgent());
[71] Fix | Delete
[72] Fix | Delete
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
[73] Fix | Delete
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
[74] Fix | Delete
// 1 is CURL_SSLVERSION_TLSv1, which is not always defined in PHP.
[75] Fix | Delete
// UpdraftPlus patch
[76] Fix | Delete
// The SDK leaves this on the default setting in later releases
[77] Fix | Delete
// curl_setopt($curl, CURLOPT_SSLVERSION, 1);
[78] Fix | Delete
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
[79] Fix | Delete
curl_setopt($curl, CURLOPT_HEADER, true);
[80] Fix | Delete
[81] Fix | Delete
if ($request->canGzip()) {
[82] Fix | Delete
curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
$options = $this->client->getClassConfig('UDP_Google_IO_Curl', 'options');
[86] Fix | Delete
if (is_array($options)) {
[87] Fix | Delete
$this->setOptions($options);
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
foreach ($this->options as $key => $var) {
[91] Fix | Delete
curl_setopt($curl, $key, $var);
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
if (!isset($this->options[CURLOPT_CAINFO])) {
[95] Fix | Delete
curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/cacerts.pem');
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
$this->client->getLogger()->debug(
[99] Fix | Delete
'cURL request',
[100] Fix | Delete
array(
[101] Fix | Delete
'url' => $request->getUrl(),
[102] Fix | Delete
'method' => $request->getRequestMethod(),
[103] Fix | Delete
'headers' => $requestHeaders,
[104] Fix | Delete
'body' => $request->getPostBody()
[105] Fix | Delete
)
[106] Fix | Delete
);
[107] Fix | Delete
[108] Fix | Delete
$response = curl_exec($curl);
[109] Fix | Delete
if ($response === false) {
[110] Fix | Delete
$error = curl_error($curl);
[111] Fix | Delete
$code = curl_errno($curl);
[112] Fix | Delete
$map = $this->client->getClassConfig('UDP_Google_IO_Exception', 'retry_map');
[113] Fix | Delete
[114] Fix | Delete
$this->client->getLogger()->error('cURL ' . $error);
[115] Fix | Delete
throw new UDP_Google_IO_Exception($error, $code, null, $map);
[116] Fix | Delete
}
[117] Fix | Delete
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
[118] Fix | Delete
[119] Fix | Delete
list($responseHeaders, $responseBody) = $this->parseHttpResponse($response, $headerSize);
[120] Fix | Delete
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
[121] Fix | Delete
[122] Fix | Delete
$this->client->getLogger()->debug(
[123] Fix | Delete
'cURL response',
[124] Fix | Delete
array(
[125] Fix | Delete
'code' => $responseCode,
[126] Fix | Delete
'headers' => $responseHeaders,
[127] Fix | Delete
'body' => $responseBody,
[128] Fix | Delete
)
[129] Fix | Delete
);
[130] Fix | Delete
[131] Fix | Delete
return array($responseBody, $responseHeaders, $responseCode);
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* Set options that update the transport implementation's behavior.
[136] Fix | Delete
* @param $options
[137] Fix | Delete
*/
[138] Fix | Delete
public function setOptions($options)
[139] Fix | Delete
{
[140] Fix | Delete
$this->options = $options + $this->options;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* Set the maximum request time in seconds.
[145] Fix | Delete
* @param $timeout in seconds
[146] Fix | Delete
*/
[147] Fix | Delete
public function setTimeout($timeout)
[148] Fix | Delete
{
[149] Fix | Delete
// Since this timeout is really for putting a bound on the time
[150] Fix | Delete
// we'll set them both to the same. If you need to specify a longer
[151] Fix | Delete
// CURLOPT_TIMEOUT, or a higher CONNECTTIMEOUT, the best thing to
[152] Fix | Delete
// do is use the setOptions method for the values individually.
[153] Fix | Delete
$this->options[CURLOPT_CONNECTTIMEOUT] = $timeout;
[154] Fix | Delete
$this->options[CURLOPT_TIMEOUT] = $timeout;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Get the maximum request time in seconds.
[159] Fix | Delete
* @return timeout in seconds
[160] Fix | Delete
*/
[161] Fix | Delete
public function getTimeout()
[162] Fix | Delete
{
[163] Fix | Delete
return $this->options[CURLOPT_TIMEOUT];
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Test for the presence of a cURL header processing bug
[168] Fix | Delete
*
[169] Fix | Delete
* {@inheritDoc}
[170] Fix | Delete
*
[171] Fix | Delete
* @return boolean
[172] Fix | Delete
*/
[173] Fix | Delete
protected function needsQuirk()
[174] Fix | Delete
{
[175] Fix | Delete
$ver = curl_version();
[176] Fix | Delete
$versionNum = $ver['version_number'];
[177] Fix | Delete
return $versionNum < UDP_Google_IO_Curl::NO_QUIRK_VERSION;
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function