Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions test/client-proxy/test-https-proxy-request-invalid-char-in-url.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,10 @@ for (const testCase of testCases) {
proxy.close();
server.close();
assert.deepStrictEqual(requests, expectedUrls);
const logSet = new Set(logs);
for (const log of logSet) {
if (log.source === 'proxy connect' && log.error?.code === 'EPIPE') {
// There can be a race from eagerly shutting down the servers and severing
// two pipes at the same time but for the purpose of this test, we only
// care about whether the requests are initiated from the client as expected,
// not how the upstream/proxy servers behave. Ignore EPIPE errors from them..
// Refs: https://github.com/nodejs/node/issues/59741
console.log('Ignoring EPIPE error from proxy connect', log.error);
logSet.delete(log);
}
}
assert.deepStrictEqual(logSet, expectedProxyLogs);
const requestLogs = logs.filter((log) => !('error' in log));
const errors = logs.filter((log) => 'error' in log);
assert.deepStrictEqual(new Set(requestLogs), expectedProxyLogs);
assert.deepStrictEqual(errors, []);
}));
}
}));
Expand Down
9 changes: 8 additions & 1 deletion test/common/proxy-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ function createProxyServer(options = {}) {

const normalizedHostname = hostname.startsWith('[') && hostname.endsWith(']') ?
hostname.slice(1, -1) : hostname;
const proxyReq = net.connect(port, normalizedHostname, () => {
// A CONNECT tunnel is full-duplex. Keep the upstream socket writable after
// receiving a FIN so that the client-to-upstream pipe can finish draining.
// The reverse pipe will end `res`, and `res` will in turn end `proxyReq`.
const proxyReq = net.connect({
port,
host: normalizedHostname,
allowHalfOpen: true,
}, () => {
res.write(
'HTTP/1.1 200 Connection Established\r\n' +
'Proxy-agent: Node.js-Proxy\r\n' +
Expand Down
Loading