Strip leading slashes from requests to download map
This commit is contained in:
parent
a571832239
commit
2f43f2d934
8
http.go
8
http.go
|
@ -112,13 +112,7 @@ func redirectHandler(w http.ResponseWriter, r *http.Request) {
|
|||
redirectPath := path.Join(server.Path, r.URL.Path)
|
||||
|
||||
if dlMap != nil {
|
||||
p := r.URL.Path
|
||||
|
||||
if p[0] != '/' {
|
||||
p = "/" + p
|
||||
}
|
||||
|
||||
if newPath, exists := dlMap[p]; exists {
|
||||
if newPath, exists := dlMap[strings.TrimLeft(r.URL.Path, "/")]; exists {
|
||||
downloadsMapped.Inc()
|
||||
redirectPath = path.Join(server.Path, newPath)
|
||||
}
|
||||
|
|
3
map.go
3
map.go
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/csv"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func loadMap(file string) (map[string]string, error) {
|
||||
|
@ -32,7 +33,7 @@ func loadMap(file string) (map[string]string, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
m[row[0]] = row[1]
|
||||
m[strings.TrimLeft(row[0], "/")] = strings.TrimLeft(row[1], "/")
|
||||
}
|
||||
|
||||
return m, nil
|
||||
|
|
Loading…
Reference in New Issue