0

I'm working on a SCIM api using https://github.com/elimity-com/scim, which gives me an http.Handler that I have mounted using app.Mount("/api/v1/scim", scimHandler). Requests route to the scim handler, but have a trailing / appended to them which confuses the handler. For instance, if I request /api/v1/scim/Users (a list request), the handler sees /api/v1/scim/Users/ (a get-by-id request with no id). Similarly, if I request /api/v1/scim/Users/${id}, the handler sees /api/v1/scim/Users/${id}/ and fails to parse to the id properly.

I see similar appending of slash to other paths that aren't using Mount, but Buffalo seems to handle routing those ok. My /elb_health_check route gets to the handler as /elb_health_check/, but it does still get routed correctly and the health check doesn't care because it doesn't inspect the path.

Is there an option disable this behavior? Is it a bug I should report as an issue?

1 Answer 1

0

I'm not really happy with this workaround, but for now I've added a wrapper that strips the trailing slash.

app.Mount("/api/v1/scim", stripTrailingSlash(scimHandler))

...

func stripTrailingSlash(h http.Handler) http.Handler {
  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    path := r.URL.Path
    path = strings.TrimSuffix(path, "/")

    url, err := url.Parse(path)
    if err != nil {
      // Fall back to serving unmodified URL
      h.ServeHTTP(w, r)
      return
    }

    r.URL = url
    h.ServeHTTP(w, r)
  })
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.