mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 17:38:41 +00:00
Add custom path to gRPC (#1815)
This commit is contained in:
parent
6872be5cc3
commit
526c6789ed
5 changed files with 166 additions and 17 deletions
|
@ -2,6 +2,7 @@ package grpc
|
|||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
|
@ -15,6 +16,41 @@ func init() {
|
|||
}))
|
||||
}
|
||||
|
||||
func (c *Config) getNormalizedName() string {
|
||||
return url.PathEscape(c.ServiceName)
|
||||
func (c *Config) getServiceName() string {
|
||||
// Normal old school config
|
||||
if !strings.HasPrefix(c.ServiceName, "/") {
|
||||
return url.PathEscape(c.ServiceName)
|
||||
}
|
||||
// Otherwise new custom paths
|
||||
rawServiceName := c.ServiceName[1:strings.LastIndex(c.ServiceName, "/")] // trim from first to last '/'
|
||||
serviceNameParts := strings.Split(rawServiceName, "/")
|
||||
for i := range serviceNameParts {
|
||||
serviceNameParts[i] = url.PathEscape(serviceNameParts[i])
|
||||
}
|
||||
return strings.Join(serviceNameParts, "/")
|
||||
}
|
||||
|
||||
func (c *Config) getTunStreamName() string {
|
||||
// Normal old school config
|
||||
if !strings.HasPrefix(c.ServiceName, "/") {
|
||||
return "Tun"
|
||||
}
|
||||
// Otherwise new custom paths
|
||||
endingPath := c.ServiceName[strings.LastIndex(c.ServiceName, "/")+1:] // from the last '/' to end of string
|
||||
return url.PathEscape(strings.Split(endingPath, "|")[0])
|
||||
}
|
||||
|
||||
func (c *Config) getTunMultiStreamName() string {
|
||||
// Normal old school config
|
||||
if !strings.HasPrefix(c.ServiceName, "/") {
|
||||
return "TunMulti"
|
||||
}
|
||||
// Otherwise new custom paths
|
||||
endingPath := c.ServiceName[strings.LastIndex(c.ServiceName, "/")+1:] // from the last '/' to end of string
|
||||
streamNames := strings.Split(endingPath, "|")
|
||||
if len(streamNames) == 1 { // client side. Service name is the full path to multi tun
|
||||
return url.PathEscape(streamNames[0])
|
||||
} else { // server side. The second part is the path to multi tun
|
||||
return url.PathEscape(streamNames[1])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue