proxy-chain 3.0.2-beta.22 → 3.0.2-beta.24

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
@@ -3,6 +3,7 @@ import https from 'node:https';
3
3
  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
+ import { forwardedRequestHeaders } from './utils/forwarded_request_headers.js';
6
7
  import { getBasicAuthorizationHeader } from './utils/get_basic.js';
7
8
  import { validHeadersOnly } from './utils/valid_headers_only.js';
8
9
  /**
@@ -27,7 +28,7 @@ export const forward = async (request, response, handlerOpts) => new Promise((re
27
28
  const origin = proxy ? proxy.origin : request.url;
28
29
  const options = {
29
30
  method: request.method,
30
- headers: validHeadersOnly(request.rawHeaders),
31
+ headers: forwardedRequestHeaders(request),
31
32
  insecureHTTPParser: true,
32
33
  localAddress: handlerOpts.localAddress,
33
34
  family: handlerOpts.ipFamily,
@@ -3,6 +3,7 @@ import { pipeline } from 'node:stream/promises';
3
3
  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
+ import { forwardedRequestHeaders } from './utils/forwarded_request_headers.js';
6
7
  import { validHeadersOnly } from './utils/valid_headers_only.js';
7
8
  /**
8
9
  * Forwards HTTP requests through a SOCKS upstream proxy.
@@ -20,7 +21,7 @@ export const forwardSocks = async (request, response, handlerOpts) => new Promis
20
21
  const agent = new SocksProxyAgent(handlerOpts.upstreamProxyUrlParsed);
21
22
  const options = {
22
23
  method: request.method,
23
- headers: validHeadersOnly(request.rawHeaders),
24
+ headers: forwardedRequestHeaders(request),
24
25
  insecureHTTPParser: true,
25
26
  localAddress: handlerOpts.localAddress,
26
27
  agent,
@@ -0,0 +1,2 @@
1
+ import type http from 'node:http';
2
+ export declare const forwardedRequestHeaders: (request: http.IncomingMessage) => string[];
@@ -0,0 +1,16 @@
1
+ import { validHeadersOnly } from './valid_headers_only.js';
2
+ // Node de-chunks the inbound body but only re-chunks outbound bodies on methods that have one by default.
3
+ // On GET, HEAD, DELETE and OPTIONS the body would otherwise be written raw and parsed upstream as a new request.
4
+ export const forwardedRequestHeaders = (request) => {
5
+ const headers = validHeadersOnly(request.rawHeaders);
6
+ if (request.headers['transfer-encoding'] === undefined) {
7
+ return headers;
8
+ }
9
+ const withoutContentLength = [];
10
+ for (let index = 0; index < headers.length; index += 2) {
11
+ if (headers[index].toLowerCase() !== 'content-length') {
12
+ withoutContentLength.push(headers[index], headers[index + 1]);
13
+ }
14
+ }
15
+ return [...withoutContentLength, 'transfer-encoding', 'chunked'];
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proxy-chain",
3
- "version": "3.0.2-beta.22",
3
+ "version": "3.0.2-beta.24",
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",