Socket
Socket
Sign inDemoInstall

get-proxy-settings

Package Overview
Dependencies
5
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.6 to 0.1.7

dist/defaults.d.ts

0

dist/cli.d.ts
export {};

@@ -17,2 +17,5 @@ "use strict";

});
// To test
// process.env.HTTP_PROXY = "http://localhost:8888";
// process.env.HTTPS_PROXY = "http://localhost:8888";
proxy_1.getAndTestProxySettings(login).then((settings) => {

@@ -19,0 +22,0 @@ if (settings) {

@@ -0,1 +1,2 @@

export * from "./defaults";
export * from "./proxy";

@@ -2,0 +3,0 @@ export * from "./validate";

@@ -6,2 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./defaults"));
__export(require("./proxy"));

@@ -8,0 +9,0 @@ __export(require("./validate"));

@@ -12,1 +12,8 @@ import { ProxySetting } from "./proxy-settings";

}
/**
* Error when the connection to the proxy failed ERRCONNREFUSED
* Proxy might be down
*/
export declare class ProxyConnectionRefusedError extends GetProxyError {
constructor(proxy: ProxySetting);
}

@@ -22,2 +22,12 @@ "use strict";

exports.ProxyInvalidCredentialsError = ProxyInvalidCredentialsError;
/**
* Error when the connection to the proxy failed ERRCONNREFUSED
* Proxy might be down
*/
class ProxyConnectionRefusedError extends GetProxyError {
constructor(proxy) {
super(proxy, `Proxy "${proxy}" doesn't seem to be available. Connection refused.`);
}
}
exports.ProxyConnectionRefusedError = ProxyConnectionRefusedError;
//# sourceMappingURL=proxy-errors.js.map

@@ -0,0 +0,0 @@ export declare enum Protocol {

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { ProxyCredentials, ProxySettings } from "./proxy-settings";

@@ -0,0 +0,0 @@ "use strict";

import { ProxySetting } from "./proxy-settings";
/**
* Validate the given proxy setting
* @param setting Proxy setting to validate.
*
* @throws {ProxyConnectionRefusedError} if it cannot connect to the proxy
* @throws {ProxyAuthenticationRequiredError} if proxy settings doesn't have credentials but is required
* @throws {ProxyInvalidCredentialsError} if proxy settings has credentials but proxy denies the request(407)
* @throws {GetProxyError} for other errors
*/
export declare function validateProxySetting(setting: ProxySetting): Promise<boolean>;

@@ -13,2 +13,4 @@ "use strict";

const https = require("https");
const url_1 = require("url");
const defaults_1 = require("./defaults");
const proxy_errors_1 = require("./proxy-errors");

@@ -19,3 +21,3 @@ function get(opts, useHttps = false) {

return new Promise((resolve, reject) => {
send(opts, (res) => {
const req = send(opts, (res) => {
if (res.statusCode < 200 || res.statusCode > 299) {

@@ -28,8 +30,19 @@ reject(res);

});
req.on("error", e => reject(e));
});
});
}
/**
* Validate the given proxy setting
* @param setting Proxy setting to validate.
*
* @throws {ProxyConnectionRefusedError} if it cannot connect to the proxy
* @throws {ProxyAuthenticationRequiredError} if proxy settings doesn't have credentials but is required
* @throws {ProxyInvalidCredentialsError} if proxy settings has credentials but proxy denies the request(407)
* @throws {GetProxyError} for other errors
*/
function validateProxySetting(setting) {
return __awaiter(this, void 0, void 0, function* () {
const auth = setting.getAuthorizationHeader();
const testUrl = new url_1.URL(defaults_1.defaults.testUrl);
try {

@@ -39,6 +52,6 @@ yield get({

port: setting.port,
path: "https://www.bing.com/",
path: defaults_1.defaults.testUrl,
headers: {
"Connection": "close",
"Host": "www.bing.com",
"Host": testUrl.host,
"Proxy-Authorization": auth,

@@ -51,3 +64,6 @@ },

catch (e) {
if (e.statusCode === 407) {
if (e.code === "ECONNREFUSED") {
throw new proxy_errors_1.ProxyConnectionRefusedError(setting);
}
else if (e.statusCode === 407) {
if (setting.credentials) {

@@ -54,0 +70,0 @@ throw new proxy_errors_1.ProxyInvalidCredentialsError(setting);

@@ -0,0 +0,0 @@ export declare enum Hive {

@@ -0,0 +0,0 @@ "use strict";

2

package.json
{
"name": "get-proxy-settings",
"version": "0.1.6",
"version": "0.1.7",
"description": "Retrieve proxy settings specified by the system",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -37,3 +37,2 @@ # System Proxy

// Get and validate the proxy settings
async function withValidation() {

@@ -50,3 +49,11 @@ async function login() {

## Config
Update the test url(Which url is used to validate the proxy)
```js
import { defaults } from "get-proxy-settings";
defaults.testUrl = "https://example.com";
```
# Contributing

@@ -53,0 +60,0 @@

@@ -0,0 +0,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc