From ba8c928154d9f130b6109ec3745cd10bf85e2290 Mon Sep 17 00:00:00 2001 From: Florian Traverse Date: Wed, 24 Feb 2016 14:23:23 +0100 Subject: [PATCH 1/2] support DEBUG="xmlrpc:*" (etc.) in order to easily get input/output --- lib/client.js | 4 ++- lib/deserializer.js | 15 ++++----- lib/serializer.js | 14 +++++++-- lib/server.js | 2 +- package.json | 76 +++++++++++++++++++++++++-------------------- 5 files changed, 65 insertions(+), 46 deletions(-) diff --git a/lib/client.js b/lib/client.js index b875461..690c59f 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,6 +1,7 @@ var http = require('http') , https = require('https') , url = require('url') + , debug = require('debug')('xmlrpc:client') , Serializer = require('./serializer') , Deserializer = require('./deserializer') , Cookies = require('./cookies') @@ -112,6 +113,7 @@ Client.prototype.methodCall = function methodCall(method, params, callback) { Object.defineProperty(err, 'req', { value: request }) Object.defineProperty(err, 'res', { value: response }) Object.defineProperty(err, 'body', { value: body.join('') }) + debug(err); return err } @@ -119,6 +121,7 @@ Client.prototype.methodCall = function methodCall(method, params, callback) { callback(__enrichError(new Error('Not Found'))) } else { + debug("headers", response.headers); this.headersProcessors.parseResponse(response.headers) var deserializer = new Deserializer(options.responseEncoding) @@ -174,4 +177,3 @@ Client.prototype.setCookie = function setCookie(name, value) { } module.exports = Client - diff --git a/lib/deserializer.js b/lib/deserializer.js index 819356a..39fc141 100644 --- a/lib/deserializer.js +++ b/lib/deserializer.js @@ -1,4 +1,7 @@ var sax = require('sax') + , debug = require('debug')('xmlrpc:deserializer') + , debugClient = require('debug-stream')(require('debug')('xmlrpc:client:response:stream')) + , debugServer = require('debug-stream')(require('debug')('xmlrpc:server:request:stream')) , dateFormatter = require('./date_formatter') var Deserializer = function(encoding) { @@ -45,7 +48,7 @@ Deserializer.prototype.deserializeMethodResponse = function(stream, callback) { stream.setEncoding(this.encoding) stream.on('error', this.onError.bind(this)) - stream.pipe(this.parser) + stream.pipe(debugClient('%s')).pipe(this.parser) } Deserializer.prototype.deserializeMethodCall = function(stream, callback) { @@ -68,12 +71,11 @@ Deserializer.prototype.deserializeMethodCall = function(stream, callback) { stream.setEncoding(this.encoding) stream.on('error', this.onError.bind(this)) - stream.pipe(this.parser) + stream.pipe(debugServer('%s')).pipe(this.parser) } Deserializer.prototype.onDone = function() { var that = this - if (!this.error) { if (this.type === null || this.marks.length) { this.callback(new Error('Invalid XML-RPC message')) @@ -96,13 +98,13 @@ Deserializer.prototype.onDone = function() { // TODO: // Error handling needs a little thinking. There are two different kinds of -// errors: +// errors: // 1. Low level errors like network, stream or xml errors. These don't // require special treatment. They only need to be forwarded. The IO -// is already stopped in these cases. +// is already stopped in these cases. // 2. Protocol errors: Invalid tags, invalid values &c. These happen in // our code and we should tear down the IO and stop parsing. -// Currently all errors end here. Guess I'll split it up. +// Currently all errors end here. Guess I'll split it up. Deserializer.prototype.onError = function(msg) { if (!this.error) { if (typeof msg === 'string') { @@ -321,4 +323,3 @@ Deserializer.prototype.endMethodCall = function(data) { } module.exports = Deserializer - diff --git a/lib/serializer.js b/lib/serializer.js index a1fdc23..7a90b87 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -1,4 +1,5 @@ var xmlBuilder = require('xmlbuilder') + , debug = require('debug')('xmlrpc:serializer') , dateFormatter = require('./date_formatter') , CustomType = require('./customtype') @@ -21,6 +22,7 @@ exports.serializeMethodCall = function(method, params, encoding) { options.encoding = encoding } + debug('call method <'+method+'>('+(encoding || 'utf8')+')', params) var xml = xmlBuilder.create('methodCall', options) .ele('methodName') .txt(method) @@ -32,7 +34,9 @@ exports.serializeMethodCall = function(method, params, encoding) { }) // Includes the declaration - return xml.doc().toString() + var str = xml.doc().toString() + debug('method <'+method+'> call body XML', params) + return str } /** @@ -52,7 +56,9 @@ exports.serializeMethodResponse = function(result) { serializeValue(result, xml) // Includes the declaration - return xml.doc().toString() + var str = xml.doc().toString(); + debug('method response:'+str) + return str } exports.serializeFault = function(fault) { @@ -62,7 +68,9 @@ exports.serializeFault = function(fault) { serializeValue(fault, xml) // Includes the declaration - return xml.doc().toString() + var str = xml.doc().toString(); + debug('fault: '+str); + return str } function serializeValue(value, xml) { diff --git a/lib/server.js b/lib/server.js index baef3b6..ad8b1f7 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,6 +1,7 @@ var http = require('http') , https = require('https') , url = require('url') + , debug = require('debug')('xmlrpc:server') , EventEmitter = require('events').EventEmitter , Serializer = require('./serializer') , Deserializer = require('./deserializer') @@ -75,4 +76,3 @@ function Server(options, isSecure, onListening) { Server.prototype.__proto__ = EventEmitter.prototype module.exports = Server - diff --git a/package.json b/package.json index bea1d64..80bccb2 100644 --- a/package.json +++ b/package.json @@ -1,35 +1,43 @@ -{ "name" : "xmlrpc" -, "description" : "A pure JavaScript XML-RPC client and server." -, "keywords" : [ "xml-rpc", "xmlrpc", "xml", "rpc" ] -, "version" : "1.3.1" -, "preferGlobal" : false -, "homepage" : "https://github.com/baalexander/node-xmlrpc" -, "author" : "Brandon Alexander (https://github.com/baalexander)" -, "repository" : { - "type" : "git" - , "url" : "git://github.com/baalexander/node-xmlrpc.git" - } -, "bugs" : { - "url" : "https://github.com/baalexander/node-xmlrpc/issues" - } -, "directories" : { - "lib" : "./lib" - } -, "main" : "./lib/xmlrpc.js" -, "dependencies" : { - "sax" : "0.6.x" - , "xmlbuilder" : "2.6.x" - } -, "devDependencies" : { - "vows" : "0.7.x" - } -, "scripts" : { - "test" : "vows 'test/*.js'" - } -, "engines" : { - "node" : ">=0.8", - "npm" : ">=1.0.0" - } -, "license" : "MIT" +{ + "name": "xmlrpc", + "description": "A pure JavaScript XML-RPC client and server.", + "keywords": [ + "xml-rpc", + "xmlrpc", + "xml", + "rpc" + ], + "version": "1.3.1", + "preferGlobal": false, + "homepage": "https://github.com/baalexander/node-xmlrpc", + "author": "Brandon Alexander (https://github.com/baalexander)", + "repository": { + "type": "git", + "url": "git://github.com/baalexander/node-xmlrpc.git" + }, + "bugs": { + "url": "https://github.com/baalexander/node-xmlrpc/issues" + }, + "directories": { + "lib": "./lib" + }, + "main": "./lib/xmlrpc.js", + "dependencies": { + "debug": "^2.2.0", + "debug-stream": "^3.0.1", + "sax": "0.6.x", + "xmlbuilder": "2.6.x" + }, + "devDependencies": { + "vows": "0.7.x" + }, + "scripts": { + "test": "vows 'test/*.js'" + }, + "engines": { + "node": ">=0.8", + "npm": ">=1.0.0" + }, + "contributors": [], + "license": "MIT" } - From ba6f209dd904d4ea7458f9b9708a569e28576104 Mon Sep 17 00:00:00 2001 From: Florian Traverse Date: Wed, 24 Feb 2016 15:02:24 +0100 Subject: [PATCH 2/2] small fix ( was returning params rather than body in serializer) --- lib/serializer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/serializer.js b/lib/serializer.js index 7a90b87..e19f895 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -35,7 +35,7 @@ exports.serializeMethodCall = function(method, params, encoding) { // Includes the declaration var str = xml.doc().toString() - debug('method <'+method+'> call body XML', params) + debug('method <'+method+'> call body XML', str) return str }