aboutsummaryrefslogtreecommitdiff
path: root/node_modules/proxy-check
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/proxy-check')
-rw-r--r--node_modules/proxy-check/README.md21
-rw-r--r--node_modules/proxy-check/index.js87
-rw-r--r--node_modules/proxy-check/package.json22
3 files changed, 130 insertions, 0 deletions
diff --git a/node_modules/proxy-check/README.md b/node_modules/proxy-check/README.md
new file mode 100644
index 0000000..29bd28a
--- /dev/null
+++ b/node_modules/proxy-check/README.md
@@ -0,0 +1,21 @@
+# Check proxy for NodeJS
+
+```javascript
+const proxy_check = require('proxy-check');
+
+const proxy = {
+ host: '54.82.74.24',
+ port: 5557,
+ proxyAuth: 'y0adXjeO:pAzAHCr4'
+};
+// or
+// const proxy = 'y0adXjeO:pAzAHCr4@54.82.74.24:5557';
+
+proxy_check(proxy).then(r => {
+ console.log(r); // true
+}).catch(e => {
+ console.error(e); // ECONNRESET
+});
+```
+
+#### Install your simple proxy-server: https://github.com/zamanuhina/install-proxy-one-line
diff --git a/node_modules/proxy-check/index.js b/node_modules/proxy-check/index.js
new file mode 100644
index 0000000..efb6991
--- /dev/null
+++ b/node_modules/proxy-check/index.js
@@ -0,0 +1,87 @@
+const http = require('http');
+
+const errors = [
+ 'Bad proxy string',
+ 'Proxy offline'
+];
+
+const proxy_check = p => {
+
+ return new Promise((resolve, reject) => {
+
+ let proxy = {
+ host: '',
+ port: 0,
+ proxyAuth: ''
+ };
+
+ if (typeof p === 'object') {
+ if (Array.isArray(p)) {
+ if (typeof p[0] === 'object') {
+ proxy = p[0];
+ } else if (typeof p === 'string') {
+ p = p[0];
+ } else {
+ return reject(errors[0]);
+ }
+ } else {
+ proxy = p;
+ }
+ }
+
+ if (typeof p === 'string') {
+ if (p.indexOf('@') + 1) {
+ proxy.proxyAuth = p.split('@')[0];
+ const host_port = p.split('@')[1];
+ if (host_port.indexOf(':') + 1) {
+ proxy.host = host_port.split(':')[0];
+ proxy.port = host_port.split(':')[1];
+ }
+ } else {
+ if (p.indexOf(':') + 1) {
+ proxy.host = p.split(':')[0];
+ proxy.port = p.split(':')[1];
+ }
+ }
+ }
+
+ const proxy_options = {
+ method: 'CONNECT',
+ path: 'www.google.com:443',
+ timeout: 1000,
+ agent: false
+ };
+
+ if (proxy.host) {
+ proxy_options.host = proxy.host;
+ }
+ if (proxy.port) {
+ proxy_options.port = proxy.port;
+ }
+ if (proxy.proxyAuth) {
+ proxy_options.headers = {
+ 'Proxy-Authorization': 'Basic ' + Buffer.from(proxy.proxyAuth).toString('base64')
+ };
+ }
+
+ const req = http.request(proxy_options);
+ req.on('connect', res => {
+ req.destroy();
+ if (res.statusCode === 200) {
+ return resolve(true);
+ } else {
+ return reject(errors[1]);
+ }
+ });
+ req.on('timeout', () => {
+ req.destroy();
+ });
+ req.on('error', err => {
+ return reject((err && err.code) || errors[1]);
+ });
+ req.end();
+
+ });
+}
+
+module.exports = proxy_check;
diff --git a/node_modules/proxy-check/package.json b/node_modules/proxy-check/package.json
new file mode 100644
index 0000000..b38e0cc
--- /dev/null
+++ b/node_modules/proxy-check/package.json
@@ -0,0 +1,22 @@
+{
+ "name": "proxy-check",
+ "version": "1.0.8",
+ "description": "Check proxy for NodeJS",
+ "main": "index.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/zamanuhina/proxy-check.git"
+ },
+ "publishConfig": {
+ "registry": "https://registry.npmjs.org/"
+ },
+ "keywords": [
+ "proxy",
+ "proxy-check"
+ ],
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/zamanuhina/proxy-check/issues"
+ },
+ "homepage": "https://github.com/zamanuhina/proxy-check#readme"
+}