mirror of
https://git.robbyzambito.me/http-nats-proxy
synced 2025-12-21 16:54:50 +00:00
Sanitize paths
Use _ instead of . in paths. This is useful for paths like /.well-known, where the previous subject transformation would be invalid, due to two consecutive dots.
This commit is contained in:
7
main.go
7
main.go
@@ -99,12 +99,13 @@ func main() {
|
|||||||
if h, _, err := net.SplitHostPort(host); err == nil {
|
if h, _, err := net.SplitHostPort(host); err == nil {
|
||||||
host = h
|
host = h
|
||||||
}
|
}
|
||||||
// Use "-" instead of "." in the domain to make it a single token.
|
// Use "_" instead of "." in the domain to make it a single token.
|
||||||
domainParts := strings.ReplaceAll(host, ".", "-")
|
domainParts := strings.ReplaceAll(host, ".", "_")
|
||||||
|
|
||||||
// Process path component
|
// Process path component
|
||||||
path := strings.TrimPrefix(r.URL.Path, "/")
|
path := strings.TrimPrefix(r.URL.Path, "/")
|
||||||
subjectPath := strings.ReplaceAll(path, "/", ".")
|
// Replace all "." with "_" and then all "/" with ".".
|
||||||
|
subjectPath := strings.ReplaceAll(strings.ReplaceAll(path, ".", "_"), "/", ".")
|
||||||
|
|
||||||
// Build final subject
|
// Build final subject
|
||||||
subjectBase := "http"
|
subjectBase := "http"
|
||||||
|
|||||||
Reference in New Issue
Block a user