mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-28 18:05:24 +01:00
32 lines
676 B
Go
32 lines
676 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
func createTargetURL(ui *UserInfo, uOrig *url.URL) (string, error) {
|
|
u, err := url.Parse(uOrig.String())
|
|
if err != nil {
|
|
return "", fmt.Errorf("cannot make a copy of %q: %w", u, err)
|
|
}
|
|
// Prevent from attacks with using `..` in r.URL.Path
|
|
u.Path = path.Clean(u.Path)
|
|
if !strings.HasPrefix(u.Path, "/") {
|
|
u.Path = "/" + u.Path
|
|
}
|
|
for _, e := range ui.URLMap {
|
|
for _, path := range e.SrcPaths {
|
|
if u.Path == path {
|
|
return e.URLPrefix + u.RequestURI(), nil
|
|
}
|
|
}
|
|
}
|
|
if len(ui.URLPrefix) > 0 {
|
|
return ui.URLPrefix + u.RequestURI(), nil
|
|
}
|
|
return "", fmt.Errorf("missing route for %q", u)
|
|
}
|