-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: make --insecure-http-parser configurable per-stream or per-server
From the issue: > Some servers deviate from HTTP spec enougth that Node.js can't > communicate with them, but "work" when `--insecure-http-parser` > is enabled globally. It would be useful to be able to use this > mode, as a client, only when connecting to known bad servers. This is largely equivalent to #31446 in terms of code changes. Fixes: #31440 Refs: #31446 PR-URL: #31448 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
- Loading branch information
Showing
4 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
const MakeDuplexPair = require('../common/duplexpair'); | ||
|
||
// Test that setting the `maxHeaderSize` option works on a per-stream-basis. | ||
|
||
// Test 1: The server sends an invalid header. | ||
{ | ||
const { clientSide, serverSide } = MakeDuplexPair(); | ||
|
||
const req = http.request({ | ||
createConnection: common.mustCall(() => clientSide), | ||
insecureHTTPParser: true | ||
}, common.mustCall((res) => { | ||
assert.strictEqual(res.headers.hello, 'foo\x08foo'); | ||
res.resume(); // We don’t actually care about contents. | ||
res.on('end', common.mustCall()); | ||
})); | ||
req.end(); | ||
|
||
serverSide.resume(); // Dump the request | ||
serverSide.end('HTTP/1.1 200 OK\r\n' + | ||
'Hello: foo\x08foo\r\n' + | ||
'Content-Length: 0\r\n' + | ||
'\r\n\r\n'); | ||
} | ||
|
||
// Test 2: The same as Test 1 except without the option, to make sure it fails. | ||
{ | ||
const { clientSide, serverSide } = MakeDuplexPair(); | ||
|
||
const req = http.request({ | ||
createConnection: common.mustCall(() => clientSide) | ||
}, common.mustNotCall()); | ||
req.end(); | ||
req.on('error', common.mustCall()); | ||
|
||
serverSide.resume(); // Dump the request | ||
serverSide.end('HTTP/1.1 200 OK\r\n' + | ||
'Hello: foo\x08foo\r\n' + | ||
'Content-Length: 0\r\n' + | ||
'\r\n\r\n'); | ||
} | ||
|
||
// Test 3: The client sends an invalid header. | ||
{ | ||
const testData = 'Hello, World!\n'; | ||
const server = http.createServer( | ||
{ insecureHTTPParser: true }, | ||
common.mustCall((req, res) => { | ||
res.statusCode = 200; | ||
res.setHeader('Content-Type', 'text/plain'); | ||
res.end(testData); | ||
})); | ||
|
||
server.on('clientError', common.mustNotCall()); | ||
|
||
const { clientSide, serverSide } = MakeDuplexPair(); | ||
serverSide.server = server; | ||
server.emit('connection', serverSide); | ||
|
||
clientSide.write('GET / HTTP/1.1\r\n' + | ||
'Hello: foo\x08foo\r\n' + | ||
'\r\n\r\n'); | ||
} | ||
|
||
// Test 4: The same as Test 3 except without the option, to make sure it fails. | ||
{ | ||
const server = http.createServer(common.mustNotCall()); | ||
|
||
server.on('clientError', common.mustCall()); | ||
|
||
const { clientSide, serverSide } = MakeDuplexPair(); | ||
serverSide.server = server; | ||
server.emit('connection', serverSide); | ||
|
||
clientSide.write('GET / HTTP/1.1\r\n' + | ||
'Hello: foo\x08foo\r\n' + | ||
'\r\n\r\n'); | ||
} |