http-proxy-agent
Advanced tools
Comparing version 6.0.1 to 6.1.0
@@ -50,2 +50,3 @@ "use strict"; | ||
this.proxy = typeof proxy === 'string' ? new URL(proxy) : proxy; | ||
this.proxyHeaders = opts?.headers ?? {}; | ||
debug('Creating new HttpProxyAgent instance: %o', this.proxy.href); | ||
@@ -60,3 +61,3 @@ // Trim off the brackets from IPv6 addresses | ||
this.connectOpts = { | ||
...opts, | ||
...(opts ? omit(opts, 'headers') : null), | ||
host, | ||
@@ -80,9 +81,20 @@ port, | ||
req._header = null; | ||
const headers = typeof this.proxyHeaders === 'function' | ||
? this.proxyHeaders() | ||
: { ...this.proxyHeaders }; | ||
if (proxy.username || proxy.password) { | ||
const auth = `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`; | ||
req.setHeader('Proxy-Authorization', `Basic ${Buffer.from(auth).toString('base64')}`); | ||
headers['Proxy-Authorization'] = `Basic ${Buffer.from(auth).toString('base64')}`; | ||
} | ||
if (!req.hasHeader('proxy-connection')) { | ||
req.setHeader('Proxy-Connection', this.keepAlive ? 'Keep-Alive' : 'close'); | ||
if (!headers['Proxy-Connection']) { | ||
headers['Proxy-Connection'] = this.keepAlive | ||
? 'Keep-Alive' | ||
: 'close'; | ||
} | ||
for (const name of Object.keys(headers)) { | ||
const value = headers[name]; | ||
if (value) { | ||
req.setHeader(name, value); | ||
} | ||
} | ||
// Create a socket connection to the proxy server. | ||
@@ -124,2 +136,12 @@ let socket; | ||
exports.HttpProxyAgent = HttpProxyAgent; | ||
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 |
@@ -8,2 +8,3 @@ /// <reference types="node" /> | ||
import * as http from 'http'; | ||
import type { OutgoingHttpHeaders } from 'http'; | ||
import { Agent, AgentConnectOpts } from 'agent-base'; | ||
@@ -18,3 +19,5 @@ type Protocol<T> = T extends `${infer Protocol}:${infer _}` ? Protocol : never; | ||
}[keyof ConnectOptsMap]; | ||
export type HttpProxyAgentOptions<T> = ConnectOpts<T> & http.AgentOptions; | ||
export type HttpProxyAgentOptions<T> = ConnectOpts<T> & http.AgentOptions & { | ||
headers?: OutgoingHttpHeaders | (() => OutgoingHttpHeaders); | ||
}; | ||
interface HttpProxyAgentClientRequest extends http.ClientRequest { | ||
@@ -34,2 +37,3 @@ outputData?: { | ||
readonly proxy: URL; | ||
proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders); | ||
connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions; | ||
@@ -36,0 +40,0 @@ get secureProxy(): boolean; |
@@ -50,2 +50,3 @@ "use strict"; | ||
this.proxy = typeof proxy === 'string' ? new URL(proxy) : proxy; | ||
this.proxyHeaders = opts?.headers ?? {}; | ||
debug('Creating new HttpProxyAgent instance: %o', this.proxy.href); | ||
@@ -60,3 +61,3 @@ // Trim off the brackets from IPv6 addresses | ||
this.connectOpts = { | ||
...opts, | ||
...(opts ? omit(opts, 'headers') : null), | ||
host, | ||
@@ -80,9 +81,20 @@ port, | ||
req._header = null; | ||
const headers = typeof this.proxyHeaders === 'function' | ||
? this.proxyHeaders() | ||
: { ...this.proxyHeaders }; | ||
if (proxy.username || proxy.password) { | ||
const auth = `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`; | ||
req.setHeader('Proxy-Authorization', `Basic ${Buffer.from(auth).toString('base64')}`); | ||
headers['Proxy-Authorization'] = `Basic ${Buffer.from(auth).toString('base64')}`; | ||
} | ||
if (!req.hasHeader('proxy-connection')) { | ||
req.setHeader('Proxy-Connection', this.keepAlive ? 'Keep-Alive' : 'close'); | ||
if (!headers['Proxy-Connection']) { | ||
headers['Proxy-Connection'] = this.keepAlive | ||
? 'Keep-Alive' | ||
: 'close'; | ||
} | ||
for (const name of Object.keys(headers)) { | ||
const value = headers[name]; | ||
if (value) { | ||
req.setHeader(name, value); | ||
} | ||
} | ||
// Create a socket connection to the proxy server. | ||
@@ -124,2 +136,12 @@ let socket; | ||
exports.HttpProxyAgent = HttpProxyAgent; | ||
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": "http-proxy-agent", | ||
"version": "6.0.1", | ||
"version": "6.1.0", | ||
"description": "An HTTP(s) proxy `http.Agent` implementation for HTTP", | ||
@@ -24,3 +24,3 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"agent-base": "^7.0.1", | ||
"agent-base": "^7.0.2", | ||
"debug": "^4.3.4" | ||
@@ -36,3 +36,3 @@ }, | ||
"typescript": "^5.0.4", | ||
"proxy": "2.0.1", | ||
"proxy": "2.1.1", | ||
"tsconfig": "0.0.0" | ||
@@ -39,0 +39,0 @@ }, |
@@ -27,2 +27,21 @@ http-proxy-agent | ||
API | ||
--- | ||
### new HttpProxyAgent(proxy: string | URL, options?: HttpProxyAgentOptions) | ||
The `HttpProxyAgent` class implements an `http.Agent` subclass that connects | ||
to the specified "HTTP(s) proxy server" in order to proxy HTTP requests. | ||
The `proxy` argument is the URL for the proxy server. | ||
The `options` argument accepts the usual `http.Agent` constructor options, and | ||
some additional properties: | ||
* `headers` - Object containing additional headers to send to the proxy server | ||
in each request. This may also be a function that returns a headers object. | ||
**NOTE:** If your proxy does not strip these headers from the request, they | ||
will also be sent to the destination server. | ||
License | ||
@@ -29,0 +48,0 @@ ------- |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
23582
325
71
Updatedagent-base@^7.0.2