Edit File by line
/home/barbar84/www/wp-inclu.../Requests/Transpor...
File: cURL.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* cURL HTTP transport
[2] Fix | Delete
*
[3] Fix | Delete
* @package Requests
[4] Fix | Delete
* @subpackage Transport
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* cURL HTTP transport
[9] Fix | Delete
*
[10] Fix | Delete
* @package Requests
[11] Fix | Delete
* @subpackage Transport
[12] Fix | Delete
*/
[13] Fix | Delete
class Requests_Transport_cURL implements Requests_Transport {
[14] Fix | Delete
const CURL_7_10_5 = 0x070A05;
[15] Fix | Delete
const CURL_7_16_2 = 0x071002;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Raw HTTP data
[19] Fix | Delete
*
[20] Fix | Delete
* @var string
[21] Fix | Delete
*/
[22] Fix | Delete
public $headers = '';
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* Raw body data
[26] Fix | Delete
*
[27] Fix | Delete
* @var string
[28] Fix | Delete
*/
[29] Fix | Delete
public $response_data = '';
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Information on the current request
[33] Fix | Delete
*
[34] Fix | Delete
* @var array cURL information array, see {@see https://secure.php.net/curl_getinfo}
[35] Fix | Delete
*/
[36] Fix | Delete
public $info;
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Version string
[40] Fix | Delete
*
[41] Fix | Delete
* @var long
[42] Fix | Delete
*/
[43] Fix | Delete
public $version;
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* cURL handle
[47] Fix | Delete
*
[48] Fix | Delete
* @var resource
[49] Fix | Delete
*/
[50] Fix | Delete
protected $handle;
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Hook dispatcher instance
[54] Fix | Delete
*
[55] Fix | Delete
* @var Requests_Hooks
[56] Fix | Delete
*/
[57] Fix | Delete
protected $hooks;
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Have we finished the headers yet?
[61] Fix | Delete
*
[62] Fix | Delete
* @var boolean
[63] Fix | Delete
*/
[64] Fix | Delete
protected $done_headers = false;
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* If streaming to a file, keep the file pointer
[68] Fix | Delete
*
[69] Fix | Delete
* @var resource
[70] Fix | Delete
*/
[71] Fix | Delete
protected $stream_handle;
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* How many bytes are in the response body?
[75] Fix | Delete
*
[76] Fix | Delete
* @var int
[77] Fix | Delete
*/
[78] Fix | Delete
protected $response_bytes;
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* What's the maximum number of bytes we should keep?
[82] Fix | Delete
*
[83] Fix | Delete
* @var int|bool Byte count, or false if no limit.
[84] Fix | Delete
*/
[85] Fix | Delete
protected $response_byte_limit;
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Constructor
[89] Fix | Delete
*/
[90] Fix | Delete
public function __construct() {
[91] Fix | Delete
$curl = curl_version();
[92] Fix | Delete
$this->version = $curl['version_number'];
[93] Fix | Delete
$this->handle = curl_init();
[94] Fix | Delete
[95] Fix | Delete
curl_setopt($this->handle, CURLOPT_HEADER, false);
[96] Fix | Delete
curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, 1);
[97] Fix | Delete
if ($this->version >= self::CURL_7_10_5) {
[98] Fix | Delete
curl_setopt($this->handle, CURLOPT_ENCODING, '');
[99] Fix | Delete
}
[100] Fix | Delete
if (defined('CURLOPT_PROTOCOLS')) {
[101] Fix | Delete
curl_setopt($this->handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
[102] Fix | Delete
}
[103] Fix | Delete
if (defined('CURLOPT_REDIR_PROTOCOLS')) {
[104] Fix | Delete
curl_setopt($this->handle, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
/**
[109] Fix | Delete
* Destructor
[110] Fix | Delete
*/
[111] Fix | Delete
public function __destruct() {
[112] Fix | Delete
if (is_resource($this->handle)) {
[113] Fix | Delete
curl_close($this->handle);
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Perform a request
[119] Fix | Delete
*
[120] Fix | Delete
* @throws Requests_Exception On a cURL error (`curlerror`)
[121] Fix | Delete
*
[122] Fix | Delete
* @param string $url URL to request
[123] Fix | Delete
* @param array $headers Associative array of request headers
[124] Fix | Delete
* @param string|array $data Data to send either as the POST body, or as parameters in the URL for a GET/HEAD
[125] Fix | Delete
* @param array $options Request options, see {@see Requests::response()} for documentation
[126] Fix | Delete
* @return string Raw HTTP result
[127] Fix | Delete
*/
[128] Fix | Delete
public function request($url, $headers = array(), $data = array(), $options = array()) {
[129] Fix | Delete
$this->hooks = $options['hooks'];
[130] Fix | Delete
[131] Fix | Delete
$this->setup_handle($url, $headers, $data, $options);
[132] Fix | Delete
[133] Fix | Delete
$options['hooks']->dispatch('curl.before_send', array(&$this->handle));
[134] Fix | Delete
[135] Fix | Delete
if ($options['filename'] !== false) {
[136] Fix | Delete
$this->stream_handle = fopen($options['filename'], 'wb');
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
$this->response_data = '';
[140] Fix | Delete
$this->response_bytes = 0;
[141] Fix | Delete
$this->response_byte_limit = false;
[142] Fix | Delete
if ($options['max_bytes'] !== false) {
[143] Fix | Delete
$this->response_byte_limit = $options['max_bytes'];
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
if (isset($options['verify'])) {
[147] Fix | Delete
if ($options['verify'] === false) {
[148] Fix | Delete
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
[149] Fix | Delete
curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, 0);
[150] Fix | Delete
}
[151] Fix | Delete
elseif (is_string($options['verify'])) {
[152] Fix | Delete
curl_setopt($this->handle, CURLOPT_CAINFO, $options['verify']);
[153] Fix | Delete
}
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
if (isset($options['verifyname']) && $options['verifyname'] === false) {
[157] Fix | Delete
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
curl_exec($this->handle);
[161] Fix | Delete
$response = $this->response_data;
[162] Fix | Delete
[163] Fix | Delete
$options['hooks']->dispatch('curl.after_send', array());
[164] Fix | Delete
[165] Fix | Delete
if (curl_errno($this->handle) === 23 || curl_errno($this->handle) === 61) {
[166] Fix | Delete
// Reset encoding and try again
[167] Fix | Delete
curl_setopt($this->handle, CURLOPT_ENCODING, 'none');
[168] Fix | Delete
[169] Fix | Delete
$this->response_data = '';
[170] Fix | Delete
$this->response_bytes = 0;
[171] Fix | Delete
curl_exec($this->handle);
[172] Fix | Delete
$response = $this->response_data;
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
$this->process_response($response, $options);
[176] Fix | Delete
[177] Fix | Delete
// Need to remove the $this reference from the curl handle.
[178] Fix | Delete
// Otherwise Requests_Transport_cURL wont be garbage collected and the curl_close() will never be called.
[179] Fix | Delete
curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, null);
[180] Fix | Delete
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, null);
[181] Fix | Delete
[182] Fix | Delete
return $this->headers;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Send multiple requests simultaneously
[187] Fix | Delete
*
[188] Fix | Delete
* @param array $requests Request data
[189] Fix | Delete
* @param array $options Global options
[190] Fix | Delete
* @return array Array of Requests_Response objects (may contain Requests_Exception or string responses as well)
[191] Fix | Delete
*/
[192] Fix | Delete
public function request_multiple($requests, $options) {
[193] Fix | Delete
// If you're not requesting, we can't get any responses ¯\_(ツ)_/¯
[194] Fix | Delete
if (empty($requests)) {
[195] Fix | Delete
return array();
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
$multihandle = curl_multi_init();
[199] Fix | Delete
$subrequests = array();
[200] Fix | Delete
$subhandles = array();
[201] Fix | Delete
[202] Fix | Delete
$class = get_class($this);
[203] Fix | Delete
foreach ($requests as $id => $request) {
[204] Fix | Delete
$subrequests[$id] = new $class();
[205] Fix | Delete
$subhandles[$id] = $subrequests[$id]->get_subrequest_handle($request['url'], $request['headers'], $request['data'], $request['options']);
[206] Fix | Delete
$request['options']['hooks']->dispatch('curl.before_multi_add', array(&$subhandles[$id]));
[207] Fix | Delete
curl_multi_add_handle($multihandle, $subhandles[$id]);
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
$completed = 0;
[211] Fix | Delete
$responses = array();
[212] Fix | Delete
[213] Fix | Delete
$request['options']['hooks']->dispatch('curl.before_multi_exec', array(&$multihandle));
[214] Fix | Delete
[215] Fix | Delete
do {
[216] Fix | Delete
$active = false;
[217] Fix | Delete
[218] Fix | Delete
do {
[219] Fix | Delete
$status = curl_multi_exec($multihandle, $active);
[220] Fix | Delete
}
[221] Fix | Delete
while ($status === CURLM_CALL_MULTI_PERFORM);
[222] Fix | Delete
[223] Fix | Delete
$to_process = array();
[224] Fix | Delete
[225] Fix | Delete
// Read the information as needed
[226] Fix | Delete
while ($done = curl_multi_info_read($multihandle)) {
[227] Fix | Delete
$key = array_search($done['handle'], $subhandles, true);
[228] Fix | Delete
if (!isset($to_process[$key])) {
[229] Fix | Delete
$to_process[$key] = $done;
[230] Fix | Delete
}
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
// Parse the finished requests before we start getting the new ones
[234] Fix | Delete
foreach ($to_process as $key => $done) {
[235] Fix | Delete
$options = $requests[$key]['options'];
[236] Fix | Delete
if (CURLE_OK !== $done['result']) {
[237] Fix | Delete
//get error string for handle.
[238] Fix | Delete
$reason = curl_error($done['handle']);
[239] Fix | Delete
$exception = new Requests_Exception_Transport_cURL(
[240] Fix | Delete
$reason,
[241] Fix | Delete
Requests_Exception_Transport_cURL::EASY,
[242] Fix | Delete
$done['handle'],
[243] Fix | Delete
$done['result']
[244] Fix | Delete
);
[245] Fix | Delete
$responses[$key] = $exception;
[246] Fix | Delete
$options['hooks']->dispatch('transport.internal.parse_error', array(&$responses[$key], $requests[$key]));
[247] Fix | Delete
}
[248] Fix | Delete
else {
[249] Fix | Delete
$responses[$key] = $subrequests[$key]->process_response($subrequests[$key]->response_data, $options);
[250] Fix | Delete
[251] Fix | Delete
$options['hooks']->dispatch('transport.internal.parse_response', array(&$responses[$key], $requests[$key]));
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
curl_multi_remove_handle($multihandle, $done['handle']);
[255] Fix | Delete
curl_close($done['handle']);
[256] Fix | Delete
[257] Fix | Delete
if (!is_string($responses[$key])) {
[258] Fix | Delete
$options['hooks']->dispatch('multiple.request.complete', array(&$responses[$key], $key));
[259] Fix | Delete
}
[260] Fix | Delete
$completed++;
[261] Fix | Delete
}
[262] Fix | Delete
}
[263] Fix | Delete
while ($active || $completed < count($subrequests));
[264] Fix | Delete
[265] Fix | Delete
$request['options']['hooks']->dispatch('curl.after_multi_exec', array(&$multihandle));
[266] Fix | Delete
[267] Fix | Delete
curl_multi_close($multihandle);
[268] Fix | Delete
[269] Fix | Delete
return $responses;
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
/**
[273] Fix | Delete
* Get the cURL handle for use in a multi-request
[274] Fix | Delete
*
[275] Fix | Delete
* @param string $url URL to request
[276] Fix | Delete
* @param array $headers Associative array of request headers
[277] Fix | Delete
* @param string|array $data Data to send either as the POST body, or as parameters in the URL for a GET/HEAD
[278] Fix | Delete
* @param array $options Request options, see {@see Requests::response()} for documentation
[279] Fix | Delete
* @return resource Subrequest's cURL handle
[280] Fix | Delete
*/
[281] Fix | Delete
public function &get_subrequest_handle($url, $headers, $data, $options) {
[282] Fix | Delete
$this->setup_handle($url, $headers, $data, $options);
[283] Fix | Delete
[284] Fix | Delete
if ($options['filename'] !== false) {
[285] Fix | Delete
$this->stream_handle = fopen($options['filename'], 'wb');
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
$this->response_data = '';
[289] Fix | Delete
$this->response_bytes = 0;
[290] Fix | Delete
$this->response_byte_limit = false;
[291] Fix | Delete
if ($options['max_bytes'] !== false) {
[292] Fix | Delete
$this->response_byte_limit = $options['max_bytes'];
[293] Fix | Delete
}
[294] Fix | Delete
$this->hooks = $options['hooks'];
[295] Fix | Delete
[296] Fix | Delete
return $this->handle;
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
/**
[300] Fix | Delete
* Setup the cURL handle for the given data
[301] Fix | Delete
*
[302] Fix | Delete
* @param string $url URL to request
[303] Fix | Delete
* @param array $headers Associative array of request headers
[304] Fix | Delete
* @param string|array $data Data to send either as the POST body, or as parameters in the URL for a GET/HEAD
[305] Fix | Delete
* @param array $options Request options, see {@see Requests::response()} for documentation
[306] Fix | Delete
*/
[307] Fix | Delete
protected function setup_handle($url, $headers, $data, $options) {
[308] Fix | Delete
$options['hooks']->dispatch('curl.before_request', array(&$this->handle));
[309] Fix | Delete
[310] Fix | Delete
// Force closing the connection for old versions of cURL (<7.22).
[311] Fix | Delete
if ( ! isset( $headers['Connection'] ) ) {
[312] Fix | Delete
$headers['Connection'] = 'close';
[313] Fix | Delete
}
[314] Fix | Delete
[315] Fix | Delete
$headers = Requests::flatten($headers);
[316] Fix | Delete
[317] Fix | Delete
if (!empty($data)) {
[318] Fix | Delete
$data_format = $options['data_format'];
[319] Fix | Delete
[320] Fix | Delete
if ($data_format === 'query') {
[321] Fix | Delete
$url = self::format_get($url, $data);
[322] Fix | Delete
$data = '';
[323] Fix | Delete
}
[324] Fix | Delete
elseif (!is_string($data)) {
[325] Fix | Delete
$data = http_build_query($data, null, '&');
[326] Fix | Delete
}
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
switch ($options['type']) {
[330] Fix | Delete
case Requests::POST:
[331] Fix | Delete
curl_setopt($this->handle, CURLOPT_POST, true);
[332] Fix | Delete
curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
[333] Fix | Delete
break;
[334] Fix | Delete
case Requests::HEAD:
[335] Fix | Delete
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
[336] Fix | Delete
curl_setopt($this->handle, CURLOPT_NOBODY, true);
[337] Fix | Delete
break;
[338] Fix | Delete
case Requests::TRACE:
[339] Fix | Delete
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
[340] Fix | Delete
break;
[341] Fix | Delete
case Requests::PATCH:
[342] Fix | Delete
case Requests::PUT:
[343] Fix | Delete
case Requests::DELETE:
[344] Fix | Delete
case Requests::OPTIONS:
[345] Fix | Delete
default:
[346] Fix | Delete
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
[347] Fix | Delete
if (!empty($data)) {
[348] Fix | Delete
curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
[349] Fix | Delete
}
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
// cURL requires a minimum timeout of 1 second when using the system
[353] Fix | Delete
// DNS resolver, as it uses `alarm()`, which is second resolution only.
[354] Fix | Delete
// There's no way to detect which DNS resolver is being used from our
[355] Fix | Delete
// end, so we need to round up regardless of the supplied timeout.
[356] Fix | Delete
//
[357] Fix | Delete
// https://github.com/curl/curl/blob/4f45240bc84a9aa648c8f7243be7b79e9f9323a5/lib/hostip.c#L606-L609
[358] Fix | Delete
$timeout = max($options['timeout'], 1);
[359] Fix | Delete
[360] Fix | Delete
if (is_int($timeout) || $this->version < self::CURL_7_16_2) {
[361] Fix | Delete
curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($timeout));
[362] Fix | Delete
}
[363] Fix | Delete
else {
[364] Fix | Delete
curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($timeout * 1000));
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
if (is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2) {
[368] Fix | Delete
curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT, ceil($options['connect_timeout']));
[369] Fix | Delete
}
[370] Fix | Delete
else {
[371] Fix | Delete
curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT_MS, round($options['connect_timeout'] * 1000));
[372] Fix | Delete
}
[373] Fix | Delete
curl_setopt($this->handle, CURLOPT_URL, $url);
[374] Fix | Delete
curl_setopt($this->handle, CURLOPT_REFERER, $url);
[375] Fix | Delete
curl_setopt($this->handle, CURLOPT_USERAGENT, $options['useragent']);
[376] Fix | Delete
if (!empty($headers)) {
[377] Fix | Delete
curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers);
[378] Fix | Delete
}
[379] Fix | Delete
if ($options['protocol_version'] === 1.1) {
[380] Fix | Delete
curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
[381] Fix | Delete
}
[382] Fix | Delete
else {
[383] Fix | Delete
curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
if (true === $options['blocking']) {
[387] Fix | Delete
curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers'));
[388] Fix | Delete
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body'));
[389] Fix | Delete
curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE);
[390] Fix | Delete
}
[391] Fix | Delete
}
[392] Fix | Delete
[393] Fix | Delete
/**
[394] Fix | Delete
* Process a response
[395] Fix | Delete
*
[396] Fix | Delete
* @param string $response Response data from the body
[397] Fix | Delete
* @param array $options Request options
[398] Fix | Delete
* @return string HTTP response data including headers
[399] Fix | Delete
*/
[400] Fix | Delete
public function process_response($response, $options) {
[401] Fix | Delete
if ($options['blocking'] === false) {
[402] Fix | Delete
$fake_headers = '';
[403] Fix | Delete
$options['hooks']->dispatch('curl.after_request', array(&$fake_headers));
[404] Fix | Delete
return false;
[405] Fix | Delete
}
[406] Fix | Delete
if ($options['filename'] !== false) {
[407] Fix | Delete
fclose($this->stream_handle);
[408] Fix | Delete
$this->headers = trim($this->headers);
[409] Fix | Delete
}
[410] Fix | Delete
else {
[411] Fix | Delete
$this->headers .= $response;
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
if (curl_errno($this->handle)) {
[415] Fix | Delete
$error = sprintf(
[416] Fix | Delete
'cURL error %s: %s',
[417] Fix | Delete
curl_errno($this->handle),
[418] Fix | Delete
curl_error($this->handle)
[419] Fix | Delete
);
[420] Fix | Delete
throw new Requests_Exception($error, 'curlerror', $this->handle);
[421] Fix | Delete
}
[422] Fix | Delete
$this->info = curl_getinfo($this->handle);
[423] Fix | Delete
[424] Fix | Delete
$options['hooks']->dispatch('curl.after_request', array(&$this->headers, &$this->info));
[425] Fix | Delete
return $this->headers;
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
/**
[429] Fix | Delete
* Collect the headers as they are received
[430] Fix | Delete
*
[431] Fix | Delete
* @param resource $handle cURL resource
[432] Fix | Delete
* @param string $headers Header string
[433] Fix | Delete
* @return integer Length of provided header
[434] Fix | Delete
*/
[435] Fix | Delete
public function stream_headers($handle, $headers) {
[436] Fix | Delete
// Why do we do this? cURL will send both the final response and any
[437] Fix | Delete
// interim responses, such as a 100 Continue. We don't need that.
[438] Fix | Delete
// (We may want to keep this somewhere just in case)
[439] Fix | Delete
if ($this->done_headers) {
[440] Fix | Delete
$this->headers = '';
[441] Fix | Delete
$this->done_headers = false;
[442] Fix | Delete
}
[443] Fix | Delete
$this->headers .= $headers;
[444] Fix | Delete
[445] Fix | Delete
if ($headers === "\r\n") {
[446] Fix | Delete
$this->done_headers = true;
[447] Fix | Delete
}
[448] Fix | Delete
return strlen($headers);
[449] Fix | Delete
}
[450] Fix | Delete
[451] Fix | Delete
/**
[452] Fix | Delete
* Collect data as it's received
[453] Fix | Delete
*
[454] Fix | Delete
* @since 1.6.1
[455] Fix | Delete
*
[456] Fix | Delete
* @param resource $handle cURL resource
[457] Fix | Delete
* @param string $data Body data
[458] Fix | Delete
* @return integer Length of provided data
[459] Fix | Delete
*/
[460] Fix | Delete
public function stream_body($handle, $data) {
[461] Fix | Delete
$this->hooks->dispatch('request.progress', array($data, $this->response_bytes, $this->response_byte_limit));
[462] Fix | Delete
$data_length = strlen($data);
[463] Fix | Delete
[464] Fix | Delete
// Are we limiting the response size?
[465] Fix | Delete
if ($this->response_byte_limit) {
[466] Fix | Delete
if ($this->response_bytes === $this->response_byte_limit) {
[467] Fix | Delete
// Already at maximum, move on
[468] Fix | Delete
return $data_length;
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
if (($this->response_bytes + $data_length) > $this->response_byte_limit) {
[472] Fix | Delete
// Limit the length
[473] Fix | Delete
$limited_length = ($this->response_byte_limit - $this->response_bytes);
[474] Fix | Delete
$data = substr($data, 0, $limited_length);
[475] Fix | Delete
}
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
if ($this->stream_handle) {
[479] Fix | Delete
fwrite($this->stream_handle, $data);
[480] Fix | Delete
}
[481] Fix | Delete
else {
[482] Fix | Delete
$this->response_data .= $data;
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
$this->response_bytes += strlen($data);
[486] Fix | Delete
return $data_length;
[487] Fix | Delete
}
[488] Fix | Delete
[489] Fix | Delete
/**
[490] Fix | Delete
* Format a URL given GET data
[491] Fix | Delete
*
[492] Fix | Delete
* @param string $url
[493] Fix | Delete
* @param array|object $data Data to build query using, see {@see https://secure.php.net/http_build_query}
[494] Fix | Delete
* @return string URL with data
[495] Fix | Delete
*/
[496] Fix | Delete
protected static function format_get($url, $data) {
[497] Fix | Delete
if (!empty($data)) {
[498] Fix | Delete
$url_parts = parse_url($url);
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function