Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: process http over https proxy correctly #129

Merged
merged 2 commits into from
Mar 25, 2024
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
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
Loading