(part1, part2)
| 22 | } |
| 23 | |
| 24 | function demoBug(part1, part2) { |
| 25 | flushPool(); |
| 26 | |
| 27 | const parser = new HTTPParser(); |
| 28 | parser.initialize(HTTPParser.REQUEST, {}); |
| 29 | |
| 30 | parser.headers = []; |
| 31 | parser.url = ''; |
| 32 | |
| 33 | parser[kOnHeaders] = function(headers, url) { |
| 34 | parser.headers = parser.headers.concat(headers); |
| 35 | parser.url += url; |
| 36 | }; |
| 37 | |
| 38 | parser[kOnHeadersComplete] = function(info) { |
| 39 | headersComplete++; |
| 40 | console.log('url', info.url); |
| 41 | }; |
| 42 | |
| 43 | parser[kOnBody] = () => {}; |
| 44 | |
| 45 | parser[kOnMessageComplete] = function() { |
| 46 | messagesComplete++; |
| 47 | }; |
| 48 | |
| 49 | |
| 50 | // We use a function to eliminate references to the Buffer b |
| 51 | // We want b to be GCed. The parser will hold a bad reference to it. |
| 52 | (function() { |
| 53 | const b = Buffer.from(part1); |
| 54 | flushPool(); |
| 55 | |
| 56 | console.log('parse the first part of the message'); |
| 57 | parser.execute(b, 0, b.length); |
| 58 | })(); |
| 59 | |
| 60 | flushPool(); |
| 61 | |
| 62 | (function() { |
| 63 | const b = Buffer.from(part2); |
| 64 | |
| 65 | console.log('parse the second part of the message'); |
| 66 | parser.execute(b, 0, b.length); |
| 67 | parser.finish(); |
| 68 | })(); |
| 69 | |
| 70 | flushPool(); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | demoBug('POST /1', '/22 HTTP/1.1\r\n' + |
no test coverage detected
searching dependent graphs…