Skip to content

Commit

Permalink
Update PEAR HTTP_Request2 package to version 2.5.1 (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
bramley authored Jan 13, 2023
1 parent f6d238a commit 4e4777e
Show file tree
Hide file tree
Showing 17 changed files with 482 additions and 301 deletions.
174 changes: 104 additions & 70 deletions public_html/lists/admin/PEAR/HTTP/Request2.php

Large diffs are not rendered by default.

30 changes: 18 additions & 12 deletions public_html/lists/admin/PEAR/HTTP/Request2/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @category HTTP
* @package HTTP_Request2
* @author Alexey Borzov <[email protected]>
* @copyright 2008-2020 Alexey Borzov <[email protected]>
* @copyright 2008-2022 Alexey Borzov <[email protected]>
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2
*/
Expand All @@ -34,14 +34,15 @@
* @package HTTP_Request2
* @author Alexey Borzov <[email protected]>
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.4.2
* @version Release: 2.5.1
* @link http://pear.php.net/package/HTTP_Request2
*/
abstract class HTTP_Request2_Adapter
{
/**
* A list of methods that MUST NOT have a request body, per RFC 2616
* @var array
*
* @var array
*/
protected static $bodyDisallowed = ['TRACE'];

Expand All @@ -59,20 +60,23 @@ abstract class HTTP_Request2_Adapter

/**
* Request being sent
* @var HTTP_Request2
*
* @var HTTP_Request2
*/
protected $request;

/**
* Request body
* @var string|resource|HTTP_Request2_MultipartBody
* @see HTTP_Request2::getBody()
*
* @var string|resource|HTTP_Request2_MultipartBody
* @see HTTP_Request2::getBody()
*/
protected $requestBody;

/**
* Length of the request body
* @var integer
*
* @var integer
*/
protected $contentLength;

Expand All @@ -81,17 +85,19 @@ abstract class HTTP_Request2_Adapter
*
* @param HTTP_Request2 $request HTTP request message
*
* @return HTTP_Request2_Response
* @throws HTTP_Request2_Exception
* @return HTTP_Request2_Response
* @throws HTTP_Request2_Exception
*/
abstract public function sendRequest(HTTP_Request2 $request);

/**
* Calculates length of the request body, adds proper headers
*
* @param array &$headers associative array of request headers, this method
* will add proper 'Content-Length' and 'Content-Type'
* headers to this array (or remove them if not needed)
* @param array $headers associative array of request headers, this method
* will add proper 'Content-Length' and 'Content-Type'
* headers to this array (or remove them if not needed)
*
* @return void
*/
protected function calculateRequestLength(&$headers)
{
Expand Down
89 changes: 51 additions & 38 deletions public_html/lists/admin/PEAR/HTTP/Request2/Adapter/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @category HTTP
* @package HTTP_Request2
* @author Alexey Borzov <[email protected]>
* @copyright 2008-2020 Alexey Borzov <[email protected]>
* @copyright 2008-2022 Alexey Borzov <[email protected]>
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2
*/
Expand All @@ -30,14 +30,15 @@
* @package HTTP_Request2
* @author Alexey Borzov <[email protected]>
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.4.2
* @version Release: 2.5.1
* @link http://pear.php.net/package/HTTP_Request2
*/
class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
{
/**
* Mapping of header names to cURL options
* @var array
*
* @var array
*/
protected static $headerMap = [
'accept-encoding' => CURLOPT_ENCODING,
Expand All @@ -48,7 +49,8 @@ class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter

/**
* Mapping of SSL context options to cURL options
* @var array
*
* @var array
*/
protected static $sslContextMap = [
'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER,
Expand All @@ -60,7 +62,8 @@ class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter

/**
* Mapping of CURLE_* constants to Exception subclasses and error codes
* @var array
*
* @var array
*/
protected static $errorMap = [
CURLE_UNSUPPORTED_PROTOCOL => ['HTTP_Request2_MessageException',
Expand Down Expand Up @@ -100,38 +103,44 @@ class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter

/**
* Response being received
* @var HTTP_Request2_Response
*
* @var HTTP_Request2_Response
*/
protected $response;

/**
* Whether 'sentHeaders' event was sent to observers
* @var boolean
*
* @var boolean
*/
protected $eventSentHeaders = false;

/**
* Whether 'receivedHeaders' event was sent to observers
*
* @var boolean
*/
protected $eventReceivedHeaders = false;

/**
* Whether 'sentBoody' event was sent to observers
*
* @var boolean
*/
protected $eventSentBody = false;

/**
* Position within request body
* @var integer
* @see callbackReadBody()
*
* @var integer
* @see callbackReadBody()
*/
protected $position = 0;

/**
* Information about last transfer, as returned by curl_getinfo()
* @var array
*
* @var array
*/
protected $lastInfo;

Expand Down Expand Up @@ -161,8 +170,8 @@ protected static function wrapCurlError($ch)
*
* @param HTTP_Request2 $request HTTP request message
*
* @return HTTP_Request2_Response
* @throws HTTP_Request2_Exception
* @return HTTP_Request2_Response
* @throws HTTP_Request2_Exception
*/
public function sendRequest(HTTP_Request2 $request)
{
Expand Down Expand Up @@ -208,7 +217,7 @@ public function sendRequest(HTTP_Request2 $request)
/**
* Returns information about last transfer
*
* @return array associative array as returned by curl_getinfo()
* @return array associative array as returned by curl_getinfo()
*/
public function getInfo()
{
Expand All @@ -218,27 +227,29 @@ public function getInfo()
/**
* Creates a new cURL handle and populates it with data from the request
*
* @return resource a cURL handle, as created by curl_init()
* @throws HTTP_Request2_LogicException
* @throws HTTP_Request2_NotImplementedException
* @return resource a cURL handle, as created by curl_init()
* @throws HTTP_Request2_LogicException
* @throws HTTP_Request2_NotImplementedException
*/
protected function createCurlHandle()
{
$ch = curl_init();

curl_setopt_array($ch, [
// setup write callbacks
CURLOPT_HEADERFUNCTION => [$this, 'callbackWriteHeader'],
CURLOPT_WRITEFUNCTION => [$this, 'callbackWriteBody'],
// buffer size
CURLOPT_BUFFERSIZE => $this->request->getConfig('buffer_size'),
// connection timeout
CURLOPT_CONNECTTIMEOUT => $this->request->getConfig('connect_timeout'),
// save full outgoing headers, in case someone is interested
CURLINFO_HEADER_OUT => true,
// request url
CURLOPT_URL => $this->request->getUrl()->getUrl()
]);
curl_setopt_array(
$ch, [
// setup write callbacks
CURLOPT_HEADERFUNCTION => [$this, 'callbackWriteHeader'],
CURLOPT_WRITEFUNCTION => [$this, 'callbackWriteBody'],
// buffer size
CURLOPT_BUFFERSIZE => $this->request->getConfig('buffer_size'),
// connection timeout
CURLOPT_CONNECTTIMEOUT => $this->request->getConfig('connect_timeout'),
// save full outgoing headers, in case someone is interested
CURLINFO_HEADER_OUT => true,
// request url
CURLOPT_URL => $this->request->getUrl()->getUrl()
]
);

// set up redirects
if (!$this->request->getConfig('follow_redirects')) {
Expand Down Expand Up @@ -399,8 +410,10 @@ protected function createCurlHandle()
* and setting it as CURLOPT_POSTFIELDS, so it isn't recommended for large
* file uploads, use Socket adapter instead.
*
* @param resource $ch cURL handle
* @param array &$headers Request headers
* @param resource $ch cURL handle
* @param array $headers Request headers
*
* @return void
*/
protected function workaroundPhpBug47204($ch, &$headers)
{
Expand All @@ -409,7 +422,7 @@ protected function workaroundPhpBug47204($ch, &$headers)
// https://pear.php.net/bugs/bug.php?id=20440 for PUTs
if (!$this->request->getConfig('follow_redirects')
&& (!($auth = $this->request->getAuth())
|| HTTP_Request2::AUTH_DIGEST != $auth['scheme'])
|| HTTP_Request2::AUTH_DIGEST !== $auth['scheme'])
|| HTTP_Request2::METHOD_POST !== $this->request->getMethod()
) {
curl_setopt($ch, CURLOPT_READFUNCTION, [$this, 'callbackReadBody']);
Expand Down Expand Up @@ -439,7 +452,7 @@ protected function workaroundPhpBug47204($ch, &$headers)
* @param resource $fd file descriptor (not used)
* @param integer $length maximum length of data to return
*
* @return string part of the request body, up to $length bytes
* @return string part of the request body, up to $length bytes
*/
protected function callbackReadBody($ch, $fd, $length)
{
Expand Down Expand Up @@ -472,8 +485,8 @@ protected function callbackReadBody($ch, $fd, $length)
* @param resource $ch cURL handle
* @param string $string response header (with trailing CRLF)
*
* @return integer number of bytes saved
* @see HTTP_Request2_Response::parseHeaderLine()
* @return integer number of bytes saved
* @see HTTP_Request2_Response::parseHeaderLine()
*/
protected function callbackWriteHeader($ch, $string)
{
Expand Down Expand Up @@ -548,9 +561,9 @@ protected function callbackWriteHeader($ch, $string)
* @param resource $ch cURL handle (not used)
* @param string $string part of the response body
*
* @return integer number of bytes saved
* @throws HTTP_Request2_MessageException
* @see HTTP_Request2_Response::appendBody()
* @return integer number of bytes saved
* @throws HTTP_Request2_MessageException
* @see HTTP_Request2_Response::appendBody()
*/
protected function callbackWriteBody($ch, $string)
{
Expand Down
26 changes: 14 additions & 12 deletions public_html/lists/admin/PEAR/HTTP/Request2/Adapter/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @category HTTP
* @package HTTP_Request2
* @author Alexey Borzov <[email protected]>
* @copyright 2008-2020 Alexey Borzov <[email protected]>
* @copyright 2008-2022 Alexey Borzov <[email protected]>
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2
*/
Expand Down Expand Up @@ -44,14 +44,15 @@
* @package HTTP_Request2
* @author Alexey Borzov <[email protected]>
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.4.2
* @version Release: 2.5.1
* @link http://pear.php.net/package/HTTP_Request2
*/
class HTTP_Request2_Adapter_Mock extends HTTP_Request2_Adapter
{
/**
* A queue of responses to be returned by sendRequest()
* @var array
*
* @var array
*/
protected $responses = [];

Expand All @@ -65,8 +66,8 @@ class HTTP_Request2_Adapter_Mock extends HTTP_Request2_Adapter
*
* @param HTTP_Request2 $request HTTP request message
*
* @return HTTP_Request2_Response
* @throws Exception
* @return HTTP_Request2_Response
* @throws Exception
*/
public function sendRequest(HTTP_Request2 $request)
{
Expand Down Expand Up @@ -102,16 +103,17 @@ public function sendRequest(HTTP_Request2 $request)
* @param string $url A request URL this response should be valid for
* (see {@link http://pear.php.net/bugs/bug.php?id=19276})
*
* @throws HTTP_Request2_Exception
* @return void
* @throws HTTP_Request2_Exception
*/
public function addResponse($response, $url = null)
{
if (is_string($response)) {
$response = self::createResponseFromString($response);
} elseif (is_resource($response)) {
$response = self::createResponseFromFile($response);
} elseif (!$response instanceof HTTP_Request2_Response &&
!$response instanceof Exception
} elseif (!$response instanceof HTTP_Request2_Response
&& !$response instanceof Exception
) {
throw new HTTP_Request2_Exception('Parameter is not a valid response');
}
Expand All @@ -123,8 +125,8 @@ public function addResponse($response, $url = null)
*
* @param string $str string containing HTTP response message
*
* @return HTTP_Request2_Response
* @throws HTTP_Request2_Exception
* @return HTTP_Request2_Response
* @throws HTTP_Request2_Exception
*/
public static function createResponseFromString($str)
{
Expand All @@ -146,8 +148,8 @@ public static function createResponseFromString($str)
*
* @param resource $fp file pointer returned by fopen()
*
* @return HTTP_Request2_Response
* @throws HTTP_Request2_Exception
* @return HTTP_Request2_Response
* @throws HTTP_Request2_Exception
*/
public static function createResponseFromFile($fp)
{
Expand Down
Loading

0 comments on commit 4e4777e

Please sign in to comment.