weavejester / compojure

A concise routing library for Ring/Clojure
Eclipse Public License 1.0
4.08k stars 259 forks source link

Question: match path case insensitive? #219

Closed svdo closed 6 months ago

svdo commented 6 months ago

Hi,

Thanks for Compojure, it's a nice library! We're using it for routing in a web server that partially serves content itself, and partially proxies it to another server. That other server is unfortunately (somewhat) case insensitive when it comes to paths. We want to give some of the URLs special treatment using extra middleware for example. Is there a way to specify routes in compojure that have case insensitive path?

For example:

(-> (context "/bla" []
      (GET "/specialPath" [] {:status 403})
      (ANY "/*" [] proxy-handler))
    (wrap-routes ...))

This returns 403 for "/bla/specialPath", but passes the request on when it is sent as "/bla/SpecialPath".

I was thinking of something like (GET #"(?i)/specialPath" [] {:status 403}) but regexes don't work in this context apparently, also not when using clout directly.

weavejester commented 6 months ago

There's no syntax for it in Compojure, but you can wrap some or all of the rounds in middleware that lowercases the request URI.

svdo commented 6 months ago

Yes that was indeed my alternate solution. Thanks!