Comparing version 5.2.5 to 5.3.0
@@ -184,3 +184,3 @@ "use strict"; | ||
this.options.path = u.path || '/'; | ||
this.options.agent = this.options.agent || deps_1.deps.proxy.agent(this.secure); | ||
this.options.agent = this.options.agent || deps_1.deps.proxy.agent(this.secure, this.options.host); | ||
this.options.port = u.port || this.options.port || (this.secure ? 443 : 80); | ||
@@ -342,3 +342,3 @@ } | ||
let type = this.response.headers['content-type'] ? deps_1.deps.contentType.parse(this.response).type : ''; | ||
let json = type.startsWith('application/json') || type.startsWith('application/vnd.api+json'); | ||
let json = type.startsWith('application/json') || type.endsWith('+json'); | ||
if (json) | ||
@@ -345,0 +345,0 @@ this.body = JSONParse(this.body); |
@@ -6,7 +6,9 @@ /// <reference types="node" /> | ||
static readonly httpsProxy: string | undefined; | ||
static readonly usingProxy: boolean; | ||
static readonly noProxy: string | undefined; | ||
static shouldDodgeProxy(host: string): boolean; | ||
static usingProxy(host?: string): boolean; | ||
static readonly sslCertDir: Array<string>; | ||
static readonly sslCertFile: Array<string>; | ||
static readonly certs: Array<Buffer>; | ||
static agent(https: boolean): any; | ||
static agent(https: boolean, host?: string): any; | ||
} |
@@ -13,3 +13,18 @@ "use strict"; | ||
} | ||
static get usingProxy() { | ||
static get noProxy() { | ||
return this.env.NO_PROXY || this.env.no_proxy; | ||
} | ||
static shouldDodgeProxy(host) { | ||
if (!this.noProxy) | ||
return false; | ||
if (this.noProxy === '*') | ||
return true; | ||
return this.noProxy | ||
.split(',') | ||
.map(p => p.trim()) | ||
.some(p => (p[0] === '.' && host.endsWith(p.substr(1))) || host.endsWith(p)); | ||
} | ||
static usingProxy(host) { | ||
if (host && this.shouldDodgeProxy(host)) | ||
return false; | ||
if (this.httpProxy || this.httpsProxy) | ||
@@ -37,4 +52,4 @@ return true; | ||
} | ||
static agent(https) { | ||
if (!this.usingProxy) | ||
static agent(https, host) { | ||
if (!this.usingProxy(host)) | ||
return; | ||
@@ -41,0 +56,0 @@ const u = https ? this.httpsProxy || this.httpProxy : this.httpProxy; |
@@ -71,1 +71,69 @@ "use strict"; | ||
}); | ||
describe('with no_proxy', () => { | ||
beforeEach(() => { | ||
proxy_1.default.env.HTTP_PROXY = 'http://user:pass@foo.com'; | ||
proxy_1.default.env.NO_PROXY = 'some.com,test-domain.com'; | ||
}); | ||
test('is an exact match of no_proxy', () => { | ||
expect(proxy_1.default.agent(false, 'test-domain.com')).toBeUndefined(); | ||
}); | ||
test('is a subdomain of no_proxy', () => { | ||
expect(proxy_1.default.agent(false, 'something.prod.test-domain.com')).toBeUndefined(); | ||
}); | ||
test('should be proxied', () => { | ||
expect(proxy_1.default.agent(false, 'proxied-domain.com')).toMatchObject({ | ||
options: { | ||
proxy: { | ||
host: 'foo.com', | ||
port: '8080', | ||
proxyAuth: 'user:pass', | ||
}, | ||
}, | ||
proxyOptions: { | ||
host: 'foo.com', | ||
port: '8080', | ||
proxyAuth: 'user:pass', | ||
}, | ||
}); | ||
}); | ||
}); | ||
describe('proxy dodging', () => { | ||
test('not set should proxy', () => { | ||
proxy_1.default.env.NO_PROXY = ''; | ||
expect(proxy_1.default.shouldDodgeProxy('test-domain.com')).toBe(false); | ||
expect(proxy_1.default.shouldDodgeProxy('other-domain.com')).toBe(false); | ||
}); | ||
test('wildcard proxies any', () => { | ||
proxy_1.default.env.NO_PROXY = '*'; | ||
expect(proxy_1.default.shouldDodgeProxy('test-domain.com')).toBe(true); | ||
expect(proxy_1.default.shouldDodgeProxy('anything.other-domain.com')).toBe(true); | ||
}); | ||
test('exact domain should also match subdomains', () => { | ||
proxy_1.default.env.NO_PROXY = 'test-domain.com'; | ||
expect(proxy_1.default.shouldDodgeProxy('test-domain.com')).toBe(true); | ||
expect(proxy_1.default.shouldDodgeProxy('anything.test-domain.com')).toBe(true); | ||
expect(proxy_1.default.shouldDodgeProxy('other-domain.com')).toBe(false); | ||
expect(proxy_1.default.shouldDodgeProxy('anything.other-domain.com')).toBe(false); | ||
}); | ||
test('any sub domain should include the domain itself', () => { | ||
proxy_1.default.env.NO_PROXY = '.test-domain.com'; | ||
expect(proxy_1.default.shouldDodgeProxy('test-domain.com')).toBe(true); | ||
expect(proxy_1.default.shouldDodgeProxy('anything.test-domain.com')).toBe(true); | ||
expect(proxy_1.default.shouldDodgeProxy('other-domain.com')).toBe(false); | ||
expect(proxy_1.default.shouldDodgeProxy('anything.other-domain.com')).toBe(false); | ||
}); | ||
test('multiple domains', () => { | ||
proxy_1.default.env.NO_PROXY = '.test-domain.com, .other-domain.com'; | ||
expect(proxy_1.default.shouldDodgeProxy('test-domain.com')).toBe(true); | ||
expect(proxy_1.default.shouldDodgeProxy('anything.test-domain.com')).toBe(true); | ||
expect(proxy_1.default.shouldDodgeProxy('other-domain.com')).toBe(true); | ||
expect(proxy_1.default.shouldDodgeProxy('anything.other-domain.com')).toBe(true); | ||
}); | ||
test('match any subdomains', () => { | ||
proxy_1.default.env.NO_PROXY = '.test-domain.com, other-domain.com'; | ||
expect(proxy_1.default.shouldDodgeProxy('test-domain.com')).toBe(true); | ||
expect(proxy_1.default.shouldDodgeProxy('something.something-else.anything.test-domain.com')).toBe(true); | ||
expect(proxy_1.default.shouldDodgeProxy('other-domain.com')).toBe(true); | ||
expect(proxy_1.default.shouldDodgeProxy('something.anything.other-domain.com')).toBe(true); | ||
}); | ||
}); |
{ | ||
"name": "http-call", | ||
"description": "make http requests", | ||
"version": "5.2.5", | ||
"version": "5.3.0", | ||
"author": "Jeff Dickey @jdxcode", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/heroku/http-call/issues", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43903
1159