Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../vendor/guzzleht.../guzzle/src/Handler
File: CurlFactory.php
<?php
[0] Fix | Delete
namespace GuzzleHttp\Handler;
[1] Fix | Delete
[2] Fix | Delete
use GuzzleHttp\Exception\ConnectException;
[3] Fix | Delete
use GuzzleHttp\Exception\RequestException;
[4] Fix | Delete
use GuzzleHttp\Promise\FulfilledPromise;
[5] Fix | Delete
use GuzzleHttp\Psr7;
[6] Fix | Delete
use GuzzleHttp\Psr7\LazyOpenStream;
[7] Fix | Delete
use GuzzleHttp\TransferStats;
[8] Fix | Delete
use Psr\Http\Message\RequestInterface;
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Creates curl resources from a request
[12] Fix | Delete
*/
[13] Fix | Delete
class CurlFactory implements CurlFactoryInterface
[14] Fix | Delete
{
[15] Fix | Delete
const CURL_VERSION_STR = 'curl_version';
[16] Fix | Delete
const LOW_CURL_VERSION_NUMBER = '7.21.2';
[17] Fix | Delete
[18] Fix | Delete
/** @var array */
[19] Fix | Delete
private $handles = [];
[20] Fix | Delete
[21] Fix | Delete
/** @var int Total number of idle handles to keep in cache */
[22] Fix | Delete
private $maxHandles;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* @param int $maxHandles Maximum number of idle handles.
[26] Fix | Delete
*/
[27] Fix | Delete
public function __construct($maxHandles)
[28] Fix | Delete
{
[29] Fix | Delete
$this->maxHandles = $maxHandles;
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
public function create(RequestInterface $request, array $options)
[33] Fix | Delete
{
[34] Fix | Delete
if (isset($options['curl']['body_as_string'])) {
[35] Fix | Delete
$options['_body_as_string'] = $options['curl']['body_as_string'];
[36] Fix | Delete
unset($options['curl']['body_as_string']);
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
$easy = new EasyHandle;
[40] Fix | Delete
$easy->request = $request;
[41] Fix | Delete
$easy->options = $options;
[42] Fix | Delete
$conf = $this->getDefaultConf($easy);
[43] Fix | Delete
$this->applyMethod($easy, $conf);
[44] Fix | Delete
$this->applyHandlerOptions($easy, $conf);
[45] Fix | Delete
$this->applyHeaders($easy, $conf);
[46] Fix | Delete
unset($conf['_headers']);
[47] Fix | Delete
[48] Fix | Delete
// Add handler options from the request configuration options
[49] Fix | Delete
if (isset($options['curl'])) {
[50] Fix | Delete
$conf = array_replace($conf, $options['curl']);
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
$conf[CURLOPT_HEADERFUNCTION] = $this->createHeaderFn($easy);
[54] Fix | Delete
$easy->handle = $this->handles
[55] Fix | Delete
? array_pop($this->handles)
[56] Fix | Delete
: curl_init();
[57] Fix | Delete
curl_setopt_array($easy->handle, $conf);
[58] Fix | Delete
[59] Fix | Delete
return $easy;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
public function release(EasyHandle $easy)
[63] Fix | Delete
{
[64] Fix | Delete
$resource = $easy->handle;
[65] Fix | Delete
unset($easy->handle);
[66] Fix | Delete
[67] Fix | Delete
if (count($this->handles) >= $this->maxHandles) {
[68] Fix | Delete
curl_close($resource);
[69] Fix | Delete
} else {
[70] Fix | Delete
// Remove all callback functions as they can hold onto references
[71] Fix | Delete
// and are not cleaned up by curl_reset. Using curl_setopt_array
[72] Fix | Delete
// does not work for some reason, so removing each one
[73] Fix | Delete
// individually.
[74] Fix | Delete
curl_setopt($resource, CURLOPT_HEADERFUNCTION, null);
[75] Fix | Delete
curl_setopt($resource, CURLOPT_READFUNCTION, null);
[76] Fix | Delete
curl_setopt($resource, CURLOPT_WRITEFUNCTION, null);
[77] Fix | Delete
curl_setopt($resource, CURLOPT_PROGRESSFUNCTION, null);
[78] Fix | Delete
curl_reset($resource);
[79] Fix | Delete
$this->handles[] = $resource;
[80] Fix | Delete
}
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Completes a cURL transaction, either returning a response promise or a
[85] Fix | Delete
* rejected promise.
[86] Fix | Delete
*
[87] Fix | Delete
* @param callable $handler
[88] Fix | Delete
* @param EasyHandle $easy
[89] Fix | Delete
* @param CurlFactoryInterface $factory Dictates how the handle is released
[90] Fix | Delete
*
[91] Fix | Delete
* @return \GuzzleHttp\Promise\PromiseInterface
[92] Fix | Delete
*/
[93] Fix | Delete
public static function finish(
[94] Fix | Delete
callable $handler,
[95] Fix | Delete
EasyHandle $easy,
[96] Fix | Delete
CurlFactoryInterface $factory
[97] Fix | Delete
) {
[98] Fix | Delete
if (isset($easy->options['on_stats'])) {
[99] Fix | Delete
self::invokeStats($easy);
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
if (!$easy->response || $easy->errno) {
[103] Fix | Delete
return self::finishError($handler, $easy, $factory);
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
// Return the response if it is present and there is no error.
[107] Fix | Delete
$factory->release($easy);
[108] Fix | Delete
[109] Fix | Delete
// Rewind the body of the response if possible.
[110] Fix | Delete
$body = $easy->response->getBody();
[111] Fix | Delete
if ($body->isSeekable()) {
[112] Fix | Delete
$body->rewind();
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
return new FulfilledPromise($easy->response);
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
private static function invokeStats(EasyHandle $easy)
[119] Fix | Delete
{
[120] Fix | Delete
$curlStats = curl_getinfo($easy->handle);
[121] Fix | Delete
$curlStats['appconnect_time'] = curl_getinfo($easy->handle, CURLINFO_APPCONNECT_TIME);
[122] Fix | Delete
$stats = new TransferStats(
[123] Fix | Delete
$easy->request,
[124] Fix | Delete
$easy->response,
[125] Fix | Delete
$curlStats['total_time'],
[126] Fix | Delete
$easy->errno,
[127] Fix | Delete
$curlStats
[128] Fix | Delete
);
[129] Fix | Delete
call_user_func($easy->options['on_stats'], $stats);
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
private static function finishError(
[133] Fix | Delete
callable $handler,
[134] Fix | Delete
EasyHandle $easy,
[135] Fix | Delete
CurlFactoryInterface $factory
[136] Fix | Delete
) {
[137] Fix | Delete
// Get error information and release the handle to the factory.
[138] Fix | Delete
$ctx = [
[139] Fix | Delete
'errno' => $easy->errno,
[140] Fix | Delete
'error' => curl_error($easy->handle),
[141] Fix | Delete
'appconnect_time' => curl_getinfo($easy->handle, CURLINFO_APPCONNECT_TIME),
[142] Fix | Delete
] + curl_getinfo($easy->handle);
[143] Fix | Delete
$ctx[self::CURL_VERSION_STR] = curl_version()['version'];
[144] Fix | Delete
$factory->release($easy);
[145] Fix | Delete
[146] Fix | Delete
// Retry when nothing is present or when curl failed to rewind.
[147] Fix | Delete
if (empty($easy->options['_err_message'])
[148] Fix | Delete
&& (!$easy->errno || $easy->errno == 65)
[149] Fix | Delete
) {
[150] Fix | Delete
return self::retryFailedRewind($handler, $easy, $ctx);
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
return self::createRejection($easy, $ctx);
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
private static function createRejection(EasyHandle $easy, array $ctx)
[157] Fix | Delete
{
[158] Fix | Delete
static $connectionErrors = [
[159] Fix | Delete
CURLE_OPERATION_TIMEOUTED => true,
[160] Fix | Delete
CURLE_COULDNT_RESOLVE_HOST => true,
[161] Fix | Delete
CURLE_COULDNT_CONNECT => true,
[162] Fix | Delete
CURLE_SSL_CONNECT_ERROR => true,
[163] Fix | Delete
CURLE_GOT_NOTHING => true,
[164] Fix | Delete
];
[165] Fix | Delete
[166] Fix | Delete
// If an exception was encountered during the onHeaders event, then
[167] Fix | Delete
// return a rejected promise that wraps that exception.
[168] Fix | Delete
if ($easy->onHeadersException) {
[169] Fix | Delete
return \GuzzleHttp\Promise\rejection_for(
[170] Fix | Delete
new RequestException(
[171] Fix | Delete
'An error was encountered during the on_headers event',
[172] Fix | Delete
$easy->request,
[173] Fix | Delete
$easy->response,
[174] Fix | Delete
$easy->onHeadersException,
[175] Fix | Delete
$ctx
[176] Fix | Delete
)
[177] Fix | Delete
);
[178] Fix | Delete
}
[179] Fix | Delete
if (version_compare($ctx[self::CURL_VERSION_STR], self::LOW_CURL_VERSION_NUMBER)) {
[180] Fix | Delete
$message = sprintf(
[181] Fix | Delete
'cURL error %s: %s (%s)',
[182] Fix | Delete
$ctx['errno'],
[183] Fix | Delete
$ctx['error'],
[184] Fix | Delete
'see https://curl.haxx.se/libcurl/c/libcurl-errors.html'
[185] Fix | Delete
);
[186] Fix | Delete
} else {
[187] Fix | Delete
$message = sprintf(
[188] Fix | Delete
'cURL error %s: %s (%s) for %s',
[189] Fix | Delete
$ctx['errno'],
[190] Fix | Delete
$ctx['error'],
[191] Fix | Delete
'see https://curl.haxx.se/libcurl/c/libcurl-errors.html',
[192] Fix | Delete
$easy->request->getUri()
[193] Fix | Delete
);
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
// Create a connection exception if it was a specific error code.
[197] Fix | Delete
$error = isset($connectionErrors[$easy->errno])
[198] Fix | Delete
? new ConnectException($message, $easy->request, null, $ctx)
[199] Fix | Delete
: new RequestException($message, $easy->request, $easy->response, null, $ctx);
[200] Fix | Delete
[201] Fix | Delete
return \GuzzleHttp\Promise\rejection_for($error);
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
private function getDefaultConf(EasyHandle $easy)
[205] Fix | Delete
{
[206] Fix | Delete
$conf = [
[207] Fix | Delete
'_headers' => $easy->request->getHeaders(),
[208] Fix | Delete
CURLOPT_CUSTOMREQUEST => $easy->request->getMethod(),
[209] Fix | Delete
CURLOPT_URL => (string) $easy->request->getUri()->withFragment(''),
[210] Fix | Delete
CURLOPT_RETURNTRANSFER => false,
[211] Fix | Delete
CURLOPT_HEADER => false,
[212] Fix | Delete
CURLOPT_CONNECTTIMEOUT => 150,
[213] Fix | Delete
];
[214] Fix | Delete
[215] Fix | Delete
if (defined('CURLOPT_PROTOCOLS')) {
[216] Fix | Delete
$conf[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
$version = $easy->request->getProtocolVersion();
[220] Fix | Delete
if ($version == 1.1) {
[221] Fix | Delete
$conf[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
[222] Fix | Delete
} elseif ($version == 2.0) {
[223] Fix | Delete
$conf[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2_0;
[224] Fix | Delete
} else {
[225] Fix | Delete
$conf[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
return $conf;
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
private function applyMethod(EasyHandle $easy, array &$conf)
[232] Fix | Delete
{
[233] Fix | Delete
$body = $easy->request->getBody();
[234] Fix | Delete
$size = $body->getSize();
[235] Fix | Delete
[236] Fix | Delete
if ($size === null || $size > 0) {
[237] Fix | Delete
$this->applyBody($easy->request, $easy->options, $conf);
[238] Fix | Delete
return;
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
$method = $easy->request->getMethod();
[242] Fix | Delete
if ($method === 'PUT' || $method === 'POST') {
[243] Fix | Delete
// See http://tools.ietf.org/html/rfc7230#section-3.3.2
[244] Fix | Delete
if (!$easy->request->hasHeader('Content-Length')) {
[245] Fix | Delete
$conf[CURLOPT_HTTPHEADER][] = 'Content-Length: 0';
[246] Fix | Delete
}
[247] Fix | Delete
} elseif ($method === 'HEAD') {
[248] Fix | Delete
$conf[CURLOPT_NOBODY] = true;
[249] Fix | Delete
unset(
[250] Fix | Delete
$conf[CURLOPT_WRITEFUNCTION],
[251] Fix | Delete
$conf[CURLOPT_READFUNCTION],
[252] Fix | Delete
$conf[CURLOPT_FILE],
[253] Fix | Delete
$conf[CURLOPT_INFILE]
[254] Fix | Delete
);
[255] Fix | Delete
}
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
private function applyBody(RequestInterface $request, array $options, array &$conf)
[259] Fix | Delete
{
[260] Fix | Delete
$size = $request->hasHeader('Content-Length')
[261] Fix | Delete
? (int) $request->getHeaderLine('Content-Length')
[262] Fix | Delete
: null;
[263] Fix | Delete
[264] Fix | Delete
// Send the body as a string if the size is less than 1MB OR if the
[265] Fix | Delete
// [curl][body_as_string] request value is set.
[266] Fix | Delete
if (($size !== null && $size < 1000000) ||
[267] Fix | Delete
!empty($options['_body_as_string'])
[268] Fix | Delete
) {
[269] Fix | Delete
$conf[CURLOPT_POSTFIELDS] = (string) $request->getBody();
[270] Fix | Delete
// Don't duplicate the Content-Length header
[271] Fix | Delete
$this->removeHeader('Content-Length', $conf);
[272] Fix | Delete
$this->removeHeader('Transfer-Encoding', $conf);
[273] Fix | Delete
} else {
[274] Fix | Delete
$conf[CURLOPT_UPLOAD] = true;
[275] Fix | Delete
if ($size !== null) {
[276] Fix | Delete
$conf[CURLOPT_INFILESIZE] = $size;
[277] Fix | Delete
$this->removeHeader('Content-Length', $conf);
[278] Fix | Delete
}
[279] Fix | Delete
$body = $request->getBody();
[280] Fix | Delete
if ($body->isSeekable()) {
[281] Fix | Delete
$body->rewind();
[282] Fix | Delete
}
[283] Fix | Delete
$conf[CURLOPT_READFUNCTION] = function ($ch, $fd, $length) use ($body) {
[284] Fix | Delete
return $body->read($length);
[285] Fix | Delete
};
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
// If the Expect header is not present, prevent curl from adding it
[289] Fix | Delete
if (!$request->hasHeader('Expect')) {
[290] Fix | Delete
$conf[CURLOPT_HTTPHEADER][] = 'Expect:';
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
// cURL sometimes adds a content-type by default. Prevent this.
[294] Fix | Delete
if (!$request->hasHeader('Content-Type')) {
[295] Fix | Delete
$conf[CURLOPT_HTTPHEADER][] = 'Content-Type:';
[296] Fix | Delete
}
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
private function applyHeaders(EasyHandle $easy, array &$conf)
[300] Fix | Delete
{
[301] Fix | Delete
foreach ($conf['_headers'] as $name => $values) {
[302] Fix | Delete
foreach ($values as $value) {
[303] Fix | Delete
$value = (string) $value;
[304] Fix | Delete
if ($value === '') {
[305] Fix | Delete
// cURL requires a special format for empty headers.
[306] Fix | Delete
// See https://github.com/guzzle/guzzle/issues/1882 for more details.
[307] Fix | Delete
$conf[CURLOPT_HTTPHEADER][] = "$name;";
[308] Fix | Delete
} else {
[309] Fix | Delete
$conf[CURLOPT_HTTPHEADER][] = "$name: $value";
[310] Fix | Delete
}
[311] Fix | Delete
}
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
// Remove the Accept header if one was not set
[315] Fix | Delete
if (!$easy->request->hasHeader('Accept')) {
[316] Fix | Delete
$conf[CURLOPT_HTTPHEADER][] = 'Accept:';
[317] Fix | Delete
}
[318] Fix | Delete
}
[319] Fix | Delete
[320] Fix | Delete
/**
[321] Fix | Delete
* Remove a header from the options array.
[322] Fix | Delete
*
[323] Fix | Delete
* @param string $name Case-insensitive header to remove
[324] Fix | Delete
* @param array $options Array of options to modify
[325] Fix | Delete
*/
[326] Fix | Delete
private function removeHeader($name, array &$options)
[327] Fix | Delete
{
[328] Fix | Delete
foreach (array_keys($options['_headers']) as $key) {
[329] Fix | Delete
if (!strcasecmp($key, $name)) {
[330] Fix | Delete
unset($options['_headers'][$key]);
[331] Fix | Delete
return;
[332] Fix | Delete
}
[333] Fix | Delete
}
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
private function applyHandlerOptions(EasyHandle $easy, array &$conf)
[337] Fix | Delete
{
[338] Fix | Delete
$options = $easy->options;
[339] Fix | Delete
if (isset($options['verify'])) {
[340] Fix | Delete
if ($options['verify'] === false) {
[341] Fix | Delete
unset($conf[CURLOPT_CAINFO]);
[342] Fix | Delete
$conf[CURLOPT_SSL_VERIFYHOST] = 0;
[343] Fix | Delete
$conf[CURLOPT_SSL_VERIFYPEER] = false;
[344] Fix | Delete
} else {
[345] Fix | Delete
$conf[CURLOPT_SSL_VERIFYHOST] = 2;
[346] Fix | Delete
$conf[CURLOPT_SSL_VERIFYPEER] = true;
[347] Fix | Delete
if (is_string($options['verify'])) {
[348] Fix | Delete
// Throw an error if the file/folder/link path is not valid or doesn't exist.
[349] Fix | Delete
if (!file_exists($options['verify'])) {
[350] Fix | Delete
throw new \InvalidArgumentException(
[351] Fix | Delete
"SSL CA bundle not found: {$options['verify']}"
[352] Fix | Delete
);
[353] Fix | Delete
}
[354] Fix | Delete
// If it's a directory or a link to a directory use CURLOPT_CAPATH.
[355] Fix | Delete
// If not, it's probably a file, or a link to a file, so use CURLOPT_CAINFO.
[356] Fix | Delete
if (is_dir($options['verify']) ||
[357] Fix | Delete
(is_link($options['verify']) && is_dir(readlink($options['verify'])))) {
[358] Fix | Delete
$conf[CURLOPT_CAPATH] = $options['verify'];
[359] Fix | Delete
} else {
[360] Fix | Delete
$conf[CURLOPT_CAINFO] = $options['verify'];
[361] Fix | Delete
}
[362] Fix | Delete
}
[363] Fix | Delete
}
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
if (!empty($options['decode_content'])) {
[367] Fix | Delete
$accept = $easy->request->getHeaderLine('Accept-Encoding');
[368] Fix | Delete
if ($accept) {
[369] Fix | Delete
$conf[CURLOPT_ENCODING] = $accept;
[370] Fix | Delete
} else {
[371] Fix | Delete
$conf[CURLOPT_ENCODING] = '';
[372] Fix | Delete
// Don't let curl send the header over the wire
[373] Fix | Delete
$conf[CURLOPT_HTTPHEADER][] = 'Accept-Encoding:';
[374] Fix | Delete
}
[375] Fix | Delete
}
[376] Fix | Delete
[377] Fix | Delete
if (isset($options['sink'])) {
[378] Fix | Delete
$sink = $options['sink'];
[379] Fix | Delete
if (!is_string($sink)) {
[380] Fix | Delete
$sink = \GuzzleHttp\Psr7\stream_for($sink);
[381] Fix | Delete
} elseif (!is_dir(dirname($sink))) {
[382] Fix | Delete
// Ensure that the directory exists before failing in curl.
[383] Fix | Delete
throw new \RuntimeException(sprintf(
[384] Fix | Delete
'Directory %s does not exist for sink value of %s',
[385] Fix | Delete
dirname($sink),
[386] Fix | Delete
$sink
[387] Fix | Delete
));
[388] Fix | Delete
} else {
[389] Fix | Delete
$sink = new LazyOpenStream($sink, 'w+');
[390] Fix | Delete
}
[391] Fix | Delete
$easy->sink = $sink;
[392] Fix | Delete
$conf[CURLOPT_WRITEFUNCTION] = function ($ch, $write) use ($sink) {
[393] Fix | Delete
return $sink->write($write);
[394] Fix | Delete
};
[395] Fix | Delete
} else {
[396] Fix | Delete
// Use a default temp stream if no sink was set.
[397] Fix | Delete
$conf[CURLOPT_FILE] = fopen('php://temp', 'w+');
[398] Fix | Delete
$easy->sink = Psr7\stream_for($conf[CURLOPT_FILE]);
[399] Fix | Delete
}
[400] Fix | Delete
$timeoutRequiresNoSignal = false;
[401] Fix | Delete
if (isset($options['timeout'])) {
[402] Fix | Delete
$timeoutRequiresNoSignal |= $options['timeout'] < 1;
[403] Fix | Delete
$conf[CURLOPT_TIMEOUT_MS] = $options['timeout'] * 1000;
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
// CURL default value is CURL_IPRESOLVE_WHATEVER
[407] Fix | Delete
if (isset($options['force_ip_resolve'])) {
[408] Fix | Delete
if ('v4' === $options['force_ip_resolve']) {
[409] Fix | Delete
$conf[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
[410] Fix | Delete
} elseif ('v6' === $options['force_ip_resolve']) {
[411] Fix | Delete
$conf[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V6;
[412] Fix | Delete
}
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
if (isset($options['connect_timeout'])) {
[416] Fix | Delete
$timeoutRequiresNoSignal |= $options['connect_timeout'] < 1;
[417] Fix | Delete
$conf[CURLOPT_CONNECTTIMEOUT_MS] = $options['connect_timeout'] * 1000;
[418] Fix | Delete
}
[419] Fix | Delete
[420] Fix | Delete
if ($timeoutRequiresNoSignal && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
[421] Fix | Delete
$conf[CURLOPT_NOSIGNAL] = true;
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
if (isset($options['proxy'])) {
[425] Fix | Delete
if (!is_array($options['proxy'])) {
[426] Fix | Delete
$conf[CURLOPT_PROXY] = $options['proxy'];
[427] Fix | Delete
} else {
[428] Fix | Delete
$scheme = $easy->request->getUri()->getScheme();
[429] Fix | Delete
if (isset($options['proxy'][$scheme])) {
[430] Fix | Delete
$host = $easy->request->getUri()->getHost();
[431] Fix | Delete
if (!isset($options['proxy']['no']) ||
[432] Fix | Delete
!\GuzzleHttp\is_host_in_noproxy($host, $options['proxy']['no'])
[433] Fix | Delete
) {
[434] Fix | Delete
$conf[CURLOPT_PROXY] = $options['proxy'][$scheme];
[435] Fix | Delete
}
[436] Fix | Delete
}
[437] Fix | Delete
}
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
if (isset($options['cert'])) {
[441] Fix | Delete
$cert = $options['cert'];
[442] Fix | Delete
if (is_array($cert)) {
[443] Fix | Delete
$conf[CURLOPT_SSLCERTPASSWD] = $cert[1];
[444] Fix | Delete
$cert = $cert[0];
[445] Fix | Delete
}
[446] Fix | Delete
if (!file_exists($cert)) {
[447] Fix | Delete
throw new \InvalidArgumentException(
[448] Fix | Delete
"SSL certificate not found: {$cert}"
[449] Fix | Delete
);
[450] Fix | Delete
}
[451] Fix | Delete
$conf[CURLOPT_SSLCERT] = $cert;
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
if (isset($options['ssl_key'])) {
[455] Fix | Delete
if (is_array($options['ssl_key'])) {
[456] Fix | Delete
if (count($options['ssl_key']) === 2) {
[457] Fix | Delete
list($sslKey, $conf[CURLOPT_SSLKEYPASSWD]) = $options['ssl_key'];
[458] Fix | Delete
} else {
[459] Fix | Delete
list($sslKey) = $options['ssl_key'];
[460] Fix | Delete
}
[461] Fix | Delete
}
[462] Fix | Delete
[463] Fix | Delete
$sslKey = isset($sslKey) ? $sslKey: $options['ssl_key'];
[464] Fix | Delete
[465] Fix | Delete
if (!file_exists($sslKey)) {
[466] Fix | Delete
throw new \InvalidArgumentException(
[467] Fix | Delete
"SSL private key not found: {$sslKey}"
[468] Fix | Delete
);
[469] Fix | Delete
}
[470] Fix | Delete
$conf[CURLOPT_SSLKEY] = $sslKey;
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
if (isset($options['progress'])) {
[474] Fix | Delete
$progress = $options['progress'];
[475] Fix | Delete
if (!is_callable($progress)) {
[476] Fix | Delete
throw new \InvalidArgumentException(
[477] Fix | Delete
'progress client option must be callable'
[478] Fix | Delete
);
[479] Fix | Delete
}
[480] Fix | Delete
$conf[CURLOPT_NOPROGRESS] = false;
[481] Fix | Delete
$conf[CURLOPT_PROGRESSFUNCTION] = function () use ($progress) {
[482] Fix | Delete
$args = func_get_args();
[483] Fix | Delete
// PHP 5.5 pushed the handle onto the start of the args
[484] Fix | Delete
if (is_resource($args[0])) {
[485] Fix | Delete
array_shift($args);
[486] Fix | Delete
}
[487] Fix | Delete
call_user_func_array($progress, $args);
[488] Fix | Delete
};
[489] Fix | Delete
}
[490] Fix | Delete
[491] Fix | Delete
if (!empty($options['debug'])) {
[492] Fix | Delete
$conf[CURLOPT_STDERR] = \GuzzleHttp\debug_resource($options['debug']);
[493] Fix | Delete
$conf[CURLOPT_VERBOSE] = true;
[494] Fix | Delete
}
[495] Fix | Delete
}
[496] Fix | Delete
[497] Fix | Delete
/**
[498] Fix | Delete
* This function ensures that a response was set on a transaction. If one
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function