Skip to content

Commit

Permalink
Merge pull request #492 from alphagov/update-preserve-segments
Browse files Browse the repository at this point in the history
Change shouldPreserveSegements arguments to accept strings
  • Loading branch information
theseanything authored Nov 4, 2024
2 parents ea5fc42 + 2bf35aa commit 8b470b9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func loadRoutes(c *mgo.Collection, mux *triemux.Mux, backends map[string]http.Ha
logDebug(fmt.Sprintf("router: registered %s (prefix: %v) for %s",
incomingURL.Path, prefix, route.BackendID))
case "redirect":
handler := handlers.NewRedirectHandler(incomingURL.Path, route.RedirectTo, shouldPreserveSegments(route))
handler := handlers.NewRedirectHandler(incomingURL.Path, route.RedirectTo, shouldPreserveSegments(route.RouteType, route.SegmentsMode))
mux.Handle(incomingURL.Path, prefix, handler)
logDebug(fmt.Sprintf("router: registered %s (prefix: %v) -> %s",
incomingURL.Path, prefix, route.RedirectTo))
Expand All @@ -347,12 +347,12 @@ func loadRoutes(c *mgo.Collection, mux *triemux.Mux, backends map[string]http.Ha
}
}

func shouldPreserveSegments(route *Route) bool {
switch route.RouteType {
func shouldPreserveSegments(routeType, segmentsMode string) bool {
switch routeType {
case RouteTypeExact:
return route.SegmentsMode == SegmentsModePreserve
return segmentsMode == SegmentsModePreserve
case RouteTypePrefix:
return route.SegmentsMode != SegmentsModeIgnore
return segmentsMode != SegmentsModeIgnore
default:
return false
}
Expand Down

0 comments on commit 8b470b9

Please sign in to comment.