mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-13 02:23:03 +00:00
Add prefix match
This commit is contained in:
parent
4bec9ab845
commit
600ee0ed1a
@ -3,7 +3,6 @@ package inbound
|
|||||||
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
|
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
gotls "crypto/tls"
|
gotls "crypto/tls"
|
||||||
@ -313,10 +312,11 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||||||
h2path := extractPathFromH2Request(connection)
|
h2path := extractPathFromH2Request(connection)
|
||||||
if h2path != "" {
|
if h2path != "" {
|
||||||
path = h2path
|
path = h2path
|
||||||
|
errors.LogInfo(ctx, "realPath = "+path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fb := pfb[path]
|
fb := prefixMatch(pfb, path)
|
||||||
if fb == nil {
|
if fb == nil {
|
||||||
return errors.New(`failed to find the default "path" config`).AtWarning()
|
return errors.New(`failed to find the default "path" config`).AtWarning()
|
||||||
}
|
}
|
||||||
@ -595,8 +595,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||||||
|
|
||||||
// Get path form http2
|
// Get path form http2
|
||||||
func extractPathFromH2Request(conn stat.Connection) string {
|
func extractPathFromH2Request(conn stat.Connection) string {
|
||||||
reader := bufio.NewReader(conn)
|
framer := http2.NewFramer(io.Discard, conn)
|
||||||
framer := http2.NewFramer(conn, reader)
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
frame, err := framer.ReadFrame()
|
frame, err := framer.ReadFrame()
|
||||||
@ -626,3 +625,21 @@ func extractPathFromH2Request(conn stat.Connection) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func prefixMatch(pfb map[string]*Fallback, path string) *Fallback {
|
||||||
|
for {
|
||||||
|
if val, exists := pfb[path]; exists {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
if path == "/" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
path = strings.TrimSuffix(path, "/")
|
||||||
|
if idx := strings.LastIndex(path, "/"); idx != -1 {
|
||||||
|
path = path[:idx]
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user