Skip to content

Commit

Permalink
Don't append a trailing slash to the request path if it doesn't actua…
Browse files Browse the repository at this point in the history
…lly help find something (#3271)
  • Loading branch information
jefferai authored Aug 31, 2017
1 parent 717560f commit 7230d4d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions vault/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,19 @@ func (r *Router) RouteExistenceCheck(req *logical.Request) (bool, bool, error) {
func (r *Router) routeCommon(req *logical.Request, existenceCheck bool) (*logical.Response, bool, bool, error) {
// Find the mount point
r.l.RLock()
mount, raw, ok := r.root.LongestPrefix(req.Path)
if !ok {
adjustedPath := req.Path
mount, raw, ok := r.root.LongestPrefix(adjustedPath)
if !ok && !strings.HasSuffix(adjustedPath, "/") {
// Re-check for a backend by appending a slash. This lets "foo" mean
// "foo/" at the root level which is almost always what we want.
req.Path += "/"
mount, raw, ok = r.root.LongestPrefix(req.Path)
adjustedPath += "/"
mount, raw, ok = r.root.LongestPrefix(adjustedPath)
}
r.l.RUnlock()
if !ok {
return logical.ErrorResponse(fmt.Sprintf("no handler for route '%s'", req.Path)), false, false, logical.ErrUnsupportedPath
}
req.Path = adjustedPath
defer metrics.MeasureSince([]string{"route", string(req.Operation),
strings.Replace(mount, "/", "-", -1)}, time.Now())
re := raw.(*routeEntry)
Expand Down

0 comments on commit 7230d4d

Please sign in to comment.