13
13
* @category HTTP
14
14
* @package HTTP_Request2
15
15
* @author Alexey Borzov <[email protected] >
16
- * @copyright 2008-2020 Alexey Borzov <[email protected] >
16
+ * @copyright 2008-2022 Alexey Borzov <[email protected] >
17
17
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
18
18
* @link http://pear.php.net/package/HTTP_Request2
19
19
*/
30
30
* @package HTTP_Request2
31
31
* @author Alexey Borzov <[email protected] >
32
32
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
33
- * @version Release: 2.4.2
33
+ * @version Release: 2.5.1
34
34
* @link http://pear.php.net/package/HTTP_Request2
35
35
*/
36
36
class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
37
37
{
38
38
/**
39
39
* Mapping of header names to cURL options
40
- * @var array
40
+ *
41
+ * @var array
41
42
*/
42
43
protected static $ headerMap = [
43
44
'accept-encoding ' => CURLOPT_ENCODING ,
@@ -48,7 +49,8 @@ class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
48
49
49
50
/**
50
51
* Mapping of SSL context options to cURL options
51
- * @var array
52
+ *
53
+ * @var array
52
54
*/
53
55
protected static $ sslContextMap = [
54
56
'ssl_verify_peer ' => CURLOPT_SSL_VERIFYPEER ,
@@ -60,7 +62,8 @@ class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
60
62
61
63
/**
62
64
* Mapping of CURLE_* constants to Exception subclasses and error codes
63
- * @var array
65
+ *
66
+ * @var array
64
67
*/
65
68
protected static $ errorMap = [
66
69
CURLE_UNSUPPORTED_PROTOCOL => ['HTTP_Request2_MessageException ' ,
@@ -100,38 +103,44 @@ class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
100
103
101
104
/**
102
105
* Response being received
103
- * @var HTTP_Request2_Response
106
+ *
107
+ * @var HTTP_Request2_Response
104
108
*/
105
109
protected $ response ;
106
110
107
111
/**
108
112
* Whether 'sentHeaders' event was sent to observers
109
- * @var boolean
113
+ *
114
+ * @var boolean
110
115
*/
111
116
protected $ eventSentHeaders = false ;
112
117
113
118
/**
114
119
* Whether 'receivedHeaders' event was sent to observers
120
+ *
115
121
* @var boolean
116
122
*/
117
123
protected $ eventReceivedHeaders = false ;
118
124
119
125
/**
120
126
* Whether 'sentBoody' event was sent to observers
127
+ *
121
128
* @var boolean
122
129
*/
123
130
protected $ eventSentBody = false ;
124
131
125
132
/**
126
133
* Position within request body
127
- * @var integer
128
- * @see callbackReadBody()
134
+ *
135
+ * @var integer
136
+ * @see callbackReadBody()
129
137
*/
130
138
protected $ position = 0 ;
131
139
132
140
/**
133
141
* Information about last transfer, as returned by curl_getinfo()
134
- * @var array
142
+ *
143
+ * @var array
135
144
*/
136
145
protected $ lastInfo ;
137
146
@@ -161,8 +170,8 @@ protected static function wrapCurlError($ch)
161
170
*
162
171
* @param HTTP_Request2 $request HTTP request message
163
172
*
164
- * @return HTTP_Request2_Response
165
- * @throws HTTP_Request2_Exception
173
+ * @return HTTP_Request2_Response
174
+ * @throws HTTP_Request2_Exception
166
175
*/
167
176
public function sendRequest (HTTP_Request2 $ request )
168
177
{
@@ -208,7 +217,7 @@ public function sendRequest(HTTP_Request2 $request)
208
217
/**
209
218
* Returns information about last transfer
210
219
*
211
- * @return array associative array as returned by curl_getinfo()
220
+ * @return array associative array as returned by curl_getinfo()
212
221
*/
213
222
public function getInfo ()
214
223
{
@@ -218,27 +227,29 @@ public function getInfo()
218
227
/**
219
228
* Creates a new cURL handle and populates it with data from the request
220
229
*
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
224
233
*/
225
234
protected function createCurlHandle ()
226
235
{
227
236
$ ch = curl_init ();
228
237
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
+ );
242
253
243
254
// set up redirects
244
255
if (!$ this ->request ->getConfig ('follow_redirects ' )) {
@@ -399,8 +410,10 @@ protected function createCurlHandle()
399
410
* and setting it as CURLOPT_POSTFIELDS, so it isn't recommended for large
400
411
* file uploads, use Socket adapter instead.
401
412
*
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
404
417
*/
405
418
protected function workaroundPhpBug47204 ($ ch , &$ headers )
406
419
{
@@ -409,7 +422,7 @@ protected function workaroundPhpBug47204($ch, &$headers)
409
422
// https://pear.php.net/bugs/bug.php?id=20440 for PUTs
410
423
if (!$ this ->request ->getConfig ('follow_redirects ' )
411
424
&& (!($ auth = $ this ->request ->getAuth ())
412
- || HTTP_Request2::AUTH_DIGEST != $ auth ['scheme ' ])
425
+ || HTTP_Request2::AUTH_DIGEST != = $ auth ['scheme ' ])
413
426
|| HTTP_Request2::METHOD_POST !== $ this ->request ->getMethod ()
414
427
) {
415
428
curl_setopt ($ ch , CURLOPT_READFUNCTION , [$ this , 'callbackReadBody ' ]);
@@ -439,7 +452,7 @@ protected function workaroundPhpBug47204($ch, &$headers)
439
452
* @param resource $fd file descriptor (not used)
440
453
* @param integer $length maximum length of data to return
441
454
*
442
- * @return string part of the request body, up to $length bytes
455
+ * @return string part of the request body, up to $length bytes
443
456
*/
444
457
protected function callbackReadBody ($ ch , $ fd , $ length )
445
458
{
@@ -472,8 +485,8 @@ protected function callbackReadBody($ch, $fd, $length)
472
485
* @param resource $ch cURL handle
473
486
* @param string $string response header (with trailing CRLF)
474
487
*
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()
477
490
*/
478
491
protected function callbackWriteHeader ($ ch , $ string )
479
492
{
@@ -548,9 +561,9 @@ protected function callbackWriteHeader($ch, $string)
548
561
* @param resource $ch cURL handle (not used)
549
562
* @param string $string part of the response body
550
563
*
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()
554
567
*/
555
568
protected function callbackWriteBody ($ ch , $ string )
556
569
{
0 commit comments