Socket
Socket
Sign inDemoInstall

socks-proxy-agent

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socks-proxy-agent - npm Package Compare versions

Comparing version 6.1.1 to 6.2.0-beta.0

49

dist/index.d.ts
/// <reference types="node" />
import { SocksProxy } from 'socks';
import { Agent, ClientRequest, RequestOptions } from 'agent-base';
import CacheableLookup from 'cacheable-lookup';
import { AgentOptions } from 'agent-base';
import { Url } from 'url';
import { SocksProxy } from 'socks';
import net from 'net';
import tls from 'tls';
import { AgentOptions } from 'agent-base';
import _SocksProxyAgent from './agent';
declare function createSocksProxyAgent(opts: string | createSocksProxyAgent.SocksProxyAgentOptions): _SocksProxyAgent;
declare namespace createSocksProxyAgent {
interface BaseSocksProxyAgentOptions {
host?: string | null;
port?: string | number | null;
username?: string | null;
tls?: tls.ConnectionOptions | null;
}
export interface SocksProxyAgentOptions extends AgentOptions, BaseSocksProxyAgentOptions, Partial<Omit<Url & SocksProxy, keyof BaseSocksProxyAgentOptions>> {
}
export type SocksProxyAgent = _SocksProxyAgent;
export const SocksProxyAgent: typeof _SocksProxyAgent;
export {};
interface BaseSocksProxyAgentOptions {
host?: string | null;
port?: string | number | null;
username?: string | null;
tls?: tls.ConnectionOptions | null;
}
export = createSocksProxyAgent;
interface SocksProxyAgentOptionsExtra {
dnsCache?: CacheableLookup;
timeout?: number;
}
export interface SocksProxyAgentOptions extends AgentOptions, BaseSocksProxyAgentOptions, Partial<Omit<Url & SocksProxy, keyof BaseSocksProxyAgentOptions>> {
}
export declare class SocksProxyAgent extends Agent {
private readonly lookup;
private readonly proxy;
private readonly tlsConnectionOptions;
private readonly dnsCache;
timeout: number | null;
constructor(input: string | SocksProxyAgentOptions, options?: SocksProxyAgentOptionsExtra);
/**
* Initiates a SOCKS connection to the specified SOCKS proxy server,
* which in turn connects to the specified remote host and port.
*
* @api protected
*/
callback(req: ClientRequest, opts: RequestOptions): Promise<net.Socket>;
}
export {};
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
const agent_1 = __importDefault(require("./agent"));
function createSocksProxyAgent(opts) {
return new agent_1.default(opts);
Object.defineProperty(exports, "__esModule", { value: true });
exports.SocksProxyAgent = void 0;
const socks_1 = require("socks");
const agent_base_1 = require("agent-base");
const cacheable_lookup_1 = __importDefault(require("cacheable-lookup"));
const debug_1 = __importDefault(require("debug"));
const tls_1 = __importDefault(require("tls"));
const debug = (0, debug_1.default)('socks-proxy-agent');
function parseSocksProxy(opts) {
var _a;
let port = 0;
let lookup = false;
let type = 5;
const host = opts.hostname;
if (host == null) {
throw new TypeError('No "host"');
}
if (typeof opts.port === 'number') {
port = opts.port;
}
else if (typeof opts.port === 'string') {
port = parseInt(opts.port, 10);
}
// From RFC 1928, Section 3: https://tools.ietf.org/html/rfc1928#section-3
// "The SOCKS service is conventionally located on TCP port 1080"
if (port == null) {
port = 1080;
}
// figure out if we want socks v4 or v5, based on the "protocol" used.
// Defaults to 5.
if (opts.protocol != null) {
switch (opts.protocol.replace(':', '')) {
case 'socks4':
lookup = true;
// pass through
case 'socks4a':
type = 4;
break;
case 'socks5':
lookup = true;
// pass through
case 'socks': // no version specified, default to 5h
case 'socks5h':
type = 5;
break;
default:
throw new TypeError(`A "socks" protocol must be specified! Got: ${String(opts.protocol)}`);
}
}
if (typeof opts.type !== 'undefined') {
if (opts.type === 4 || opts.type === 5) {
type = opts.type;
}
else {
throw new TypeError(`"type" must be 4 or 5, got: ${String(opts.type)}`);
}
}
const proxy = {
host,
port,
type
};
let userId = (_a = opts.userId) !== null && _a !== void 0 ? _a : opts.username;
let password = opts.password;
if (opts.auth != null) {
const auth = opts.auth.split(':');
userId = auth[0];
password = auth[1];
}
if (userId != null) {
Object.defineProperty(proxy, 'userId', {
value: userId,
enumerable: false
});
}
if (password != null) {
Object.defineProperty(proxy, 'password', {
value: password,
enumerable: false
});
}
return { lookup, proxy };
}
(function (createSocksProxyAgent) {
createSocksProxyAgent.SocksProxyAgent = agent_1.default;
createSocksProxyAgent.prototype = agent_1.default.prototype;
})(createSocksProxyAgent || (createSocksProxyAgent = {}));
module.exports = createSocksProxyAgent;
const normalizeProxyOptions = (input) => {
let proxyOptions;
if (typeof input === 'string') {
proxyOptions = new URL(input);
}
else {
proxyOptions = input;
}
if (proxyOptions == null) {
throw new TypeError('a SOCKS proxy server `host` and `port` must be specified!');
}
return proxyOptions;
};
class SocksProxyAgent extends agent_base_1.Agent {
constructor(input, options) {
var _a, _b;
const proxyOptions = normalizeProxyOptions(input);
super(proxyOptions);
const parsedProxy = parseSocksProxy(proxyOptions);
this.lookup = parsedProxy.lookup;
this.proxy = parsedProxy.proxy;
this.tlsConnectionOptions = proxyOptions.tls != null ? proxyOptions.tls : {};
this.dnsCache = (_a = options === null || options === void 0 ? void 0 : options.dnsCache) !== null && _a !== void 0 ? _a : new cacheable_lookup_1.default();
this.timeout = (_b = options === null || options === void 0 ? void 0 : options.timeout) !== null && _b !== void 0 ? _b : null;
}
/**
* Initiates a SOCKS connection to the specified SOCKS proxy server,
* which in turn connects to the specified remote host and port.
*
* @api protected
*/
callback(req, opts) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const { lookup, proxy, timeout } = this;
let { host, port } = opts;
if (host == null) {
throw new Error('No `host` defined!');
}
if (lookup) {
// Client-side DNS resolution for "4" and "5" socks proxy versions.
const res = yield this.dnsCache.lookupAsync(host);
host = res.address;
}
const socksOpts = {
proxy,
destination: { host, port },
command: 'connect',
timeout: timeout !== null && timeout !== void 0 ? timeout : undefined
};
const cleanup = (tlsSocket) => {
req.destroy();
socket.destroy();
if (tlsSocket)
tlsSocket.destroy();
};
debug('Creating socks proxy connection: %o', socksOpts);
const { socket } = yield socks_1.SocksClient.createConnection(socksOpts);
debug('Successfully created socks proxy connection');
if (timeout !== null) {
socket.setTimeout(timeout);
socket.on('timeout', () => cleanup());
}
if (opts.secureEndpoint) {
// The proxy is connecting to a TLS server, so upgrade
// this socket connection to a TLS connection.
debug('Upgrading socket connection to TLS');
const servername = (_a = opts.servername) !== null && _a !== void 0 ? _a : opts.host;
const tlsSocket = tls_1.default.connect(Object.assign(Object.assign(Object.assign({}, omit(opts, 'host', 'hostname', 'path', 'port')), { socket,
servername }), this.tlsConnectionOptions));
tlsSocket.once('error', (error) => {
debug('socket TLS error', error.message);
cleanup(tlsSocket);
});
return tlsSocket;
}
return socket;
});
}
}
exports.SocksProxyAgent = SocksProxyAgent;
function omit(obj, ...keys) {
const ret = {};
let key;
for (key in obj) {
if (!keys.includes(key)) {
ret[key] = obj[key];
}
}
return ret;
}
//# sourceMappingURL=index.js.map
{
"name": "socks-proxy-agent",
"version": "6.1.1",
"description": "A SOCKS proxy `http.Agent` implementation for HTTP and HTTPS",
"main": "dist/index",
"typings": "dist/index.d.ts",
"files": [
"dist"
"homepage": "https://github.com/TooTallNate/node-socks-proxy-agent#readme",
"version": "6.2.0-beta.0",
"main": "dist/index.js",
"author": {
"email": "nathan@tootallnate.net",
"name": "Nathan Rajlich",
"url": "http://n8.io/"
},
"contributors": [
{
"name": "Kiko Beats",
"email": "josefrancisco.verdu@gmail.com"
},
{
"name": "Josh Glazebrook",
"email": "josh@joshglazebrook.com"
},
{
"name": "talmobi",
"email": "talmobi@users.noreply.github.com"
},
{
"name": "Kilian von Pflugk",
"email": "github@jumoog.io"
},
{
"name": "Kyle",
"email": "admin@hk1229.cn"
},
{
"name": "Shantanu Sharma",
"email": "shantanu34@outlook.com"
},
{
"name": "Vadim Baryshev",
"email": "vadimbaryshev@gmail.com"
},
{
"name": "Alba Mendez",
"email": "me@jmendeth.com"
},
{
"name": "Дмитрий Гуденков",
"email": "Dimangud@rambler.ru"
},
{
"name": "Andrei Bitca",
"email": "63638922+andrei-bitca-dc@users.noreply.github.com"
},
{
"name": "Andrew Casey",
"email": "amcasey@users.noreply.github.com"
},
{
"name": "Dang Duy Thanh",
"email": "thanhdd.it@gmail.com"
},
{
"name": "Indospace.io",
"email": "justin@indospace.io"
}
],
"scripts": {
"prebuild": "rimraf dist",
"build": "tsc",
"test": "mocha --reporter spec",
"test-lint": "eslint src --ext .js,.ts",
"prepublishOnly": "npm run build"
},
"repository": {

@@ -21,3 +70,10 @@ "type": "git",

},
"bugs": {
"url": "https://github.com/TooTallNate/node-socks-proxy-agent/issues"
},
"keywords": [
"agent",
"http",
"https",
"proxy",
"socks",

@@ -27,35 +83,30 @@ "socks4",

"socks5",
"socks5h",
"proxy",
"http",
"https",
"agent"
"socks5h"
],
"author": "Nathan Rajlich <nathan@tootallnate.net> (http://n8.io/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/TooTallNate/node-socks-proxy-agent/issues"
},
"dependencies": {
"agent-base": "^6.0.2",
"debug": "^4.3.1",
"socks": "^2.6.1"
"cacheable-lookup": "~6.0.4",
"debug": "^4.3.3",
"socks": "^2.6.2"
},
"devDependencies": {
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
"@types/debug": "latest",
"@types/node": "latest",
"@typescript-eslint/eslint-plugin": "latest",
"@typescript-eslint/parser": "latest",
"eslint": "latest",
"eslint-config-airbnb": "latest",
"eslint-config-prettier": "latest",
"eslint-import-resolver-typescript": "latest",
"eslint-plugin-import": "latest",
"eslint-plugin-jsx-a11y": "latest",
"eslint-plugin-react": "latest",
"conventional-github-releaser": "latest",
"finepack": "latest",
"git-authors-cli": "latest",
"mocha": "latest",
"proxy": "latest",
"nano-staged": "latest",
"npm-check-updates": "latest",
"prettier-standard": "latest",
"raw-body": "latest",
"rimraf": "latest",
"socksv5": "TooTallNate/socksv5#fix/dstSock-close-event",
"simple-git-hooks": "latest",
"socksv5": "github:TooTallNate/socksv5#fix/dstSock-close-event",
"standard": "latest",
"standard-markdown": "latest",
"standard-version": "latest",
"ts-standard": "latest",
"typescript": "latest"

@@ -65,3 +116,33 @@ },

"node": ">= 10"
}
}
},
"files": [
"dist"
],
"license": "MIT",
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"simple-git-hooks": {
"commit-msg": "npx commitlint --edit",
"pre-commit": "npx nano-staged"
},
"typings": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"clean": "rimraf node_modules",
"contributors": "(git-authors-cli && finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
"lint": "ts-standard",
"postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
"prebuild": "rimraf dist",
"prerelease": "npm run update:check && npm run contributors",
"release": "standard-version -a",
"release:github": "conventional-github-releaser -p angular",
"release:tags": "git push --follow-tags origin HEAD:master",
"test": "mocha --reporter spec",
"update": "ncu -u",
"update:check": "ncu -- --error-level 2"
},
"readme": "socks-proxy-agent\n================\n### A SOCKS proxy `http.Agent` implementation for HTTP and HTTPS\n[![Build Status](https://github.com/TooTallNate/node-socks-proxy-agent/workflows/Node%20CI/badge.svg)](https://github.com/TooTallNate/node-socks-proxy-agent/actions?workflow=Node+CI)\n\nThis module provides an `http.Agent` implementation that connects to a\nspecified SOCKS proxy server, and can be used with the built-in `http`\nand `https` modules.\n\nIt can also be used in conjunction with the `ws` module to establish a WebSocket\nconnection over a SOCKS proxy. See the \"Examples\" section below.\n\nInstallation\n------------\n\nInstall with `npm`:\n\n``` bash\n$ npm install socks-proxy-agent\n```\n\n\nExamples\n--------\n\n#### TypeScript example\n\n```ts\nimport https from 'https';\nimport { SocksProxyAgent } from 'socks-proxy-agent';\n\nconst info = {\n\thost: 'br41.nordvpn.com',\n\tuserId: 'your-name@gmail.com',\n\tpassword: 'abcdef12345124'\n};\nconst agent = new SocksProxyAgent(info);\n\nhttps.get('https://jsonip.org', { agent }, (res) => {\n\tconsole.log(res.headers);\n\tres.pipe(process.stdout);\n});\n```\n\n#### `http` module example\n\n```js\nvar url = require('url');\nvar http = require('http');\nvar SocksProxyAgent = require('socks-proxy-agent');\n\n// SOCKS proxy to connect to\nvar proxy = process.env.socks_proxy || 'socks://127.0.0.1:1080';\nconsole.log('using proxy server %j', proxy);\n\n// HTTP endpoint for the proxy to connect to\nvar endpoint = process.argv[2] || 'http://nodejs.org/api/';\nconsole.log('attempting to GET %j', endpoint);\nvar opts = url.parse(endpoint);\n\n// create an instance of the `SocksProxyAgent` class with the proxy server information\nvar agent = new SocksProxyAgent(proxy);\nopts.agent = agent;\n\nhttp.get(opts, function (res) {\n\tconsole.log('\"response\" event!', res.headers);\n\tres.pipe(process.stdout);\n});\n```\n\n#### `https` module example\n\n```js\nvar url = require('url');\nvar https = require('https');\nvar SocksProxyAgent = require('socks-proxy-agent');\n\n// SOCKS proxy to connect to\nvar proxy = process.env.socks_proxy || 'socks://127.0.0.1:1080';\nconsole.log('using proxy server %j', proxy);\n\n// HTTP endpoint for the proxy to connect to\nvar endpoint = process.argv[2] || 'https://encrypted.google.com/';\nconsole.log('attempting to GET %j', endpoint);\nvar opts = url.parse(endpoint);\n\n// create an instance of the `SocksProxyAgent` class with the proxy server information\nvar agent = new SocksProxyAgent(proxy);\nopts.agent = agent;\n\nhttps.get(opts, function (res) {\n\tconsole.log('\"response\" event!', res.headers);\n\tres.pipe(process.stdout);\n});\n```\n\n#### `ws` WebSocket connection example\n\n``` js\nvar WebSocket = require('ws');\nvar SocksProxyAgent = require('socks-proxy-agent');\n\n// SOCKS proxy to connect to\nvar proxy = process.env.socks_proxy || 'socks://127.0.0.1:1080';\nconsole.log('using proxy server %j', proxy);\n\n// WebSocket endpoint for the proxy to connect to\nvar endpoint = process.argv[2] || 'ws://echo.websocket.org';\nconsole.log('attempting to connect to WebSocket %j', endpoint);\n\n// create an instance of the `SocksProxyAgent` class with the proxy server information\nvar agent = new SocksProxyAgent(proxy);\n\n// initiate the WebSocket connection\nvar socket = new WebSocket(endpoint, { agent: agent });\n\nsocket.on('open', function () {\n\tconsole.log('\"open\" event!');\n\tsocket.send('hello world');\n});\n\nsocket.on('message', function (data, flags) {\n\tconsole.log('\"message\" event! %j %j', data, flags);\n\tsocket.close();\n});\n```\n\nLicense\n-------\n\n(The MIT License)\n\nCopyright (c) 2013 Nathan Rajlich &lt;nathan@tootallnate.net&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc