chore: allow custom path for gRPC (grpc-service-name start with /)

This commit is contained in:
wwqgtxx
2025-12-21 10:28:05 +08:00
parent 911211578c
commit 5585304d68
2 changed files with 12 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ import (
"io"
"net"
"net/url"
"strings"
"sync"
"time"
@@ -331,11 +332,19 @@ func NewHTTP2Client(dialFn DialFn, tlsConfig *tls.Config, clientFingerprint stri
return wrap
}
func ServiceNameToPath(serviceName string) string {
if strings.HasPrefix(serviceName, "/") { // custom paths
return serviceName
}
return "/" + serviceName + "/Tun"
}
func StreamGunWithTransport(transport *TransportWrap, cfg *Config) (net.Conn, error) {
serviceName := "GunService"
if cfg.ServiceName != "" {
serviceName = cfg.ServiceName
}
path := ServiceNameToPath(serviceName)
reader, writer := io.Pipe()
request := &http.Request{
@@ -344,9 +353,9 @@ func StreamGunWithTransport(transport *TransportWrap, cfg *Config) (net.Conn, er
URL: &url.URL{
Scheme: "https",
Host: cfg.Host,
Path: fmt.Sprintf("/%s/Tun", serviceName),
Path: path,
// for unescape path
Opaque: fmt.Sprintf("//%s/%s/Tun", cfg.Host, serviceName),
Opaque: "//" + cfg.Host + path,
},
Proto: "HTTP/2",
ProtoMajor: 2,

View File

@@ -24,7 +24,7 @@ type ServerOption struct {
}
func NewServerHandler(options ServerOption) http.Handler {
path := "/" + options.ServiceName + "/Tun"
path := ServiceNameToPath(options.ServiceName)
connHandler := options.ConnHandler
httpHandler := options.HttpHandler
if httpHandler == nil {