@@ -29,19 +29,22 @@ var net = require('net'),
29
29
utils = new stomp_utils . StompUtils ( ) ,
30
30
log = null ;
31
31
32
- function parse_command ( data ) {
32
+ function extract_command ( data ) {
33
33
var command ,
34
34
this_string = data . toString ( 'utf8' , start = 0 , end = data . length ) ;
35
35
command = this_string . split ( '\n' ) ;
36
36
return command [ 0 ] ;
37
37
} ;
38
38
39
- function parse_headers ( headers_str ) {
39
+ function extract_headers ( data ) {
40
40
var these_headers = { } ,
41
41
one_header = [ ] ,
42
42
header_key = null ,
43
43
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' ) ;
45
48
46
49
for ( var i = 0 ; i < headers_split . length ; i ++ ) {
47
50
one_header = headers_split [ i ] . split ( ':' ) ;
@@ -54,37 +57,33 @@ function parse_headers(headers_str) {
54
57
these_headers [ one_header [ 0 ] ] = one_header [ 1 ] ;
55
58
}
56
59
}
57
- return these_headers ;
60
+ return { length : headers_str [ 0 ] . length , headers : these_headers } ;
58
61
} ;
59
62
60
- function make_body_buffer ( body ) {
61
- buffer = new Buffer ( body , encoding = 'utf8' ) ;
62
- return buffer ;
63
- }
64
-
65
63
function parse_frame ( chunk ) {
66
64
var args = { } ,
67
65
data = null ,
68
66
command = null ,
69
67
headers = null ,
70
68
body = null ,
71
- headers_str = null ;
69
+ headers_str = null ,
70
+ log = new StompLogging ( true ) ;
72
71
73
72
if ( ! utils . really_defined ( chunk ) )
74
73
return null ;
75
74
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 ) ;
79
77
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 ) ;
83
80
84
- if ( 'content-length' in headers ) {
81
+ headers = header_data . headers ;
82
+
83
+ body = chunk ;
84
+
85
+ if ( 'content-length' in headers )
85
86
headers [ 'bytes_message' ] = true ;
86
- body = make_body_buffer ( body ) ;
87
- }
88
87
89
88
args = {
90
89
command : command ,
0 commit comments