mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-24 13:38:05 +08:00
chore: allow custom path for gRPC (grpc-service-name start with /)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user