Skip to content

Commit c115297

Browse files
committed
bug: fix redirectHandler fails for requests like region/
1 parent 9fdafef commit c115297

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

http.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,15 @@ func (r *Redirector) redirectHandler(w http.ResponseWriter, req *http.Request) {
5353

5454
// If the path has a prefix of region/NA, it will use specific regions instead
5555
// of the default geographical distance
56-
if strings.HasPrefix(req.URL.Path, "/region") {
56+
if strings.HasPrefix(req.URL.Path, "/region/") {
5757
parts := strings.Split(req.URL.Path, "/")
58+
if len(parts) < 3 || parts[2] == "" {
59+
http.Error(w, "Region not specified", http.StatusBadRequest)
60+
return
61+
}
5862

59-
// region = parts[2]
60-
if mirrors, ok := r.regionMap[parts[2]]; ok {
63+
region := parts[2]
64+
if mirrors, ok := r.regionMap[region]; ok {
6165
choices := make([]randutil.Choice, len(mirrors))
6266

6367
for i, item := range mirrors {

0 commit comments

Comments
 (0)