mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
http: add CONNECT method handling for default Host header with proxy
Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com> PR-URL: https://github.com/nodejs/node/pull/64114 Fixes: https://github.com/nodejs/node/issues/63945 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com>
This commit is contained in:
1 parent
f49704b9d0
commit
eacfbd0ca5
3 files changed
+41
-2
No files matched your search
+3
-1
@@ -526,7 +526,9 @@ function ClientRequest(input, options, cb) {
|
||||
const userHostHeader = this.getHeader('host');
|
||||
|
||||
if (host && !this.getHeader('host') && setHost) {
|
||||
this.setHeader('Host', hostHeaderFromOptions);
|
||||
const hostHeader = method === 'CONNECT' && options.path ?
|
||||
String(this.path) : hostHeaderFromOptions;
|
||||
this.setHeader('Host', hostHeader);
|
||||
}
|
||||
|
||||
if (options.auth && !this.getHeader('Authorization')) {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
const net = require('net');
|
||||
|
||||
const target = 'target.example.com:443';
|
||||
|
||||
const server = net.createServer(common.mustCall((socket) => {
|
||||
socket.once('data', common.mustCall((data) => {
|
||||
const rawRequest = data.toString();
|
||||
const requestLines = rawRequest.split('\r\n');
|
||||
|
||||
assert.strictEqual(requestLines[0], `CONNECT ${target} HTTP/1.1`);
|
||||
assert(requestLines.includes(`Host: ${target}`));
|
||||
|
||||
socket.end('HTTP/1.1 200 Connection established\r\n\r\n');
|
||||
}));
|
||||
}));
|
||||
|
||||
server.listen(0, common.localhostIPv4, common.mustCall(() => {
|
||||
const req = http.request({
|
||||
host: common.localhostIPv4,
|
||||
port: server.address().port,
|
||||
method: 'CONNECT',
|
||||
path: target,
|
||||
}, common.mustNotCall());
|
||||
|
||||
req.on('connect', common.mustCall((res, socket) => {
|
||||
assert.strictEqual(res.statusCode, 200);
|
||||
socket.destroy();
|
||||
server.close();
|
||||
}));
|
||||
|
||||
req.end();
|
||||
}));
|
||||
@@ -61,7 +61,7 @@ const proxy = net.createServer(common.mustCall((clientSocket) => {
|
||||
`CONNECT localhost:${server.address().port} ` +
|
||||
'HTTP/1.1\r\n' +
|
||||
'Proxy-Connections: keep-alive\r\n' +
|
||||
`Host: localhost:${proxy.address().port}\r\n` +
|
||||
`Host: localhost:${server.address().port}\r\n` +
|
||||
'Connection: keep-alive\r\n\r\n');
|
||||
|
||||
console.log('PROXY: got CONNECT request');
|
||||
|
||||
Reference in new issue
Block a user