-
-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update PEAR HTTP_Request2 package to version 2.5.1 (#921)
- Loading branch information
Showing
17 changed files
with
482 additions
and
301 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
@@ -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']; | ||
|
||
|
@@ -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; | ||
|
||
|
@@ -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) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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', | ||
|
@@ -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; | ||
|
||
|
@@ -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) | ||
{ | ||
|
@@ -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() | ||
{ | ||
|
@@ -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')) { | ||
|
@@ -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) | ||
{ | ||
|
@@ -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']); | ||
|
@@ -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) | ||
{ | ||
|
@@ -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) | ||
{ | ||
|
@@ -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) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
@@ -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 = []; | ||
|
||
|
@@ -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) | ||
{ | ||
|
@@ -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'); | ||
} | ||
|
@@ -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) | ||
{ | ||
|
@@ -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) | ||
{ | ||
|
Oops, something went wrong.