Skip to content

Commit

Permalink
[pac-proxy-agent] Expose PacProxyAgent.getResolver() publicly (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
akonradi-signal authored Feb 18, 2025
1 parent 3e69150 commit 9d462b8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
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

0 comments on commit 9d462b8

Please sign in to comment.