Skip to content

Commit ccf9038

Browse files
sam-githubtargos
authored andcommitted
test: check that --insecure-http-parser works
Test that using --insecure-http-parser will disable validation of invalid characters in HTTP headers. See: - #30567 PR-URL: #31253 Backport-PR-URL: #30473 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 3a7a3be commit ccf9038

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Flags: --insecure-http-parser --http-parser=legacy
2+
3+
'use strict';
4+
const common = require('../common');
5+
const assert = require('assert');
6+
const http = require('http');
7+
const net = require('net');
8+
9+
const server = http.createServer(function(req, res) {
10+
assert.strictEqual(req.headers['content-type'], 'text/te\bt');
11+
req.pipe(res);
12+
});
13+
14+
server.listen(0, common.mustCall(function() {
15+
const bufs = [];
16+
const client = net.connect(
17+
this.address().port,
18+
function() {
19+
client.write(
20+
'GET / HTTP/1.1\r\n' +
21+
'Content-Type: text/te\x08t\r\n' +
22+
'Connection: close\r\n\r\n');
23+
}
24+
);
25+
client.on('data', function(chunk) {
26+
bufs.push(chunk);
27+
});
28+
client.on('end', common.mustCall(function() {
29+
const head = Buffer.concat(bufs)
30+
.toString('latin1')
31+
.split('\r\n')[0];
32+
assert.strictEqual(head, 'HTTP/1.1 200 OK');
33+
server.close();
34+
}));
35+
}));
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Flags: --insecure-http-parser
2+
3+
'use strict';
4+
const common = require('../common');
5+
const assert = require('assert');
6+
const http = require('http');
7+
const net = require('net');
8+
9+
const server = http.createServer(function(req, res) {
10+
assert.strictEqual(req.headers['content-type'], 'text/te\bt');
11+
req.pipe(res);
12+
});
13+
14+
server.listen(0, common.mustCall(function() {
15+
const bufs = [];
16+
const client = net.connect(
17+
this.address().port,
18+
function() {
19+
client.write(
20+
'GET / HTTP/1.1\r\n' +
21+
'Content-Type: text/te\x08t\r\n' +
22+
'Connection: close\r\n\r\n');
23+
}
24+
);
25+
client.on('data', function(chunk) {
26+
bufs.push(chunk);
27+
});
28+
client.on('end', common.mustCall(function() {
29+
const head = Buffer.concat(bufs)
30+
.toString('latin1')
31+
.split('\r\n')[0];
32+
assert.strictEqual(head, 'HTTP/1.1 200 OK');
33+
server.close();
34+
}));
35+
}));

0 commit comments

Comments
 (0)