svn: /pear/packages/XML_RPC2/trunk/ XML/RPC2/Util/HTTPRequest.php tests/XML_RPC2/phpBackend/client/protocolError.phpt
tests/XML_RPC2/xmlrpcextBackend/client/protocolError.phpt
| From: | Sergio Carvalho | Date: | Thu, 24 Feb 2011 22:54:39 +0000 |
| Subject: | svn: /pear/packages/XML_RPC2/trunk/ XML/RPC2/Util/HTTPRequest.php tests/XML_RPC2/phpBackend/client/protocolError.phpt tests/XML_RPC2/xmlrpcextBackend/client/protocolError.phpt |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-61257@lists.php.net to get a copy of this message | ||
sergiosgc Thu, 24 Feb 2011 22:54:39 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=308648
Log:
Request #15068 Use HTTP_Request2 rather than cURL
Bug: http://pear.php.net/bugs/15068 (unknown)
Changed paths:
U pear/packages/XML_RPC2/trunk/XML/RPC2/Util/HTTPRequest.php
U pear/packages/XML_RPC2/trunk/tests/XML_RPC2/phpBackend/client/protocolError.phpt
U pear/packages/XML_RPC2/trunk/tests/XML_RPC2/xmlrpcextBackend/client/protocolError.phpt
Modified: pear/packages/XML_RPC2/trunk/XML/RPC2/Util/HTTPRequest.php
===================================================================
--- pear/packages/XML_RPC2/trunk/XML/RPC2/Util/HTTPRequest.php 2011-02-24 22:14:56 UTC (rev 308647)
+++ pear/packages/XML_RPC2/trunk/XML/RPC2/Util/HTTPRequest.php 2011-02-24 22:54:39 UTC (rev 308648)
@@ -42,6 +42,7 @@
// dependencies {{{
require_once 'XML/RPC2/Exception.php';
require_once 'XML/RPC2/Client.php';
+require_once 'HTTP/Request2.php';
// }}}
/**
@@ -51,7 +52,7 @@
* @category XML
* @package XML_RPC2
* @author Sergio Carvalho <sergio.carvalho@portugalmail.com>
- * @copyright 2004-2006 Sergio Carvalho
+ * @copyright 2004-2011 Sergio Carvalho
* @license http://www.gnu.org/copyleft/lesser.html LGPL
License 2.1
* @link http://pear.php.net/package/XML_RPC2
*/
@@ -193,31 +194,67 @@
*/
public function sendRequest()
{
+ $request = new HTTP_Request2($this->_uri, HTTP_Request2::METHOD_POST);
+ if (isset($params['proxy'])) {
+ $elements = parse_url($params['proxy']);
+ if (is_array($elements)) {
+ if ((isset($elements['scheme'])) and
(isset($elements['host']))) {
+ $request->setConfig('proxy_host', $elements['host']);
+ }
+ if (isset($elements['port'])) {
+ $request->setConfig('proxy_port', $elements['port']);
+ }
+ if ((isset($elements['user'])) and (isset($elements['pass'])))
{
+ $request->setConfig('proxy_user', $elements['user']);
+ $request->setConfig('proxy_password',
$elements['pass']);
+ }
+ }
+ }
+ $request->setConfig('ssl_verify_peer', $this->_sslverify);
+ $request->setConfig('ssl_verify_host', $this->_sslverify);
+ $request->setHeader('Content-type: text/xml; charset='.$this->_encoding);
+ $request->setHeader('User-Agent: PEAR::XML_RPC2/@package_version@');
+ $request->setBody($this->_postData);
+ if (isset($this->_connectionTimeout)) $request->setConfig('timeout', (int)
($this->_connectionTimeout / 1000));
+ try {
+ $result = $request->send();
+ if ($result->getStatus() != 200) throw new
XML_RPC2_ReceivedInvalidStatusCodeException('Received non-200 HTTP Code: ' .
$request->getStatus() . '. Response body:' . $result->getBody());
+
+ } catch (HTTP_Request2_Exception $e) {
+ throw new XML_RPC2_CurlException($e);
+ }
+ $this->_body = $result->getBody();
+ return $result->getBody();
+
+
+
+
+/*
if (!function_exists('curl_init') &&
!( PEAR::loadExtension('php_curl') )) {
throw new XML_RPC2_CurlException('cURI extension is not present and load
failed');
}
if ($ch = curl_init()) {
if (
- (is_null($this->_proxy) || curl_setopt($ch, CURLOPT_PROXY,
$this->_proxy)) &&
- (is_null($this->_proxyAuth) || curl_setopt($ch, CURLOPT_PROXYUSERPWD,
$this->_proxyAuth)) &&
- curl_setopt($ch, CURLOPT_URL, $this->_uri) &&
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE) &&
- curl_setopt($ch, CURLOPT_POST, 1) &&
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->_sslverify) &&
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->_sslverify) &&
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml;
charset='.$this->_encoding, 'User-Agent: PEAR::XML_RPC2/@package_version@'))
&&
- curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_postData) &&
- (!isset($this->_connectionTimeout) || curl_setopt($ch,
CURLOPT_CONNECTTIMEOUT_MS, $this->_connectionTimeout))
+// (is_null($this->_proxy) || curl_setopt($ch, CURLOPT_PROXY,
$this->_proxy)) &&
+// (is_null($this->_proxyAuth) || curl_setopt($ch, CURLOPT_PROXYUSERPWD,
$this->_proxyAuth)) &&
+// curl_setopt($ch, CURLOPT_URL, $this->_uri) &&
+//? curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE) &&
+// curl_setopt($ch, CURLOPT_POST, 1) &&
+// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->_sslverify) &&
+// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->_sslverify) &&
+// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml;
charset='.$this->_encoding, 'User-Agent: PEAR::XML_RPC2/@package_version@'))
&&
+// curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_postData) &&
+// (!isset($this->_connectionTimeout) || curl_setopt($ch,
CURLOPT_CONNECTTIMEOUT_MS, $this->_connectionTimeout))
) {
$result = curl_exec($ch);
- if (($errno = curl_errno($ch)) != 0) {
- throw new XML_RPC2_CurlException("Curl returned non-null errno
$errno:" . curl_error($ch), $errno);
+// if (($errno = curl_errno($ch)) != 0) {
+// throw new XML_RPC2_CurlException("Curl returned non-null errno
$errno:" . curl_error($ch), $errno);
+// }
+// $info = curl_getinfo($ch);
+// if ($info['http_code'] != 200) {
+// throw new XML_RPC2_ReceivedInvalidStatusCodeException('Curl returned non
200 HTTP code: ' . $info['http_code'] . '. Response body:' . $result,
$info['http_code']);
}
- $info = curl_getinfo($ch);
- if ($info['http_code'] != 200) {
- throw new XML_RPC2_ReceivedInvalidStatusCodeException('Curl returned non
200 HTTP code: ' . $info['http_code'] . '. Response body:' . $result,
$info['http_code']);
- }
} else {
throw new XML_RPC2_CurlException('Unable to setup curl');
}
@@ -226,6 +263,7 @@
}
$this->_body = $result;
return true;
+ */
}
// }}}
Modified: pear/packages/XML_RPC2/trunk/tests/XML_RPC2/phpBackend/client/protocolError.phpt
===================================================================
--- pear/packages/XML_RPC2/trunk/tests/XML_RPC2/phpBackend/client/protocolError.phpt 2011-02-24
22:14:56 UTC (rev 308647)
+++ pear/packages/XML_RPC2/trunk/tests/XML_RPC2/phpBackend/client/protocolError.phpt 2011-02-24
22:54:39 UTC (rev 308648)
@@ -20,4 +20,4 @@
}
?>
--EXPECTREGEX--
-string\(.*\) \"Curl returned non-null errno.*
+string\(.*\) \"HTTP_Request2_Exception.*
Modified: pear/packages/XML_RPC2/trunk/tests/XML_RPC2/xmlrpcextBackend/client/protocolError.phpt
===================================================================
---
pear/packages/XML_RPC2/trunk/tests/XML_RPC2/xmlrpcextBackend/client/protocolError.phpt 2011-02-24
22:14:56 UTC (rev 308647)
+++
pear/packages/XML_RPC2/trunk/tests/XML_RPC2/xmlrpcextBackend/client/protocolError.phpt 2011-02-24
22:54:39 UTC (rev 308648)
@@ -22,5 +22,5 @@
var_dump($e->getMessage());
}
?>
---EXPECT--
-string(70) "Curl returned non-null errno 6:Couldn't resolve host
'rpc.example.com'"
+--EXPECTREGEX--
+string\(.*\) \"HTTP_Request2_Exception.*