2 // Run this program with valgrind or efence with --expose_gc to expose the
8 var assert = require('assert');
9 var HTTPParser = process.binding('http_parser').HTTPParser;
11 var kOnHeaders = HTTPParser.kOnHeaders | 0;
12 var kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
13 var kOnBody = HTTPParser.kOnBody | 0;
14 var kOnMessageComplete = HTTPParser.kOnMessageComplete | 0;
16 var headersComplete = 0;
17 var messagesComplete = 0;
19 function flushPool() {
20 new Buffer(Buffer.poolSize - 1);
24 function demoBug(part1, part2) {
27 var parser = new HTTPParser('REQUEST');
32 parser[kOnHeaders] = function(headers, url) {
33 parser.headers = parser.headers.concat(headers);
37 parser[kOnHeadersComplete] = function(info) {
39 console.log('url', info.url);
42 parser[kOnBody] = function(b, start, len) { };
44 parser[kOnMessageComplete] = function() {
49 // We use a function to eliminate references to the Buffer b
50 // We want b to be GCed. The parser will hold a bad reference to it.
52 var b = Buffer(part1);
55 console.log('parse the first part of the message');
56 parser.execute(b, 0, b.length);
62 var b = Buffer(part2);
64 console.log('parse the second part of the message');
65 parser.execute(b, 0, b.length);
73 demoBug('POST /1', '/22 HTTP/1.1\r\n' +
74 'Content-Type: text/plain\r\n' +
75 'Content-Length: 4\r\n\r\n' +
78 demoBug('POST /1/22 HTTP/1.1\r\n' +
79 'Content-Type: tex', 't/plain\r\n' +
80 'Content-Length: 4\r\n\r\n' +
83 process.on('exit', function() {
84 assert.equal(2, headersComplete);
85 assert.equal(2, messagesComplete);