* The debugging information at level 1 includes the raw data returned from the XML-RPC server it was querying
* (including bot HTTP headers and the full XML payload), and the PHP value the client attempts to create to
* represent the value returned by the server.
- * At level2, the complete payload of the xml-rpc request is also printed, before being sent to the server.
+ * At level 2, the complete payload of the xml-rpc request is also printed, before being sent to the server.
+ * At level -1, the Response objects returned by send() calls will not carry information about the http response's
+ * cookies, headers and body, which might save some memory
*
* This option can be very useful when debugging servers as it allows you to see exactly what the client sends and
* the server returns. Never leave it enabled for production!
*
- * @param integer $level values 0, 1 and 2 are supported (2 = echo sent msg too, before received response)
+ * @param integer $level values -1, 0, 1 and 2 are supported
* @return $this
*/
public function setDebug($level)
if ($this->debug > 1) {
curl_setopt($curl, CURLOPT_VERBOSE, true);
- /// @todo allow callers to redirect curlopt_stderr to some stream which can be buffered
+ /// @todo redirect curlopt_stderr to some stream which can be piped to the logger
}
curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
// required for XMLRPC: post the data
*
* @param string $data the http response, headers and body. It will be stripped of headers
* @param bool $headersProcessed when true, we assume that response inflating and dechunking has been already carried out
- * @param int $debug when != 0, logs to screen messages detailing info about the parsed data
+ * @param int $debug when > 0, logs to screen messages detailing info about the parsed data
* @return array with keys 'headers', 'cookies', 'raw_data' and 'status_code'
* @throws HttpException
*
- * @todo if $debug is 0, we could avoid populating 'raw_data' and 'headers' in the returned value - even better, have
- * 2 debug levels
+ * @todo if $debug is < 0, we could avoid populating 'raw_data' and 'headers' in the returned value - but that would
+ * be a weird API...
*/
public function parseResponseHeaders(&$data, $headersProcessed = false, $debug = 0)
{
*/
public function parseResponse($data = '', $headersProcessed = false, $returnType = XMLParser::RETURN_XMLRPCVALS)
{
- if ($this->debug) {
+ if ($this->debug > 0) {
$this->getLogger()->debugMessage("---GOT---\n$data\n---END---");
}
- $this->httpResponse = array('raw_data' => $data, 'headers' => array(), 'cookies' => array());
+ $httpResponse = array('raw_data' => $data, 'headers' => array(), 'cookies' => array());
+ $this->httpResponse = $httpResponse;
if ($data == '') {
$this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': no response received from server.');
if (substr($data, 0, 4) == 'HTTP') {
$httpParser = new Http();
try {
- $this->httpResponse = $httpParser->parseResponseHeaders($data, $headersProcessed, $this->debug);
+ $httpResponse = $httpParser->parseResponseHeaders($data, $headersProcessed, $this->debug > 0);
} catch (HttpException $e) {
// failed processing of HTTP response headers
// save into response obj the full payload received, for debugging
// try to 'guestimate' the character encoding of the received response
$respEncoding = XMLParser::guessEncoding(
- isset($this->httpResponse['headers']['content-type']) ? $this->httpResponse['headers']['content-type'] : '',
+ isset($httpResponse['headers']['content-type']) ? $httpResponse['headers']['content-type'] : '',
$data
);
- if ($this->debug) {
+ if ($this->debug >= 0) {
+ $this->httpResponse = $httpResponse;
+ } else {
+ $httpResponse = null;
+ }
+
+ if ($this->debug > 0) {
$start = strpos($data, '<!-- SERVER DEBUG INFO (BASE64 ENCODED):');
if ($start) {
$start += strlen('<!-- SERVER DEBUG INFO (BASE64 ENCODED):');
// if the user wants back raw xml, give it to her
if ($returnType == 'xml') {
- return new Response($data, 0, '', 'xml', $this->httpResponse);
+ return new Response($data, 0, '', 'xml', $httpResponse);
}
/// @todo move this block of code into the XMLParser
$r = new Response(0, PhpXmlRpc::$xmlrpcerr['invalid_xml'],
PhpXmlRpc::$xmlrpcstr['invalid_xml'] . ' ' . $xmlRpcParser->_xh['isf_reason'], '',
- $this->httpResponse
+ $httpResponse
);
- if ($this->debug) {
+ if ($this->debug > 0) {
$this->getLogger()->debugMessage($xmlRpcParser->_xh['isf_reason']);
}
}
elseif ($xmlRpcParser->_xh['isf'] == 2) {
$r = new Response(0, PhpXmlRpc::$xmlrpcerr['xml_not_compliant'],
PhpXmlRpc::$xmlrpcstr['xml_not_compliant'] . ' ' . $xmlRpcParser->_xh['isf_reason'], '',
- $this->httpResponse
+ $httpResponse
);
- if ($this->debug) {
- /// @todo echo something for user?
- }
+ /// @todo echo something for the user? check if this was already done by the parser...
+ //if ($this->debug > 0) {
+ // $this->getLogger()->debugMessage($xmlRpcParser->_xh['isf_reason']);
+ //}
}
// third error check: parsing of the response has somehow gone boink.
/// @todo shall we omit this check, since we trust the parsing code?
elseif ($xmlRpcParser->_xh['isf'] > 3 || $returnType == XMLParser::RETURN_XMLRPCVALS && !is_object($xmlRpcParser->_xh['value'])) {
// something odd has happened and it's time to generate a client side error indicating something odd went on
$r = new Response(0, PhpXmlRpc::$xmlrpcerr['xml_parsing_error'], PhpXmlRpc::$xmlrpcstr['xml_parsing_error'],
- '', $this->httpResponse
+ '', $httpResponse
);
+
+ /// @todo echo something for the user?
} else {
if ($this->debug > 1) {
$this->getLogger()->debugMessage(
$errNo = -1;
}
- $r = new Response(0, $errNo, $errStr, '', $this->httpResponse);
+ $r = new Response(0, $errNo, $errStr, '', $httpResponse);
} else {
- $r = new Response($v, 0, '', $returnType, $this->httpResponse);
+ $r = new Response($v, 0, '', $returnType, $httpResponse);
}
}
/**
* Enables/disables the echoing to screen of the xml-rpc responses received.
*
- * @param integer $level values 0, 1, 2 are supported
+ * @param integer $level values <0, 0, 1, >1 are supported
* @return $this
*/
public function setDebug($level)
* @param string $fString the error string, in case of an error response
* @param string $valType The type of $val passed in. Either 'xmlrpcvals', 'phpvals' or 'xml'. Leave empty to let
* the code guess the correct type.
- * @param array|null $httpResponse
+ * @param array|null $httpResponse this should be set when the response is being built out of data received from
+ * http (i.e. not when programmatically building a Response server-side). Array
+ * keys should include, if known: headers, cookies, raw_data, status_code
*
* @todo add check that $val / $fCode / $fString is of correct type???
* NB: as of now we do not do it, since it might be either an xml-rpc value or a plain php val, or a complete
- * xml chunk, depending on usage of Client::send() inside which creator is called...
+ * xml chunk, depending on usage of Client::send() inside which the constructor is called...
*/
public function __construct($val, $fCode = 0, $fString = '', $valType = '', $httpResponse = null)
{
* with attributes being e.g. 'expires', 'path', domain'.
* NB: cookies sent as 'expired' by the server (i.e. with an expiry date in the past) are still present in the array.
* It is up to the user-defined code to decide how to use the received cookies, and whether they have to be sent back
- * with the next request to the server (using Client::setCookie) or not.
+ * with the next request to the server (using $client->setCookie) or not.
+ * The values are filled in at constructor time, and might not be set for specific debug values used.
*
* @return array[] array of cookies received from the server
*/
}
/**
- * @return array array with keys 'headers', 'cookies', 'raw_data' and 'status_code'
+ * Returns an array with info about the http response received from the server.
+ * The values are filled in at constructor time, and might not be set for specific debug values used.
+ *
+ * @return array array with keys 'headers', 'cookies', 'raw_data' and 'status_code'.
*/
public function httpResponse()
{
* 3 = add also all processing warnings happened during method processing
* (NB: this involves setting a custom error handler, and might interfere
* with the standard processing of the php function exposed as method. In
- * particular, triggering an USER_ERROR level error will not halt script
+ * particular, triggering a USER_ERROR level error will not halt script
* execution anymore, but just end up logged in the xml-rpc response)
* Note that info added at level 2 and 3 will be base64 encoded
* @return $this