Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/popular-toys-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"pac-proxy-agent": minor
---

Expose `PacProxyAgent.getResolver()` publicly
4 changes: 1 addition & 3 deletions packages/pac-proxy-agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ export class PacProxyAgent<Uri extends string> extends Agent {
/**
* Loads the PAC proxy file from the source if necessary, and returns
* a generated `FindProxyForURL()` resolver function to use.
*
* @api private
*/
private getResolver(): Promise<FindProxyForURL> {
getResolver(): Promise<FindProxyForURL> {
if (!this.resolverPromise) {
this.resolverPromise = this.loadResolver();
this.resolverPromise.then(
Expand Down
15 changes: 15 additions & 0 deletions packages/pac-proxy-agent/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ describe('PacProxyAgent', () => {
});
});

describe('getResolver', () => {
it('should allow lookups without connecting', async () => {
function FindProxyForURL() {
return 'PROXY http-proxy.example.org:443;';
}

const uri = `data:,${encodeURIComponent(FindProxyForURL.toString())}`;
const agent = new PacProxyAgent(uri);

const resolver = await agent.getResolver();
const proxy = await resolver("https://example.com/test")
assert.equal(proxy, "PROXY http-proxy.example.org:443;")
});
})

describe('"http" module', () => {
it('should work over an HTTP proxy', async () => {
httpServer.once('request', function (req, res) {
Expand Down
Loading