Skip to content

Commit cad45ff

Browse files
authored
Merge pull request #2578 from LemonZuo/feat_socks5h
feat: support socks5h scheme for proxy settings
2 parents 6a27bce + 163d683 commit cad45ff

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

internal/runtime/executor/codex_websockets_executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ func newProxyAwareWebsocketDialer(cfg *config.Config, auth *cliproxyauth.Auth) *
734734
}
735735

736736
switch setting.URL.Scheme {
737-
case "socks5":
737+
case "socks5", "socks5h":
738738
var proxyAuth *proxy.Auth
739739
if setting.URL.User != nil {
740740
username := setting.URL.User.Username()

sdk/proxyutil/proxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func Parse(raw string) (Setting, error) {
5858
}
5959

6060
switch parsedURL.Scheme {
61-
case "socks5", "http", "https":
61+
case "socks5", "socks5h", "http", "https":
6262
setting.Mode = ModeProxy
6363
setting.URL = parsedURL
6464
return setting, nil
@@ -95,7 +95,7 @@ func BuildHTTPTransport(raw string) (*http.Transport, Mode, error) {
9595
case ModeDirect:
9696
return NewDirectTransport(), setting.Mode, nil
9797
case ModeProxy:
98-
if setting.URL.Scheme == "socks5" {
98+
if setting.URL.Scheme == "socks5" || setting.URL.Scheme == "socks5h" {
9999
var proxyAuth *proxy.Auth
100100
if setting.URL.User != nil {
101101
username := setting.URL.User.Username()

sdk/proxyutil/proxy_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestParse(t *testing.T) {
3030
{name: "http", input: "http://proxy.example.com:8080", want: ModeProxy},
3131
{name: "https", input: "https://proxy.example.com:8443", want: ModeProxy},
3232
{name: "socks5", input: "socks5://proxy.example.com:1080", want: ModeProxy},
33+
{name: "socks5h", input: "socks5h://proxy.example.com:1080", want: ModeProxy},
3334
{name: "invalid", input: "bad-value", want: ModeInvalid, wantErr: true},
3435
}
3536

@@ -137,3 +138,24 @@ func TestBuildHTTPTransportSOCKS5ProxyInheritsDefaultTransportSettings(t *testin
137138
t.Fatalf("TLSHandshakeTimeout = %v, want %v", transport.TLSHandshakeTimeout, defaultTransport.TLSHandshakeTimeout)
138139
}
139140
}
141+
142+
func TestBuildHTTPTransportSOCKS5HProxy(t *testing.T) {
143+
t.Parallel()
144+
145+
transport, mode, errBuild := BuildHTTPTransport("socks5h://proxy.example.com:1080")
146+
if errBuild != nil {
147+
t.Fatalf("BuildHTTPTransport returned error: %v", errBuild)
148+
}
149+
if mode != ModeProxy {
150+
t.Fatalf("mode = %d, want %d", mode, ModeProxy)
151+
}
152+
if transport == nil {
153+
t.Fatal("expected transport, got nil")
154+
}
155+
if transport.Proxy != nil {
156+
t.Fatal("expected SOCKS5H transport to bypass http proxy function")
157+
}
158+
if transport.DialContext == nil {
159+
t.Fatal("expected SOCKS5H transport to have custom DialContext")
160+
}
161+
}

0 commit comments

Comments
 (0)