From 6bd4a64ffe2436c16f339291f983723a48bddcac Mon Sep 17 00:00:00 2001 From: Otavio Calaca Xavier Date: Wed, 18 Nov 2015 17:22:26 -0200 Subject: [PATCH 1/3] Adding parameter in publish method to choose message type. The new fourth parameter of the "publish" method can be informed with value "byte" if you need to publish a ByteMessage. --- lib/client.js | 4 ++-- lib/frame.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/client.js b/lib/client.js index c6b851f..bac4011 100644 --- a/lib/client.js +++ b/lib/client.js @@ -304,14 +304,14 @@ StompClient.prototype.unsubscribe = function (queue, headers) { return this; }; -StompClient.prototype.publish = function(queue, message, headers) { +StompClient.prototype.publish = function(queue, message, headers, type) { headers = _extend({}, headers); headers.destination = queue; new StompFrame({ command: 'SEND', headers: headers, body: message - }).send(this.stream); + }).send(this.stream, type); return this; }; diff --git a/lib/frame.js b/lib/frame.js index 0ec5ef4..8c76f9d 100644 --- a/lib/frame.js +++ b/lib/frame.js @@ -16,14 +16,14 @@ StompFrame.prototype.toString = function() { }); }; -StompFrame.prototype.send = function(stream) { +StompFrame.prototype.send = function(stream, type) { // Avoid small writes, they get sent in their own tcp packet, which // is not efficient (and v8 does fast string concat). var frame = this.command + '\n'; for (var key in this.headers) { frame += key + ':' + this.headers[key] + '\n'; } - if (this.body.length > 0) { + if(type && type === "byte" && this.body.length > 0) { frame += 'content-length:' + Buffer.byteLength(this.body) + '\n'; } frame += '\n'; From 96b2d22b915171833f8e3890041a9ae22ee96fae Mon Sep 17 00:00:00 2001 From: Otavio Calaca Xavier Date: Thu, 19 Nov 2015 09:21:48 -0200 Subject: [PATCH 2/3] Update frame.js send method to set the default type of message as ByteMessage. --- lib/frame.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/frame.js b/lib/frame.js index 8c76f9d..06b5405 100644 --- a/lib/frame.js +++ b/lib/frame.js @@ -23,7 +23,7 @@ StompFrame.prototype.send = function(stream, type) { for (var key in this.headers) { frame += key + ':' + this.headers[key] + '\n'; } - if(type && type === "byte" && this.body.length > 0) { + if((!type || type === "byte") && this.body.length > 0) { frame += 'content-length:' + Buffer.byteLength(this.body) + '\n'; } frame += '\n'; From 9451a2837f2fbd1df39761ff978385120cffabdc Mon Sep 17 00:00:00 2001 From: Otavio Calaca Xavier Date: Thu, 19 Nov 2015 09:40:20 -0200 Subject: [PATCH 3/3] Adding test to text messages. --- test/frame.test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/frame.test.js b/test/frame.test.js index 4fc530f..fede1e8 100644 --- a/test/frame.test.js +++ b/test/frame.test.js @@ -82,6 +82,31 @@ module.exports = testCase({ test.deepEqual(expectedStream.join(''), connectionObserver.writeBuffer.join(''), 'frame stream data is correctly output on the mocked wire'); test.done(); }, + + 'test stream writes are correct and content-length is not set for text messages': function (test) { + var frame = new StompFrame({ + 'command': 'HITME', + 'headers': { + 'header1': 'value1', + 'header2': 'value2' + }, + 'body': 'wewp de doo' + }); + + var expectedStream = [ + 'HITME\n', + 'header1:value1\n', + 'header2:value2\n', + '\n', + 'wewp de doo', + '\u0000' + ]; + + frame.send(connectionObserver, "text"); + + test.deepEqual(expectedStream.join(''), connectionObserver.writeBuffer.join(''), 'frame stream data is correctly output on the mocked wire and the content-length header is not set.'); + test.done(); + }, 'check validation of arbitrary frame with arbitrary frame construct': function (test) { var validation,