proxy-chain
Advanced tools
Comparing version 2.0.7 to 2.1.0-beta.0
@@ -9,5 +9,6 @@ "use strict"; | ||
const get_basic_1 = require("./utils/get_basic"); | ||
const createHttpResponse = (statusCode, message) => { | ||
const statuses_1 = require("./statuses"); | ||
const createHttpResponse = (statusCode, statusMessage, message = '') => { | ||
return [ | ||
`HTTP/1.1 ${statusCode} ${http_1.default.STATUS_CODES[statusCode] || 'Unknown Status Code'}`, | ||
`HTTP/1.1 ${statusCode} ${statusMessage || http_1.default.STATUS_CODES[statusCode] || 'Unknown Status Code'}`, | ||
'Connection: close', | ||
@@ -74,3 +75,7 @@ `Date: ${(new Date()).toUTCString()}`, | ||
else { | ||
sourceSocket.end(createHttpResponse(502, '')); | ||
const { statusCode } = response; | ||
const status = statusCode === 401 || statusCode === 407 | ||
? statuses_1.badGatewayStatusCodes.AUTH_FAILED | ||
: statuses_1.badGatewayStatusCodes.NON_200; | ||
sourceSocket.end(createHttpResponse(status, `UPSTREAM${response.statusCode}`)); | ||
} | ||
@@ -110,2 +115,3 @@ return; | ||
client.on('error', (error) => { | ||
var _a, _b; | ||
server.log(proxyChainId, `Failed to connect to upstream proxy: ${error.stack}`); | ||
@@ -118,3 +124,5 @@ // The end socket may get connected after the client to proxy one gets disconnected. | ||
else { | ||
sourceSocket.end(createHttpResponse(502, '')); | ||
const statusCode = (_a = statuses_1.errorCodeToStatusCode[error.code]) !== null && _a !== void 0 ? _a : statuses_1.badGatewayStatusCodes.GENERIC_ERROR; | ||
const response = createHttpResponse(statusCode, (_b = error.code) !== null && _b !== void 0 ? _b : 'Upstream Closed Early'); | ||
sourceSocket.end(response); | ||
} | ||
@@ -121,0 +129,0 @@ } |
@@ -12,2 +12,3 @@ "use strict"; | ||
const count_target_bytes_1 = require("./utils/count_target_bytes"); | ||
const statuses_1 = require("./statuses"); | ||
const pipeline = util_1.default.promisify(stream_1.default.pipeline); | ||
@@ -62,3 +63,3 @@ /** | ||
if (statusCode < 100 || statusCode > 999) { | ||
statusCode = 502; | ||
statusCode = statuses_1.badGatewayStatusCodes.STATUS_CODE_OUT_OF_RANGE; | ||
} | ||
@@ -90,10 +91,4 @@ // 407 is handled separately | ||
} | ||
const statuses = { | ||
ENOTFOUND: proxy ? 502 : 404, | ||
ECONNREFUSED: 502, | ||
ECONNRESET: 502, | ||
EPIPE: 502, | ||
ETIMEDOUT: 504, | ||
}; | ||
response.statusCode = (_a = statuses[error.code]) !== null && _a !== void 0 ? _a : 502; | ||
const statusCode = (_a = statuses_1.errorCodeToStatusCode[error.code]) !== null && _a !== void 0 ? _a : statuses_1.badGatewayStatusCodes.GENERIC_ERROR; | ||
response.statusCode = !proxy && error.code === 'ENOTFOUND' ? 404 : statusCode; | ||
response.setHeader('content-type', 'text/plain; charset=utf-8'); | ||
@@ -100,0 +95,0 @@ response.end(http_1.default.STATUS_CODES[response.statusCode]); |
@@ -20,2 +20,3 @@ "use strict"; | ||
const normalize_url_port_1 = require("./utils/normalize_url_port"); | ||
const statuses_1 = require("./statuses"); | ||
// TODO: | ||
@@ -196,6 +197,6 @@ // - Implement this requirement from rfc7230 | ||
if (error.message === 'Username contains an invalid colon') { | ||
return new request_error_1.RequestError('Invalid colon in username in upstream proxy credentials', 502); | ||
return new request_error_1.RequestError('Invalid colon in username in upstream proxy credentials', statuses_1.badGatewayStatusCodes.AUTH_FAILED); | ||
} | ||
if (error.message === '407 Proxy Authentication Required') { | ||
return new request_error_1.RequestError('Invalid upstream proxy credentials', 502); | ||
return new request_error_1.RequestError('Invalid upstream proxy credentials', statuses_1.badGatewayStatusCodes.AUTH_FAILED); | ||
} | ||
@@ -202,0 +203,0 @@ return error; |
{ | ||
"name": "proxy-chain", | ||
"version": "2.0.7", | ||
"version": "2.1.0-beta.0", | ||
"description": "Node.js implementation of a proxy server (think Squid) with support for SSL, authentication, upstream proxy chaining, and protocol tunneling.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -96,2 +96,54 @@ # Programmable HTTP proxy server for Node.js | ||
## A different approach to `502 Bad Gateway` | ||
`502` status code is not comprehensive enough. Therefore, the server may respond with `590-599` instead: | ||
### `590 Non Successful` | ||
Upstream responded with non-200 status code. | ||
### `591 RESERVED` | ||
*This status code is reserved for further use.* | ||
### `592 Status Code Out Of Range` | ||
Upstream respondend with status code different than 100-999. | ||
### `593 Not Found` | ||
DNS lookup failed - [`EAI_NODATA`](https://github.com/libuv/libuv/blob/cdbba74d7a756587a696fb3545051f9a525b85ac/include/uv.h#L82) or [`EAI_NONAME`](https://github.com/libuv/libuv/blob/cdbba74d7a756587a696fb3545051f9a525b85ac/include/uv.h#L83). | ||
### `594 Connection Refused` | ||
Upstream refused connection. | ||
### `595 Connection Reset` | ||
Connection reset due to loss of connection or timeout. | ||
### `596 Broken Pipe` | ||
Trying to write on a closed socket. | ||
### `597 Auth Failed` | ||
Incorrect upstream credentials. | ||
### `598 RESERVED` | ||
*This status code is reserved for further use.* | ||
### `599 Upstream Error` | ||
Generic upstream error. | ||
--- | ||
`590` and `592` indicate an issue on the upstream side. \ | ||
`593` indicates an incorrect `proxy-chain` configuration.\ | ||
`594`, `595` and `596` may occur due to connection loss.\ | ||
`597` indicates incorrect upstream credentials.\ | ||
`599` is a generic error, where the above is not applicable. | ||
## Custom error responses | ||
@@ -98,0 +150,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
176145
84
1823
401
1
8