proxy-chain 3.0.2 → 3.0.3-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/forward.js
CHANGED
|
@@ -4,8 +4,8 @@ import { pipeline } from 'node:stream/promises';
|
|
|
4
4
|
import { badGatewayStatusCodes, errorCodeToStatusCode } from './statuses.js';
|
|
5
5
|
import { countTargetBytes } from './utils/count_target_bytes.js';
|
|
6
6
|
import { forwardedRequestHeaders } from './utils/forwarded_request_headers.js';
|
|
7
|
+
import { forwardedResponseHeaders } from './utils/forwarded_response_headers.js';
|
|
7
8
|
import { getBasicAuthorizationHeader } from './utils/get_basic.js';
|
|
8
|
-
import { validHeadersOnly } from './utils/valid_headers_only.js';
|
|
9
9
|
/**
|
|
10
10
|
* The request is read from the client and is resent.
|
|
11
11
|
* This is similar to Direct / Chain, however it uses the CONNECT protocol instead.
|
|
@@ -59,7 +59,7 @@ export const forward = async (request, response, handlerOpts) => new Promise((re
|
|
|
59
59
|
reject(new Error('407 Proxy Authentication Required'));
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
response.writeHead(statusCode, clientResponse.statusMessage,
|
|
62
|
+
response.writeHead(statusCode, clientResponse.statusMessage, forwardedResponseHeaders(clientResponse));
|
|
63
63
|
// `pipeline` automatically handles all the events and data
|
|
64
64
|
await pipeline(clientResponse, response);
|
|
65
65
|
resolve();
|
package/dist/forward_socks.js
CHANGED
|
@@ -4,7 +4,7 @@ import { SocksProxyAgent } from 'socks-proxy-agent';
|
|
|
4
4
|
import { badGatewayStatusCodes, errorCodeToStatusCode } from './statuses.js';
|
|
5
5
|
import { countTargetBytes } from './utils/count_target_bytes.js';
|
|
6
6
|
import { forwardedRequestHeaders } from './utils/forwarded_request_headers.js';
|
|
7
|
-
import {
|
|
7
|
+
import { forwardedResponseHeaders } from './utils/forwarded_response_headers.js';
|
|
8
8
|
/**
|
|
9
9
|
* Forwards HTTP requests through a SOCKS upstream proxy.
|
|
10
10
|
*
|
|
@@ -40,7 +40,7 @@ export const forwardSocks = async (request, response, handlerOpts) => new Promis
|
|
|
40
40
|
reject(new Error('407 Proxy Authentication Required'));
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
response.writeHead(statusCode, clientResponse.statusMessage,
|
|
43
|
+
response.writeHead(statusCode, clientResponse.statusMessage, forwardedResponseHeaders(clientResponse));
|
|
44
44
|
// `pipeline` automatically handles all the events and data
|
|
45
45
|
await pipeline(clientResponse, response);
|
|
46
46
|
resolve();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { validHeadersOnly } from './valid_headers_only.js';
|
|
2
|
+
// Transfer-Encoding is hop-by-hop and gets stripped, so a Content-Length sent alongside it no longer describes
|
|
3
|
+
// the body. RFC 9112 section 6.3 requires an intermediary to remove it; Node then re-frames the body as chunked.
|
|
4
|
+
export const forwardedResponseHeaders = (clientResponse) => {
|
|
5
|
+
const headers = validHeadersOnly(clientResponse.rawHeaders);
|
|
6
|
+
if (clientResponse.headers['transfer-encoding'] === undefined) {
|
|
7
|
+
return headers;
|
|
8
|
+
}
|
|
9
|
+
const withoutContentLength = [];
|
|
10
|
+
// `headers` is a flat [name, value, name, value, ...] array, so step by 2 and drop the content-length pair.
|
|
11
|
+
for (let index = 0; index < headers.length; index += 2) {
|
|
12
|
+
if (headers[index].toLowerCase() !== 'content-length') {
|
|
13
|
+
withoutContentLength.push(headers[index], headers[index + 1]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return withoutContentLength;
|
|
17
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "proxy-chain",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3-beta.0",
|
|
4
4
|
"description": "Node.js implementation of a proxy server (think Squid) with support for SSL, authentication, upstream proxy chaining, and protocol tunneling.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|