Skip to content

Commit a2f0ca3

Browse files
committed
add back HTTP parser
1 parent 0eea489 commit a2f0ca3

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

test/sequential/test-http-regr-gh-2928.js

+37-12
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,59 @@
44
'use strict';
55
const common = require('../common');
66
const assert = require('assert');
7+
const httpCommon = require('_http_common');
8+
const { HTTPParser } = require('_http_common');
79
const net = require('net');
810

9-
const COUNT = 1000 + 1;
11+
const COUNT = httpCommon.parsers.max + 1;
12+
13+
const parsers = new Array(COUNT);
14+
for (let i = 0; i < parsers.length; i++)
15+
parsers[i] = httpCommon.parsers.alloc();
1016

1117
let gotRequests = 0;
1218
let gotResponses = 0;
1319

14-
const response = Buffer.from('HTTP/1.1 200 OK\r\n\r\n');
15-
1620
function execAndClose() {
21+
if (parsers.length === 0)
22+
return;
1723
process.stdout.write('.');
1824

19-
const socket = net.connect(common.PORT, common.localhostIPv4);
20-
socket.on('end', socket.end);
21-
socket.on('data', function(chunk) {
22-
process.stdout.write('+');
23-
assert.deepStrictEqual(chunk, response);
24-
if (++gotResponses === COUNT) return;
25+
const parser = parsers.pop();
26+
parser.initialize(HTTPParser.RESPONSE, {});
2527

26-
socket.on('close', execAndClose);
28+
const socket = net.connect(common.PORT, common.localhostIPv4);
29+
socket.on('error', (e) => {
30+
// If SmartOS and ECONNREFUSED, then retry. See
31+
// https://github.com./nodejs/node/issues/2663.
32+
if (common.isSunOS && e.code === 'ECONNREFUSED') {
33+
parsers.push(parser);
34+
parser.reused = true;
35+
socket.destroy();
36+
setImmediate(execAndClose);
37+
return;
38+
}
39+
throw e;
2740
});
41+
42+
parser.consume(socket._handle);
43+
44+
parser.onIncoming = function onIncoming() {
45+
process.stdout.write('+');
46+
gotResponses++;
47+
parser.unconsume();
48+
httpCommon.freeParser(parser);
49+
socket.destroy();
50+
setImmediate(execAndClose);
51+
};
2852
}
2953

3054
const server = net.createServer(function(c) {
3155
if (++gotRequests === COUNT)
3256
server.close();
33-
c.end(response);
34-
c.resume();
57+
c.end('HTTP/1.1 200 OK\r\n\r\n', function() {
58+
c.destroySoon();
59+
});
3560
}).listen(common.PORT, common.localhostIPv4, execAndClose);
3661

3762
process.on('exit', function() {

0 commit comments

Comments
 (0)