Skip to content

Commit 4e4777e

Browse files
authored
Update PEAR HTTP_Request2 package to version 2.5.1 (phpList#921)
1 parent f6d238a commit 4e4777e

17 files changed

+482
-301
lines changed

public_html/lists/admin/PEAR/HTTP/Request2.php

+104-70
Large diffs are not rendered by default.

public_html/lists/admin/PEAR/HTTP/Request2/Adapter.php

+18-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @category HTTP
1414
* @package HTTP_Request2
1515
* @author Alexey Borzov <[email protected]>
16-
* @copyright 2008-2020 Alexey Borzov <[email protected]>
16+
* @copyright 2008-2022 Alexey Borzov <[email protected]>
1717
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
1818
* @link http://pear.php.net/package/HTTP_Request2
1919
*/
@@ -34,14 +34,15 @@
3434
* @package HTTP_Request2
3535
* @author Alexey Borzov <[email protected]>
3636
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
37-
* @version Release: 2.4.2
37+
* @version Release: 2.5.1
3838
* @link http://pear.php.net/package/HTTP_Request2
3939
*/
4040
abstract class HTTP_Request2_Adapter
4141
{
4242
/**
4343
* A list of methods that MUST NOT have a request body, per RFC 2616
44-
* @var array
44+
*
45+
* @var array
4546
*/
4647
protected static $bodyDisallowed = ['TRACE'];
4748

@@ -59,20 +60,23 @@ abstract class HTTP_Request2_Adapter
5960

6061
/**
6162
* Request being sent
62-
* @var HTTP_Request2
63+
*
64+
* @var HTTP_Request2
6365
*/
6466
protected $request;
6567

6668
/**
6769
* Request body
68-
* @var string|resource|HTTP_Request2_MultipartBody
69-
* @see HTTP_Request2::getBody()
70+
*
71+
* @var string|resource|HTTP_Request2_MultipartBody
72+
* @see HTTP_Request2::getBody()
7073
*/
7174
protected $requestBody;
7275

7376
/**
7477
* Length of the request body
75-
* @var integer
78+
*
79+
* @var integer
7680
*/
7781
protected $contentLength;
7882

@@ -81,17 +85,19 @@ abstract class HTTP_Request2_Adapter
8185
*
8286
* @param HTTP_Request2 $request HTTP request message
8387
*
84-
* @return HTTP_Request2_Response
85-
* @throws HTTP_Request2_Exception
88+
* @return HTTP_Request2_Response
89+
* @throws HTTP_Request2_Exception
8690
*/
8791
abstract public function sendRequest(HTTP_Request2 $request);
8892

8993
/**
9094
* Calculates length of the request body, adds proper headers
9195
*
92-
* @param array &$headers associative array of request headers, this method
93-
* will add proper 'Content-Length' and 'Content-Type'
94-
* headers to this array (or remove them if not needed)
96+
* @param array $headers associative array of request headers, this method
97+
* will add proper 'Content-Length' and 'Content-Type'
98+
* headers to this array (or remove them if not needed)
99+
*
100+
* @return void
95101
*/
96102
protected function calculateRequestLength(&$headers)
97103
{

public_html/lists/admin/PEAR/HTTP/Request2/Adapter/Curl.php

+51-38
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @category HTTP
1414
* @package HTTP_Request2
1515
* @author Alexey Borzov <[email protected]>
16-
* @copyright 2008-2020 Alexey Borzov <[email protected]>
16+
* @copyright 2008-2022 Alexey Borzov <[email protected]>
1717
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
1818
* @link http://pear.php.net/package/HTTP_Request2
1919
*/
@@ -30,14 +30,15 @@
3030
* @package HTTP_Request2
3131
* @author Alexey Borzov <[email protected]>
3232
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
33-
* @version Release: 2.4.2
33+
* @version Release: 2.5.1
3434
* @link http://pear.php.net/package/HTTP_Request2
3535
*/
3636
class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
3737
{
3838
/**
3939
* Mapping of header names to cURL options
40-
* @var array
40+
*
41+
* @var array
4142
*/
4243
protected static $headerMap = [
4344
'accept-encoding' => CURLOPT_ENCODING,
@@ -48,7 +49,8 @@ class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
4849

4950
/**
5051
* Mapping of SSL context options to cURL options
51-
* @var array
52+
*
53+
* @var array
5254
*/
5355
protected static $sslContextMap = [
5456
'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER,
@@ -60,7 +62,8 @@ class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
6062

6163
/**
6264
* Mapping of CURLE_* constants to Exception subclasses and error codes
63-
* @var array
65+
*
66+
* @var array
6467
*/
6568
protected static $errorMap = [
6669
CURLE_UNSUPPORTED_PROTOCOL => ['HTTP_Request2_MessageException',
@@ -100,38 +103,44 @@ class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
100103

101104
/**
102105
* Response being received
103-
* @var HTTP_Request2_Response
106+
*
107+
* @var HTTP_Request2_Response
104108
*/
105109
protected $response;
106110

107111
/**
108112
* Whether 'sentHeaders' event was sent to observers
109-
* @var boolean
113+
*
114+
* @var boolean
110115
*/
111116
protected $eventSentHeaders = false;
112117

113118
/**
114119
* Whether 'receivedHeaders' event was sent to observers
120+
*
115121
* @var boolean
116122
*/
117123
protected $eventReceivedHeaders = false;
118124

119125
/**
120126
* Whether 'sentBoody' event was sent to observers
127+
*
121128
* @var boolean
122129
*/
123130
protected $eventSentBody = false;
124131

125132
/**
126133
* Position within request body
127-
* @var integer
128-
* @see callbackReadBody()
134+
*
135+
* @var integer
136+
* @see callbackReadBody()
129137
*/
130138
protected $position = 0;
131139

132140
/**
133141
* Information about last transfer, as returned by curl_getinfo()
134-
* @var array
142+
*
143+
* @var array
135144
*/
136145
protected $lastInfo;
137146

@@ -161,8 +170,8 @@ protected static function wrapCurlError($ch)
161170
*
162171
* @param HTTP_Request2 $request HTTP request message
163172
*
164-
* @return HTTP_Request2_Response
165-
* @throws HTTP_Request2_Exception
173+
* @return HTTP_Request2_Response
174+
* @throws HTTP_Request2_Exception
166175
*/
167176
public function sendRequest(HTTP_Request2 $request)
168177
{
@@ -208,7 +217,7 @@ public function sendRequest(HTTP_Request2 $request)
208217
/**
209218
* Returns information about last transfer
210219
*
211-
* @return array associative array as returned by curl_getinfo()
220+
* @return array associative array as returned by curl_getinfo()
212221
*/
213222
public function getInfo()
214223
{
@@ -218,27 +227,29 @@ public function getInfo()
218227
/**
219228
* Creates a new cURL handle and populates it with data from the request
220229
*
221-
* @return resource a cURL handle, as created by curl_init()
222-
* @throws HTTP_Request2_LogicException
223-
* @throws HTTP_Request2_NotImplementedException
230+
* @return resource a cURL handle, as created by curl_init()
231+
* @throws HTTP_Request2_LogicException
232+
* @throws HTTP_Request2_NotImplementedException
224233
*/
225234
protected function createCurlHandle()
226235
{
227236
$ch = curl_init();
228237

229-
curl_setopt_array($ch, [
230-
// setup write callbacks
231-
CURLOPT_HEADERFUNCTION => [$this, 'callbackWriteHeader'],
232-
CURLOPT_WRITEFUNCTION => [$this, 'callbackWriteBody'],
233-
// buffer size
234-
CURLOPT_BUFFERSIZE => $this->request->getConfig('buffer_size'),
235-
// connection timeout
236-
CURLOPT_CONNECTTIMEOUT => $this->request->getConfig('connect_timeout'),
237-
// save full outgoing headers, in case someone is interested
238-
CURLINFO_HEADER_OUT => true,
239-
// request url
240-
CURLOPT_URL => $this->request->getUrl()->getUrl()
241-
]);
238+
curl_setopt_array(
239+
$ch, [
240+
// setup write callbacks
241+
CURLOPT_HEADERFUNCTION => [$this, 'callbackWriteHeader'],
242+
CURLOPT_WRITEFUNCTION => [$this, 'callbackWriteBody'],
243+
// buffer size
244+
CURLOPT_BUFFERSIZE => $this->request->getConfig('buffer_size'),
245+
// connection timeout
246+
CURLOPT_CONNECTTIMEOUT => $this->request->getConfig('connect_timeout'),
247+
// save full outgoing headers, in case someone is interested
248+
CURLINFO_HEADER_OUT => true,
249+
// request url
250+
CURLOPT_URL => $this->request->getUrl()->getUrl()
251+
]
252+
);
242253

243254
// set up redirects
244255
if (!$this->request->getConfig('follow_redirects')) {
@@ -399,8 +410,10 @@ protected function createCurlHandle()
399410
* and setting it as CURLOPT_POSTFIELDS, so it isn't recommended for large
400411
* file uploads, use Socket adapter instead.
401412
*
402-
* @param resource $ch cURL handle
403-
* @param array &$headers Request headers
413+
* @param resource $ch cURL handle
414+
* @param array $headers Request headers
415+
*
416+
* @return void
404417
*/
405418
protected function workaroundPhpBug47204($ch, &$headers)
406419
{
@@ -409,7 +422,7 @@ protected function workaroundPhpBug47204($ch, &$headers)
409422
// https://pear.php.net/bugs/bug.php?id=20440 for PUTs
410423
if (!$this->request->getConfig('follow_redirects')
411424
&& (!($auth = $this->request->getAuth())
412-
|| HTTP_Request2::AUTH_DIGEST != $auth['scheme'])
425+
|| HTTP_Request2::AUTH_DIGEST !== $auth['scheme'])
413426
|| HTTP_Request2::METHOD_POST !== $this->request->getMethod()
414427
) {
415428
curl_setopt($ch, CURLOPT_READFUNCTION, [$this, 'callbackReadBody']);
@@ -439,7 +452,7 @@ protected function workaroundPhpBug47204($ch, &$headers)
439452
* @param resource $fd file descriptor (not used)
440453
* @param integer $length maximum length of data to return
441454
*
442-
* @return string part of the request body, up to $length bytes
455+
* @return string part of the request body, up to $length bytes
443456
*/
444457
protected function callbackReadBody($ch, $fd, $length)
445458
{
@@ -472,8 +485,8 @@ protected function callbackReadBody($ch, $fd, $length)
472485
* @param resource $ch cURL handle
473486
* @param string $string response header (with trailing CRLF)
474487
*
475-
* @return integer number of bytes saved
476-
* @see HTTP_Request2_Response::parseHeaderLine()
488+
* @return integer number of bytes saved
489+
* @see HTTP_Request2_Response::parseHeaderLine()
477490
*/
478491
protected function callbackWriteHeader($ch, $string)
479492
{
@@ -548,9 +561,9 @@ protected function callbackWriteHeader($ch, $string)
548561
* @param resource $ch cURL handle (not used)
549562
* @param string $string part of the response body
550563
*
551-
* @return integer number of bytes saved
552-
* @throws HTTP_Request2_MessageException
553-
* @see HTTP_Request2_Response::appendBody()
564+
* @return integer number of bytes saved
565+
* @throws HTTP_Request2_MessageException
566+
* @see HTTP_Request2_Response::appendBody()
554567
*/
555568
protected function callbackWriteBody($ch, $string)
556569
{

public_html/lists/admin/PEAR/HTTP/Request2/Adapter/Mock.php

+14-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @category HTTP
1414
* @package HTTP_Request2
1515
* @author Alexey Borzov <[email protected]>
16-
* @copyright 2008-2020 Alexey Borzov <[email protected]>
16+
* @copyright 2008-2022 Alexey Borzov <[email protected]>
1717
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
1818
* @link http://pear.php.net/package/HTTP_Request2
1919
*/
@@ -44,14 +44,15 @@
4444
* @package HTTP_Request2
4545
* @author Alexey Borzov <[email protected]>
4646
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
47-
* @version Release: 2.4.2
47+
* @version Release: 2.5.1
4848
* @link http://pear.php.net/package/HTTP_Request2
4949
*/
5050
class HTTP_Request2_Adapter_Mock extends HTTP_Request2_Adapter
5151
{
5252
/**
5353
* A queue of responses to be returned by sendRequest()
54-
* @var array
54+
*
55+
* @var array
5556
*/
5657
protected $responses = [];
5758

@@ -65,8 +66,8 @@ class HTTP_Request2_Adapter_Mock extends HTTP_Request2_Adapter
6566
*
6667
* @param HTTP_Request2 $request HTTP request message
6768
*
68-
* @return HTTP_Request2_Response
69-
* @throws Exception
69+
* @return HTTP_Request2_Response
70+
* @throws Exception
7071
*/
7172
public function sendRequest(HTTP_Request2 $request)
7273
{
@@ -102,16 +103,17 @@ public function sendRequest(HTTP_Request2 $request)
102103
* @param string $url A request URL this response should be valid for
103104
* (see {@link http://pear.php.net/bugs/bug.php?id=19276})
104105
*
105-
* @throws HTTP_Request2_Exception
106+
* @return void
107+
* @throws HTTP_Request2_Exception
106108
*/
107109
public function addResponse($response, $url = null)
108110
{
109111
if (is_string($response)) {
110112
$response = self::createResponseFromString($response);
111113
} elseif (is_resource($response)) {
112114
$response = self::createResponseFromFile($response);
113-
} elseif (!$response instanceof HTTP_Request2_Response &&
114-
!$response instanceof Exception
115+
} elseif (!$response instanceof HTTP_Request2_Response
116+
&& !$response instanceof Exception
115117
) {
116118
throw new HTTP_Request2_Exception('Parameter is not a valid response');
117119
}
@@ -123,8 +125,8 @@ public function addResponse($response, $url = null)
123125
*
124126
* @param string $str string containing HTTP response message
125127
*
126-
* @return HTTP_Request2_Response
127-
* @throws HTTP_Request2_Exception
128+
* @return HTTP_Request2_Response
129+
* @throws HTTP_Request2_Exception
128130
*/
129131
public static function createResponseFromString($str)
130132
{
@@ -146,8 +148,8 @@ public static function createResponseFromString($str)
146148
*
147149
* @param resource $fp file pointer returned by fopen()
148150
*
149-
* @return HTTP_Request2_Response
150-
* @throws HTTP_Request2_Exception
151+
* @return HTTP_Request2_Response
152+
* @throws HTTP_Request2_Exception
151153
*/
152154
public static function createResponseFromFile($fp)
153155
{

0 commit comments

Comments
 (0)