Skip to content

Commit 341b6d9

Browse files
lpincatargos
authored andcommitted
test: deflake test-http-header-overflow
Skip the network and push the data directly to the receiving socket so that it is guaranteed to be received as a single chunk. Fixes: #46291 PR-URL: #54978 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent a929c71 commit 341b6d9

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

test/parallel/test-http-header-overflow.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Flags: --expose-internals
2-
31
'use strict';
42
const { expectsError, mustCall } = require('../common');
53
const assert = require('assert');
@@ -10,11 +8,10 @@ const CRLF = '\r\n';
108
const DUMMY_HEADER_NAME = 'Cookie: ';
119
const DUMMY_HEADER_VALUE = 'a'.repeat(
1210
// Plus one is to make it 1 byte too big
13-
maxHeaderSize - DUMMY_HEADER_NAME.length + 2
11+
maxHeaderSize - DUMMY_HEADER_NAME.length + 1
1412
);
1513
const PAYLOAD_GET = 'GET /blah HTTP/1.1';
16-
const PAYLOAD = PAYLOAD_GET + CRLF +
17-
DUMMY_HEADER_NAME + DUMMY_HEADER_VALUE + CRLF.repeat(2);
14+
const PAYLOAD = PAYLOAD_GET + CRLF + DUMMY_HEADER_NAME + DUMMY_HEADER_VALUE;
1815

1916
const server = createServer();
2017

@@ -23,18 +20,19 @@ server.on('connection', mustCall((socket) => {
2320
name: 'Error',
2421
message: 'Parse Error: Header overflow',
2522
code: 'HPE_HEADER_OVERFLOW',
26-
bytesParsed: maxHeaderSize + PAYLOAD_GET.length + (CRLF.length * 2) + 1,
23+
bytesParsed: PAYLOAD.length,
2724
rawPacket: Buffer.from(PAYLOAD)
2825
}));
26+
27+
// The data is not sent from the client to ensure that it is received as a
28+
// single chunk.
29+
socket.push(PAYLOAD);
2930
}));
3031

3132
server.listen(0, mustCall(() => {
3233
const c = createConnection(server.address().port);
3334
let received = '';
3435

35-
c.on('connect', mustCall(() => {
36-
c.write(PAYLOAD);
37-
}));
3836
c.on('data', mustCall((data) => {
3937
received += data.toString();
4038
}));

0 commit comments

Comments
 (0)