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 */
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 */
3636class 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 {
0 commit comments