mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-30 16:49:58 +09:00
Update composer dependencies
This commit is contained in:
parent
49cc39e507
commit
cbd324c35b
428 changed files with 17862 additions and 5885 deletions
313
vendor/rmccue/requests/library/Requests/Transport/cURL.php
vendored
Executable file → Normal file
313
vendor/rmccue/requests/library/Requests/Transport/cURL.php
vendored
Executable file → Normal file
|
|
@ -13,6 +13,9 @@
|
|||
* @subpackage Transport
|
||||
*/
|
||||
class Requests_Transport_cURL implements Requests_Transport {
|
||||
const CURL_7_10_5 = 0x070A05;
|
||||
const CURL_7_16_2 = 0x071002;
|
||||
|
||||
/**
|
||||
* Raw HTTP data
|
||||
*
|
||||
|
|
@ -20,17 +23,24 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
*/
|
||||
public $headers = '';
|
||||
|
||||
/**
|
||||
* Raw body data
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $response_data = '';
|
||||
|
||||
/**
|
||||
* Information on the current request
|
||||
*
|
||||
* @var array cURL information array, see {@see http://php.net/curl_getinfo}
|
||||
* @var array cURL information array, see {@see https://secure.php.net/curl_getinfo}
|
||||
*/
|
||||
public $info;
|
||||
|
||||
/**
|
||||
* Version string
|
||||
*
|
||||
* @var string
|
||||
* @var long
|
||||
*/
|
||||
public $version;
|
||||
|
||||
|
|
@ -39,7 +49,14 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $fp;
|
||||
protected $handle;
|
||||
|
||||
/**
|
||||
* Hook dispatcher instance
|
||||
*
|
||||
* @var Requests_Hooks
|
||||
*/
|
||||
protected $hooks;
|
||||
|
||||
/**
|
||||
* Have we finished the headers yet?
|
||||
|
|
@ -55,24 +72,47 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
*/
|
||||
protected $stream_handle;
|
||||
|
||||
/**
|
||||
* How many bytes are in the response body?
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $response_bytes;
|
||||
|
||||
/**
|
||||
* What's the maximum number of bytes we should keep?
|
||||
*
|
||||
* @var int|bool Byte count, or false if no limit.
|
||||
*/
|
||||
protected $response_byte_limit;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$curl = curl_version();
|
||||
$this->version = $curl['version'];
|
||||
$this->fp = curl_init();
|
||||
$this->version = $curl['version_number'];
|
||||
$this->handle = curl_init();
|
||||
|
||||
curl_setopt($this->fp, CURLOPT_HEADER, false);
|
||||
curl_setopt($this->fp, CURLOPT_RETURNTRANSFER, 1);
|
||||
if (version_compare($this->version, '7.10.5', '>=')) {
|
||||
curl_setopt($this->fp, CURLOPT_ENCODING, '');
|
||||
curl_setopt($this->handle, CURLOPT_HEADER, false);
|
||||
curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, 1);
|
||||
if ($this->version >= self::CURL_7_10_5) {
|
||||
curl_setopt($this->handle, CURLOPT_ENCODING, '');
|
||||
}
|
||||
if (defined('CURLOPT_PROTOCOLS')) {
|
||||
curl_setopt($this->fp, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
curl_setopt($this->handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
}
|
||||
if (defined('CURLOPT_REDIR_PROTOCOLS')) {
|
||||
curl_setopt($this->fp, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
curl_setopt($this->handle, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
public function __destruct() {
|
||||
if (is_resource($this->handle)) {
|
||||
curl_close($this->handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,40 +128,59 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
* @return string Raw HTTP result
|
||||
*/
|
||||
public function request($url, $headers = array(), $data = array(), $options = array()) {
|
||||
$this->hooks = $options['hooks'];
|
||||
|
||||
$this->setup_handle($url, $headers, $data, $options);
|
||||
|
||||
$options['hooks']->dispatch('curl.before_send', array(&$this->fp));
|
||||
$options['hooks']->dispatch('curl.before_send', array(&$this->handle));
|
||||
|
||||
if ($options['filename'] !== false) {
|
||||
$this->stream_handle = fopen($options['filename'], 'wb');
|
||||
curl_setopt($this->fp, CURLOPT_FILE, $this->stream_handle);
|
||||
}
|
||||
|
||||
$this->response_data = '';
|
||||
$this->response_bytes = 0;
|
||||
$this->response_byte_limit = false;
|
||||
if ($options['max_bytes'] !== false) {
|
||||
$this->response_byte_limit = $options['max_bytes'];
|
||||
}
|
||||
|
||||
if (isset($options['verify'])) {
|
||||
if ($options['verify'] === false) {
|
||||
curl_setopt($this->fp, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($this->fp, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
|
||||
} elseif (is_string($options['verify'])) {
|
||||
curl_setopt($this->fp, CURLOPT_CAINFO, $options['verify']);
|
||||
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
}
|
||||
elseif (is_string($options['verify'])) {
|
||||
curl_setopt($this->handle, CURLOPT_CAINFO, $options['verify']);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['verifyname']) && $options['verifyname'] === false) {
|
||||
curl_setopt($this->fp, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
}
|
||||
|
||||
$response = curl_exec($this->fp);
|
||||
curl_exec($this->handle);
|
||||
$response = $this->response_data;
|
||||
|
||||
$options['hooks']->dispatch('curl.after_send', array(&$fake_headers));
|
||||
$options['hooks']->dispatch('curl.after_send', array());
|
||||
|
||||
if (curl_errno($this->fp) === 23 || curl_errno($this->fp) === 61) {
|
||||
curl_setopt($this->fp, CURLOPT_ENCODING, 'none');
|
||||
$response = curl_exec($this->fp);
|
||||
if (curl_errno($this->handle) === 23 || curl_errno($this->handle) === 61) {
|
||||
// Reset encoding and try again
|
||||
curl_setopt($this->handle, CURLOPT_ENCODING, 'none');
|
||||
|
||||
$this->response_data = '';
|
||||
$this->response_bytes = 0;
|
||||
curl_exec($this->handle);
|
||||
$response = $this->response_data;
|
||||
}
|
||||
|
||||
$this->process_response($response, $options);
|
||||
curl_close($this->fp);
|
||||
|
||||
// Need to remove the $this reference from the curl handle.
|
||||
// Otherwise Requests_Transport_cURL wont be garbage collected and the curl_close() will never be called.
|
||||
curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, null);
|
||||
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, null);
|
||||
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
|
|
@ -133,6 +192,11 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
* @return array Array of Requests_Response objects (may contain Requests_Exception or string responses as well)
|
||||
*/
|
||||
public function request_multiple($requests, $options) {
|
||||
// If you're not requesting, we can't get any responses ¯\_(ツ)_/¯
|
||||
if (empty($requests)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$multihandle = curl_multi_init();
|
||||
$subrequests = array();
|
||||
$subhandles = array();
|
||||
|
|
@ -171,9 +235,23 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
// Parse the finished requests before we start getting the new ones
|
||||
foreach ($to_process as $key => $done) {
|
||||
$options = $requests[$key]['options'];
|
||||
$responses[$key] = $subrequests[$key]->process_response(curl_multi_getcontent($done['handle']), $options);
|
||||
if (CURLE_OK !== $done['result']) {
|
||||
//get error string for handle.
|
||||
$reason = curl_error($done['handle']);
|
||||
$exception = new Requests_Exception_Transport_cURL(
|
||||
$reason,
|
||||
Requests_Exception_Transport_cURL::EASY,
|
||||
$done['handle'],
|
||||
$done['result']
|
||||
);
|
||||
$responses[$key] = $exception;
|
||||
$options['hooks']->dispatch('transport.internal.parse_error', array(&$responses[$key], $requests[$key]));
|
||||
}
|
||||
else {
|
||||
$responses[$key] = $subrequests[$key]->process_response($subrequests[$key]->response_data, $options);
|
||||
|
||||
$options['hooks']->dispatch('transport.internal.parse_response', array(&$responses[$key], $requests[$key]));
|
||||
$options['hooks']->dispatch('transport.internal.parse_response', array(&$responses[$key], $requests[$key]));
|
||||
}
|
||||
|
||||
curl_multi_remove_handle($multihandle, $done['handle']);
|
||||
curl_close($done['handle']);
|
||||
|
|
@ -207,10 +285,17 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
|
||||
if ($options['filename'] !== false) {
|
||||
$this->stream_handle = fopen($options['filename'], 'wb');
|
||||
curl_setopt($this->fp, CURLOPT_FILE, $this->stream_handle);
|
||||
}
|
||||
|
||||
return $this->fp;
|
||||
$this->response_data = '';
|
||||
$this->response_bytes = 0;
|
||||
$this->response_byte_limit = false;
|
||||
if ($options['max_bytes'] !== false) {
|
||||
$this->response_byte_limit = $options['max_bytes'];
|
||||
}
|
||||
$this->hooks = $options['hooks'];
|
||||
|
||||
return $this->handle;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -222,46 +307,98 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
* @param array $options Request options, see {@see Requests::response()} for documentation
|
||||
*/
|
||||
protected function setup_handle($url, $headers, $data, $options) {
|
||||
$options['hooks']->dispatch('curl.before_request', array(&$this->fp));
|
||||
$options['hooks']->dispatch('curl.before_request', array(&$this->handle));
|
||||
|
||||
// Force closing the connection for old versions of cURL (<7.22).
|
||||
if ( ! isset( $headers['Connection'] ) ) {
|
||||
$headers['Connection'] = 'close';
|
||||
}
|
||||
|
||||
$headers = Requests::flatten($headers);
|
||||
if (in_array($options['type'], array(Requests::HEAD, Requests::GET, Requests::DELETE)) & !empty($data)) {
|
||||
$url = self::format_get($url, $data);
|
||||
}
|
||||
elseif (!empty($data) && !is_string($data)) {
|
||||
$data = http_build_query($data, null, '&');
|
||||
|
||||
if (!empty($data)) {
|
||||
$data_format = $options['data_format'];
|
||||
|
||||
if ($data_format === 'query') {
|
||||
$url = self::format_get($url, $data);
|
||||
$data = '';
|
||||
}
|
||||
elseif (!is_string($data)) {
|
||||
$data = http_build_query($data, null, '&');
|
||||
}
|
||||
}
|
||||
|
||||
switch ($options['type']) {
|
||||
case Requests::POST:
|
||||
curl_setopt($this->fp, CURLOPT_POST, true);
|
||||
curl_setopt($this->fp, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($this->handle, CURLOPT_POST, true);
|
||||
curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
|
||||
break;
|
||||
case Requests::HEAD:
|
||||
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
|
||||
curl_setopt($this->handle, CURLOPT_NOBODY, true);
|
||||
break;
|
||||
case Requests::TRACE:
|
||||
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
|
||||
break;
|
||||
case Requests::PATCH:
|
||||
case Requests::PUT:
|
||||
curl_setopt($this->fp, CURLOPT_CUSTOMREQUEST, $options['type']);
|
||||
curl_setopt($this->fp, CURLOPT_POSTFIELDS, $data);
|
||||
break;
|
||||
case Requests::DELETE:
|
||||
curl_setopt($this->fp, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
||||
break;
|
||||
case Requests::HEAD:
|
||||
curl_setopt($this->fp, CURLOPT_NOBODY, true);
|
||||
break;
|
||||
case Requests::OPTIONS:
|
||||
default:
|
||||
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
|
||||
if (!empty($data)) {
|
||||
curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
}
|
||||
|
||||
curl_setopt($this->fp, CURLOPT_URL, $url);
|
||||
curl_setopt($this->fp, CURLOPT_TIMEOUT, $options['timeout']);
|
||||
curl_setopt($this->fp, CURLOPT_CONNECTTIMEOUT, $options['timeout']);
|
||||
curl_setopt($this->fp, CURLOPT_REFERER, $url);
|
||||
curl_setopt($this->fp, CURLOPT_USERAGENT, $options['useragent']);
|
||||
curl_setopt($this->fp, CURLOPT_HTTPHEADER, $headers);
|
||||
// cURL requires a minimum timeout of 1 second when using the system
|
||||
// DNS resolver, as it uses `alarm()`, which is second resolution only.
|
||||
// There's no way to detect which DNS resolver is being used from our
|
||||
// end, so we need to round up regardless of the supplied timeout.
|
||||
//
|
||||
// https://github.com/curl/curl/blob/4f45240bc84a9aa648c8f7243be7b79e9f9323a5/lib/hostip.c#L606-L609
|
||||
$timeout = max($options['timeout'], 1);
|
||||
|
||||
if (is_int($timeout) || $this->version < self::CURL_7_16_2) {
|
||||
curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($timeout));
|
||||
}
|
||||
else {
|
||||
curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($timeout * 1000));
|
||||
}
|
||||
|
||||
if (is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2) {
|
||||
curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT, ceil($options['connect_timeout']));
|
||||
}
|
||||
else {
|
||||
curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT_MS, round($options['connect_timeout'] * 1000));
|
||||
}
|
||||
curl_setopt($this->handle, CURLOPT_URL, $url);
|
||||
curl_setopt($this->handle, CURLOPT_REFERER, $url);
|
||||
curl_setopt($this->handle, CURLOPT_USERAGENT, $options['useragent']);
|
||||
if (!empty($headers)) {
|
||||
curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers);
|
||||
}
|
||||
if ($options['protocol_version'] === 1.1) {
|
||||
curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
||||
}
|
||||
else {
|
||||
curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
|
||||
}
|
||||
|
||||
if (true === $options['blocking']) {
|
||||
curl_setopt($this->fp, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers'));
|
||||
curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers'));
|
||||
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body'));
|
||||
curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a response
|
||||
*
|
||||
* @param string $response Response data from the body
|
||||
* @param array $options Request options
|
||||
* @return string HTTP response data including headers
|
||||
*/
|
||||
public function process_response($response, $options) {
|
||||
if ($options['blocking'] === false) {
|
||||
$fake_headers = '';
|
||||
|
|
@ -276,13 +413,17 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
$this->headers .= $response;
|
||||
}
|
||||
|
||||
if (curl_errno($this->fp)) {
|
||||
throw new Requests_Exception('cURL error ' . curl_errno($this->fp) . ': ' . curl_error($this->fp), 'curlerror', $this->fp);
|
||||
return;
|
||||
if (curl_errno($this->handle)) {
|
||||
$error = sprintf(
|
||||
'cURL error %s: %s',
|
||||
curl_errno($this->handle),
|
||||
curl_error($this->handle)
|
||||
);
|
||||
throw new Requests_Exception($error, 'curlerror', $this->handle);
|
||||
}
|
||||
$this->info = curl_getinfo($this->fp);
|
||||
$this->info = curl_getinfo($this->handle);
|
||||
|
||||
$options['hooks']->dispatch('curl.after_request', array(&$this->headers));
|
||||
$options['hooks']->dispatch('curl.after_request', array(&$this->headers, &$this->info));
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
|
|
@ -293,7 +434,7 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
* @param string $headers Header string
|
||||
* @return integer Length of provided header
|
||||
*/
|
||||
protected function stream_headers($handle, $headers) {
|
||||
public function stream_headers($handle, $headers) {
|
||||
// Why do we do this? cURL will send both the final response and any
|
||||
// interim responses, such as a 100 Continue. We don't need that.
|
||||
// (We may want to keep this somewhere just in case)
|
||||
|
|
@ -309,11 +450,49 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
return strlen($headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect data as it's received
|
||||
*
|
||||
* @since 1.6.1
|
||||
*
|
||||
* @param resource $handle cURL resource
|
||||
* @param string $data Body data
|
||||
* @return integer Length of provided data
|
||||
*/
|
||||
public function stream_body($handle, $data) {
|
||||
$this->hooks->dispatch('request.progress', array($data, $this->response_bytes, $this->response_byte_limit));
|
||||
$data_length = strlen($data);
|
||||
|
||||
// Are we limiting the response size?
|
||||
if ($this->response_byte_limit) {
|
||||
if ($this->response_bytes === $this->response_byte_limit) {
|
||||
// Already at maximum, move on
|
||||
return $data_length;
|
||||
}
|
||||
|
||||
if (($this->response_bytes + $data_length) > $this->response_byte_limit) {
|
||||
// Limit the length
|
||||
$limited_length = ($this->response_byte_limit - $this->response_bytes);
|
||||
$data = substr($data, 0, $limited_length);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->stream_handle) {
|
||||
fwrite($this->stream_handle, $data);
|
||||
}
|
||||
else {
|
||||
$this->response_data .= $data;
|
||||
}
|
||||
|
||||
$this->response_bytes += strlen($data);
|
||||
return $data_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a URL given GET data
|
||||
*
|
||||
* @param string $url
|
||||
* @param array|object $data Data to build query using, see {@see http://php.net/http_build_query}
|
||||
* @param array|object $data Data to build query using, see {@see https://secure.php.net/http_build_query}
|
||||
* @return string URL with data
|
||||
*/
|
||||
protected static function format_get($url, $data) {
|
||||
|
|
@ -345,7 +524,19 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
* @codeCoverageIgnore
|
||||
* @return boolean True if the transport is valid, false otherwise.
|
||||
*/
|
||||
public static function test() {
|
||||
return (function_exists('curl_init') && function_exists('curl_exec'));
|
||||
public static function test($capabilities = array()) {
|
||||
if (!function_exists('curl_init') || !function_exists('curl_exec')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If needed, check that our installed curl version supports SSL
|
||||
if (isset($capabilities['ssl']) && $capabilities['ssl']) {
|
||||
$curl_version = curl_version();
|
||||
if (!(CURL_VERSION_SSL & $curl_version['features'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue