Skip to content

Commit

Permalink
fix: process http over https proxy correctly (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
barjin authored Mar 25, 2024
1 parent 5c78d35 commit ed636cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/hooks/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Options, type Agents } from 'got';
import http2, { auto } from 'http2-wrapper';
import { URL } from 'node:url';
import { HttpRegularProxyAgent, HttpsProxyAgent } from '../agent/h1-proxy-agent.js';
import { HttpProxyAgent, HttpRegularProxyAgent, HttpsProxyAgent } from '../agent/h1-proxy-agent.js';
import { TransformHeadersAgent } from '../agent/transform-headers-agent.js';

const {
Expand Down Expand Up @@ -87,7 +87,7 @@ async function getAgents(parsedProxyUrl: URL, rejectUnauthorized: boolean) {
} else {
// Upstream proxies hang up connections on CONNECT + unsecure HTTP
agent = {
http: new TransformHeadersAgent(new HttpRegularProxyAgent(nativeOptions)),
http: new TransformHeadersAgent(new HttpProxyAgent(nativeOptions)),
https: new TransformHeadersAgent(new HttpsProxyAgent(nativeOptions)),
http2: new Http2OverHttps(wrapperOptions),
};
Expand Down
3 changes: 2 additions & 1 deletion test/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { jest } from '@jest/globals';
import {
HttpsProxyAgent,
HttpRegularProxyAgent,
HttpProxyAgent,
} from '../src/agent/h1-proxy-agent.js';

import { proxyHook } from '../src/hooks/proxy.js';
Expand Down Expand Up @@ -96,7 +97,7 @@ describe('Proxy', () => {

const { agent } = options;
expect(agent.http).toBeInstanceOf(TransformHeadersAgent);
expect((agent.http as any).agent).toBeInstanceOf(HttpRegularProxyAgent);
expect((agent.http as any).agent).toBeInstanceOf(HttpProxyAgent);
});

test('should support https request over https proxy', async () => {
Expand Down

0 comments on commit ed636cb

Please sign in to comment.