Skip to content
This repository was archived by the owner on Nov 28, 2018. It is now read-only.

Commit a244715

Browse files
committed
Another possible fix for issue #15. Preserve the original buffer that comes in off the socket. slice off the rest of the stuff and extract commands/headers
1 parent 9bc152c commit a244715

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

lib/stomp.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,22 @@ var net = require('net'),
2929
utils = new stomp_utils.StompUtils(),
3030
log = null;
3131

32-
function parse_command(data) {
32+
function extract_command(data) {
3333
var command,
3434
this_string = data.toString('utf8', start=0, end=data.length);
3535
command = this_string.split('\n');
3636
return command[0];
3737
};
3838

39-
function parse_headers(headers_str) {
39+
function extract_headers(data) {
4040
var these_headers = {},
4141
one_header = [],
4242
header_key = null,
4343
header_val = null,
44-
headers_split = headers_str.split('\n');
44+
data_str = data.toString('utf8', start=0, end=data.length);
45+
46+
headers_str = data_str.split('\n\n', 1);
47+
headers_split = headers_str[0].split('\n');
4548

4649
for (var i = 0; i < headers_split.length; i++) {
4750
one_header = headers_split[i].split(':');
@@ -54,37 +57,33 @@ function parse_headers(headers_str) {
5457
these_headers[one_header[0]] = one_header[1];
5558
}
5659
}
57-
return these_headers;
60+
return {length: headers_str[0].length, headers: these_headers};
5861
};
5962

60-
function make_body_buffer(body) {
61-
buffer = new Buffer(body, encoding='utf8');
62-
return buffer;
63-
}
64-
6563
function parse_frame(chunk) {
6664
var args = {},
6765
data = null,
6866
command = null,
6967
headers = null,
7068
body = null,
71-
headers_str = null;
69+
headers_str = null,
70+
log = new StompLogging(true);
7271

7372
if (!utils.really_defined(chunk))
7473
return null;
7574

76-
command = parse_command(chunk);
77-
data = chunk.slice(command.length + 1, chunk.length);
78-
data = data.toString('utf8', start=0, end=data.length);
75+
command = extract_command(chunk);
76+
chunk = chunk.slice(command.length + 1, chunk.length);
7977

80-
the_rest = data.split('\n\n');
81-
headers = parse_headers(the_rest[0]);
82-
body = the_rest.slice(1, the_rest.length);
78+
header_data = extract_headers(chunk);
79+
chunk = chunk.slice(header_data.length + 1, chunk.length);
8380

84-
if ('content-length' in headers) {
81+
headers = header_data.headers;
82+
83+
body = chunk;
84+
85+
if ('content-length' in headers)
8586
headers['bytes_message'] = true;
86-
body = make_body_buffer(body);
87-
}
8887

8988
args = {
9089
command: command,

0 commit comments

Comments
 (0)