Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -112,13 +113,15 @@ 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
}

if (response.statusCode == 404) {
callback(__enrichError(new Error('Not Found')))
}
else {
debug("headers", response.headers);
this.headersProcessors.parseResponse(response.headers)

var deserializer = new Deserializer(options.responseEncoding)
Expand Down Expand Up @@ -174,4 +177,3 @@ Client.prototype.setCookie = function setCookie(name, value) {
}

module.exports = Client

15 changes: 8 additions & 7 deletions lib/deserializer.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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'))
Expand All @@ -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') {
Expand Down Expand Up @@ -321,4 +323,3 @@ Deserializer.prototype.endMethodCall = function(data) {
}

module.exports = Deserializer

14 changes: 11 additions & 3 deletions lib/serializer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var xmlBuilder = require('xmlbuilder')
, debug = require('debug')('xmlrpc:serializer')
, dateFormatter = require('./date_formatter')
, CustomType = require('./customtype')

Expand All @@ -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)
Expand All @@ -32,7 +34,9 @@ exports.serializeMethodCall = function(method, params, encoding) {
})

// Includes the <?xml ...> declaration
return xml.doc().toString()
var str = xml.doc().toString()
debug('method <'+method+'> call body XML', str)
return str
}

/**
Expand All @@ -52,7 +56,9 @@ exports.serializeMethodResponse = function(result) {
serializeValue(result, xml)

// Includes the <?xml ...> declaration
return xml.doc().toString()
var str = xml.doc().toString();
debug('method response:'+str)
return str
}

exports.serializeFault = function(fault) {
Expand All @@ -62,7 +68,9 @@ exports.serializeFault = function(fault) {
serializeValue(fault, xml)

// Includes the <?xml ...> declaration
return xml.doc().toString()
var str = xml.doc().toString();
debug('fault: '+str);
return str
}

function serializeValue(value, xml) {
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -75,4 +76,3 @@ function Server(options, isSecure, onListening) {
Server.prototype.__proto__ = EventEmitter.prototype

module.exports = Server

76 changes: 42 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> (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 <[email protected]> (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"
}