Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-proxy-agent

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-proxy-agent - npm Package Compare versions

Comparing version 5.0.0 to 6.0.0

./dist/index.js

55

dist/index.d.ts
/// <reference types="node" />
import net from 'net';
import tls from 'tls';
import { Url } from 'url';
import { AgentOptions } from 'agent-base';
import _HttpProxyAgent from './agent';
declare function createHttpProxyAgent(opts: string | createHttpProxyAgent.HttpProxyAgentOptions): _HttpProxyAgent;
declare namespace createHttpProxyAgent {
interface BaseHttpProxyAgentOptions {
secureProxy?: boolean;
host?: string | null;
path?: string | null;
port?: string | number | null;
}
export interface HttpProxyAgentOptions extends AgentOptions, BaseHttpProxyAgentOptions, Partial<Omit<Url & net.NetConnectOpts & tls.ConnectionOptions, keyof BaseHttpProxyAgentOptions>> {
}
export type HttpProxyAgent = _HttpProxyAgent;
export const HttpProxyAgent: typeof _HttpProxyAgent;
export {};
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import * as net from 'net';
import * as tls from 'tls';
import * as http from 'http';
import { Agent, AgentConnectOpts } from 'agent-base';
type Protocol<T> = T extends `${infer Protocol}:${infer _}` ? Protocol : never;
type ConnectOptsMap = {
http: Omit<net.TcpNetConnectOpts, 'host' | 'port'>;
https: Omit<tls.ConnectionOptions, 'host' | 'port'>;
};
type ConnectOpts<T> = {
[P in keyof ConnectOptsMap]: Protocol<T> extends P ? ConnectOptsMap[P] : never;
}[keyof ConnectOptsMap];
export type HttpProxyAgentOptions<T> = ConnectOpts<T> & http.AgentOptions;
interface HttpProxyAgentClientRequest extends http.ClientRequest {
outputData?: {
data: string;
}[];
_header?: string | null;
_implicitHeader(): void;
}
export = createHttpProxyAgent;
/**
* The `HttpProxyAgent` implements an HTTP Agent subclass that connects
* to the specified "HTTP proxy server" in order to proxy HTTP requests.
*/
export declare class HttpProxyAgent<Uri extends string> extends Agent {
static protocols: readonly ["http", "https"];
readonly proxy: URL;
connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;
get secureProxy(): boolean;
constructor(proxy: Uri | URL, opts?: HttpProxyAgentOptions<Uri>);
connect(req: HttpProxyAgentClientRequest, opts: AgentConnectOpts): Promise<net.Socket>;
}
export {};
//# sourceMappingURL=index.d.ts.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
const agent_1 = __importDefault(require("./agent"));
function createHttpProxyAgent(opts) {
return new agent_1.default(opts);
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpProxyAgent = void 0;
const net = __importStar(require("net"));
const tls = __importStar(require("tls"));
const debug_1 = __importDefault(require("debug"));
const events_1 = require("events");
const agent_base_1 = require("agent-base");
const debug = (0, debug_1.default)('http-proxy-agent');
function isHTTPS(protocol) {
return typeof protocol === 'string' ? /^https:?$/i.test(protocol) : false;
}
(function (createHttpProxyAgent) {
createHttpProxyAgent.HttpProxyAgent = agent_1.default;
createHttpProxyAgent.prototype = agent_1.default.prototype;
})(createHttpProxyAgent || (createHttpProxyAgent = {}));
module.exports = createHttpProxyAgent;
/**
* The `HttpProxyAgent` implements an HTTP Agent subclass that connects
* to the specified "HTTP proxy server" in order to proxy HTTP requests.
*/
class HttpProxyAgent extends agent_base_1.Agent {
get secureProxy() {
return isHTTPS(this.proxy.protocol);
}
constructor(proxy, opts) {
super(opts);
this.proxy = typeof proxy === 'string' ? new URL(proxy) : proxy;
debug('Creating new HttpProxyAgent instance: %o', this.proxy.href);
// Trim off the brackets from IPv6 addresses
const host = (this.proxy.hostname || this.proxy.host).replace(/^\[|\]$/g, '');
const port = this.proxy.port
? parseInt(this.proxy.port, 10)
: this.secureProxy
? 443
: 80;
this.connectOpts = {
...opts,
host,
port,
};
}
async connect(req, opts) {
const { proxy } = this;
const protocol = opts.secureEndpoint ? 'https:' : 'http:';
const hostname = req.getHeader('host') || 'localhost';
const base = `${protocol}//${hostname}`;
const url = new URL(req.path, base);
if (opts.port !== 80) {
url.port = String(opts.port);
}
// Change the `http.ClientRequest` instance's "path" field
// to the absolute path of the URL that will be requested.
req.path = String(url);
// Inject the `Proxy-Authorization` header if necessary.
req._header = null;
if (proxy.username || proxy.password) {
const auth = `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`;
req.setHeader('Proxy-Authorization', `Basic ${Buffer.from(auth).toString('base64')}`);
}
if (!req.hasHeader('proxy-connection')) {
req.setHeader('Proxy-Connection', this.keepAlive ? 'Keep-Alive' : 'close');
}
// Create a socket connection to the proxy server.
let socket;
if (this.secureProxy) {
debug('Creating `tls.Socket`: %o', this.connectOpts);
socket = tls.connect(this.connectOpts);
}
else {
debug('Creating `net.Socket`: %o', this.connectOpts);
socket = net.connect(this.connectOpts);
}
// At this point, the http ClientRequest's internal `_header` field
// might have already been set. If this is the case then we'll need
// to re-generate the string since we just changed the `req.path`.
let first;
let endOfHeaders;
debug('Regenerating stored HTTP header string for request');
req._implicitHeader();
if (req.outputData && req.outputData.length > 0) {
// Node >= 12
debug('Patching connection write() output buffer with updated header');
first = req.outputData[0].data;
endOfHeaders = first.indexOf('\r\n\r\n') + 4;
req.outputData[0].data =
req._header + first.substring(endOfHeaders);
debug('Output buffer: %o', req.outputData[0].data);
}
// Wait for the socket's `connect` event, so that this `callback()`
// function throws instead of the `http` request machinery. This is
// important for i.e. `PacProxyAgent` which determines a failed proxy
// connection via the `callback()` function throwing.
await (0, events_1.once)(socket, 'connect');
return socket;
}
}
HttpProxyAgent.protocols = ['http', 'https'];
exports.HttpProxyAgent = HttpProxyAgent;
//# sourceMappingURL=index.js.map
{
"name": "http-proxy-agent",
"version": "5.0.0",
"version": "6.0.0",
"description": "An HTTP(s) proxy `http.Agent` implementation for HTTP",

@@ -10,12 +10,6 @@ "main": "./dist/index.js",

],
"scripts": {
"prebuild": "rimraf dist",
"build": "tsc",
"test": "mocha",
"test-lint": "eslint src --ext .js,.ts",
"prepublishOnly": "npm run build"
},
"repository": {
"type": "git",
"url": "git://github.com/TooTallNate/node-http-proxy-agent.git"
"url": "https://github.com/TooTallNate/proxy-agents.git",
"directory": "packages/http-proxy-agent"
},

@@ -30,30 +24,26 @@ "keywords": [

"license": "MIT",
"bugs": {
"url": "https://github.com/TooTallNate/node-http-proxy-agent/issues"
},
"dependencies": {
"@tootallnate/once": "2",
"agent-base": "6",
"debug": "4"
"agent-base": "^7.0.0",
"debug": "^4.3.4"
},
"devDependencies": {
"@types/debug": "4",
"@types/node": "^12.19.2",
"@typescript-eslint/eslint-plugin": "1.6.0",
"@typescript-eslint/parser": "1.1.0",
"eslint": "5.16.0",
"eslint-config-airbnb": "17.1.0",
"eslint-config-prettier": "4.1.0",
"eslint-import-resolver-typescript": "1.1.1",
"eslint-plugin-import": "2.16.0",
"eslint-plugin-jsx-a11y": "6.2.1",
"eslint-plugin-react": "7.12.4",
"mocha": "^6.2.2",
"proxy": "1",
"rimraf": "^3.0.0",
"typescript": "^4.4.3"
"@types/debug": "^4.1.7",
"@types/jest": "^29.5.1",
"@types/node": "^14.18.43",
"async-listen": "^2.1.0",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"typescript": "^5.0.4",
"proxy": "2.0.0",
"tsconfig": "0.0.0"
},
"engines": {
"node": ">= 6"
"node": ">= 14"
},
"scripts": {
"build": "tsc",
"test": "jest --env node --verbose --bail",
"lint": "eslint . --ext .ts",
"pack": "node ../../scripts/pack.mjs"
}
}
}
http-proxy-agent
================
### An HTTP(s) proxy `http.Agent` implementation for HTTP
[![Build Status](https://github.com/TooTallNate/node-http-proxy-agent/workflows/Node%20CI/badge.svg)](https://github.com/TooTallNate/node-http-proxy-agent/actions?workflow=Node+CI)

@@ -10,36 +9,15 @@ This module provides an `http.Agent` implementation that connects to a specified

__Note:__ For HTTP proxy usage with the `https` module, check out
[`node-https-proxy-agent`](https://github.com/TooTallNate/node-https-proxy-agent).
[`https-proxy-agent`](../https-proxy-agent).
Installation
------------
Install with `npm`:
``` bash
$ npm install http-proxy-agent
```
Example
-------
``` js
var url = require('url');
var http = require('http');
var HttpProxyAgent = require('http-proxy-agent');
```ts
import * as http from 'http';
import { HttpProxyAgent } from 'http-proxy-agent';
// HTTP/HTTPS proxy to connect to
var proxy = process.env.http_proxy || 'http://168.63.76.32:3128';
console.log('using proxy server %j', proxy);
const agent = new HttpProxyAgent('http://168.63.76.32:3128');
// HTTP endpoint for the proxy to connect to
var endpoint = process.argv[2] || 'http://nodejs.org/api/';
console.log('attempting to GET %j', endpoint);
var opts = url.parse(endpoint);
// create an instance of the `HttpProxyAgent` class with the proxy server information
var agent = new HttpProxyAgent(proxy);
opts.agent = agent;
http.get(opts, function (res) {
http.get('http://nodejs.org/api/', { agent }, (res) => {
console.log('"response" event!', res.headers);

@@ -50,3 +28,2 @@ res.pipe(process.stdout);

License

@@ -53,0 +30,0 @@ -------

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