mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
74decb4bdc
The JoinUrlFragments function adds a trailing slash if to the proxy url if the proxy path is an empty string. This fix removes that trailing slash. Fixes #3847
43 lines
620 B
Go
43 lines
620 B
Go
package util
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
type UrlQueryReader struct {
|
|
values url.Values
|
|
}
|
|
|
|
func NewUrlQueryReader(url *url.URL) *UrlQueryReader {
|
|
return &UrlQueryReader{
|
|
values: url.Query(),
|
|
}
|
|
}
|
|
|
|
func (r *UrlQueryReader) Get(name string, def string) string {
|
|
val := r.values[name]
|
|
if len(val) == 0 {
|
|
return def
|
|
}
|
|
|
|
return val[0]
|
|
}
|
|
|
|
func JoinUrlFragments(a, b string) string {
|
|
aslash := strings.HasSuffix(a, "/")
|
|
bslash := strings.HasPrefix(b, "/")
|
|
|
|
if len(b) == 0 {
|
|
return a
|
|
}
|
|
|
|
switch {
|
|
case aslash && bslash:
|
|
return a + b[1:]
|
|
case !aslash && !bslash:
|
|
return a + "/" + b
|
|
}
|
|
return a + b
|
|
}
|