Permalink
Browse files

[api] Attempt naive framing via search for fist occurance of `\r\n\r\n`

  • Loading branch information...
1 parent 075c73f commit c85778f914652fe8b966d150c3b9f0fb3c0123b0 @indexzero indexzero committed Feb 12, 2012
Showing with 16 additions and 11 deletions.
  1. +16 −11 lib/balancing-proxy.js
View
@@ -250,18 +250,23 @@ exports.createServer = function () {
//self.emit('clientError', e);
});
+ var state = 'no-headers'
+
socket.ondata = function(d, start, end) {
- console.log(d.toString());
- var ret = parser.execute(d, start, end - start);
- console.dir(ret);
- console.dir(d.slice(0, ret).toString());
- console.dir(start);
- console.dir(end);
- if (ret instanceof Error) {
- debug('parse error');
- socket.destroy(ret);
- return;
- }
+ if (state === 'no-headers') {
+ var ret = parser.execute(d, start, end - start);
+ var CLRFCLRF = '\r\n\r\n';
+ var boundary = d.toString().indexOf(CLRFCLRF);
+ console.dir(d.slice(0, boundary + CLRFCLRF.length).toString());
+ console.dir(d.slice(boundary + CLRFCLRF.length).toString())
+
+ if (ret instanceof Error) {
+ debug('parse error');
+ socket.destroy(ret);
+ return;
+ }
+ }
+
// else if (parser.incoming && parser.incoming.upgrade) {
// var bytesParsed = ret;

0 comments on commit c85778f

Please sign in to comment.