http-proxy-agent
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -30,4 +30,4 @@ /// <reference types="node" /> | ||
*/ | ||
callback(req: HttpProxyAgentClientRequest, opts: RequestOptions): net.Socket; | ||
callback(req: HttpProxyAgentClientRequest, 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) { | ||
@@ -10,2 +19,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const debug_1 = __importDefault(require("debug")); | ||
const once_1 = __importDefault(require("@tootallnate/once")); | ||
const agent_base_1 = require("agent-base"); | ||
@@ -65,63 +75,70 @@ const debug = debug_1.default('http-proxy-agent'); | ||
callback(req, opts) { | ||
const { proxy, secureProxy } = this; | ||
const parsed = url_1.default.parse(req.path); | ||
if (!parsed.protocol) { | ||
parsed.protocol = 'http:'; | ||
} | ||
if (!parsed.hostname) { | ||
parsed.hostname = opts.hostname || opts.host || null; | ||
} | ||
if (parsed.port == null && typeof opts.port) { | ||
parsed.port = String(opts.port); | ||
} | ||
if (parsed.port === '80') { | ||
// if port is 80, then we can remove the port so that the | ||
// ":80" portion is not on the produced URL | ||
delete parsed.port; | ||
} | ||
// Change the `http.ClientRequest` instance's "path" field | ||
// to the absolute path of the URL that will be requested. | ||
req.path = url_1.default.format(parsed); | ||
// Inject the `Proxy-Authorization` header if necessary. | ||
if (proxy.auth) { | ||
req.setHeader('Proxy-Authorization', `Basic ${Buffer.from(proxy.auth).toString('base64')}`); | ||
} | ||
// create a socket connection to the proxy server | ||
let socket; | ||
if (secureProxy) { | ||
debug('Creating `tls.Socket`: %o', proxy); | ||
socket = tls_1.default.connect(proxy); | ||
} | ||
else { | ||
debug('Creating `net.Socket`: %o', proxy); | ||
socket = net_1.default.connect(proxy); | ||
} | ||
// 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`. | ||
if (req._header) { | ||
let first; | ||
let endOfHeaders; | ||
debug('Regenerating stored HTTP header string for request'); | ||
req._header = null; | ||
req._implicitHeader(); | ||
if (req.output && req.output.length > 0) { | ||
// Node < 12 | ||
debug('Patching connection write() output buffer with updated header'); | ||
first = req.output[0]; | ||
endOfHeaders = first.indexOf('\r\n\r\n') + 4; | ||
req.output[0] = req._header + first.substring(endOfHeaders); | ||
debug('Output buffer: %o', req.output); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { proxy, secureProxy } = this; | ||
const parsed = url_1.default.parse(req.path); | ||
if (!parsed.protocol) { | ||
parsed.protocol = 'http:'; | ||
} | ||
else 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); | ||
if (!parsed.hostname) { | ||
parsed.hostname = opts.hostname || opts.host || null; | ||
} | ||
} | ||
return socket; | ||
if (parsed.port == null && typeof opts.port) { | ||
parsed.port = String(opts.port); | ||
} | ||
if (parsed.port === '80') { | ||
// if port is 80, then we can remove the port so that the | ||
// ":80" portion is not on the produced URL | ||
delete parsed.port; | ||
} | ||
// Change the `http.ClientRequest` instance's "path" field | ||
// to the absolute path of the URL that will be requested. | ||
req.path = url_1.default.format(parsed); | ||
// Inject the `Proxy-Authorization` header if necessary. | ||
if (proxy.auth) { | ||
req.setHeader('Proxy-Authorization', `Basic ${Buffer.from(proxy.auth).toString('base64')}`); | ||
} | ||
// Create a socket connection to the proxy server. | ||
let socket; | ||
if (secureProxy) { | ||
debug('Creating `tls.Socket`: %o', proxy); | ||
socket = tls_1.default.connect(proxy); | ||
} | ||
else { | ||
debug('Creating `net.Socket`: %o', proxy); | ||
socket = net_1.default.connect(proxy); | ||
} | ||
// 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`. | ||
if (req._header) { | ||
let first; | ||
let endOfHeaders; | ||
debug('Regenerating stored HTTP header string for request'); | ||
req._header = null; | ||
req._implicitHeader(); | ||
if (req.output && req.output.length > 0) { | ||
// Node < 12 | ||
debug('Patching connection write() output buffer with updated header'); | ||
first = req.output[0]; | ||
endOfHeaders = first.indexOf('\r\n\r\n') + 4; | ||
req.output[0] = req._header + first.substring(endOfHeaders); | ||
debug('Output buffer: %o', req.output); | ||
} | ||
else 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. | ||
yield once_1.default(socket, 'connect'); | ||
return socket; | ||
}); | ||
} | ||
@@ -128,0 +145,0 @@ } |
{ | ||
"name": "http-proxy-agent", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "An HTTP(s) proxy `http.Agent` implementation for HTTP", | ||
"main": "dist/index", | ||
"typings": "dist/index", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
@@ -33,2 +33,3 @@ "dist" | ||
"dependencies": { | ||
"@tootallnate/once": "1", | ||
"agent-base": "6", | ||
@@ -35,0 +36,0 @@ "debug": "4" |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
17062
210
2
3
+ Added@tootallnate/once@1
+ Added@tootallnate/once@1.1.2(transitive)