Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #104 from Lendix:feature/encoding + tests

    - Add encoding option to client and serializer (mathieug)
    - Add unit tests
  • Loading branch information...
commit 3a3f23e3ca2a59a59f1e3b11993a1df2b07f0474 2 parents 41b736f + e5c7640
@patricklodder patricklodder authored
View
6 lib/client.js
@@ -97,9 +97,9 @@ function Client(options, isSecure) {
* - {mixed} value - The value returned in the method response.
*/
Client.prototype.methodCall = function methodCall(method, params, callback) {
- var xml = Serializer.serializeMethodCall(method, params)
- , transport = this.isSecure ? https : http
- , options = this.options
+ var options = this.options
+ var xml = Serializer.serializeMethodCall(method, params, options.encoding)
+ var transport = this.isSecure ? https : http
options.headers['Content-Length'] = Buffer.byteLength(xml, 'utf8')
this.headersProcessors.composeRequest(options.headers)
View
10 lib/serializer.js
@@ -12,10 +12,16 @@ var xmlBuilder = require('xmlbuilder')
* otherwise null.
* - {String} xml - The method call XML.
*/
-exports.serializeMethodCall = function(method, params) {
+exports.serializeMethodCall = function(method, params, encoding) {
var params = params || []
- var xml = xmlBuilder.create('methodCall', { version: '1.0' })
+ var options = { version: '1.0' }
+
+ if (encoding) {
+ options.encoding = encoding
+ }
+
+ var xml = xmlBuilder.create('methodCall', options)
.ele('methodName')
.txt(method)
.up()
View
10 test/client_test.js
@@ -81,6 +81,16 @@ vows.describe('Client').addBatch({
assert.equal(topic.port, 9999)
}
}
+ // Test passing encoding
+ , 'with an encoding passed': {
+ topic: function () {
+ var client = new Client({ url:'http://localhost:9999', encoding: 'utf-8' }, false)
+ return client.options
+ }
+ , 'caches the encoding option' : function (topic) {
+ assert.strictEqual(topic.encoding, 'utf-8')
+ }
+ }
}
//////////////////////////////////////////////////////////////////////
// Test method call functionality
View
1  test/fixtures/good_food/encoded_call.xml
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="utf-8"?><methodCall><methodName>testMethod</methodName><params><param><value><string>Foo</string></value></param></params></methodCall>
View
7 test/serializer_test.js
@@ -213,6 +213,13 @@ vows.describe('Serializer').addBatch({
, 'contains the customType': assertXml('good_food/customtype_extended_call.xml')
}
}
+ , 'utf-8 encoding': {
+ topic: function () {
+ var value = "\x46\x6F\x6F"
+ return Serializer.serializeMethodCall('testMethod', [value], 'utf-8')
+ }
+ , 'contains the encoding attribute': assertXml('good_food/encoded_call.xml')
+ }
}
, 'serializeMethodResponse() called with': {
Please sign in to comment.
Something went wrong with that request. Please try again.