ring

DrLjótsson 2023-11-12T21:48:24.480199Z

I’m trying to understand how the :context key for a ring request is handled by compojure. I can see that it’s read here https://github.com/weavejester/compojure/blob/1f921964801ef4ba45b7e694bc9c6a27394c1300/src/compojure/core.clj#L258 and passed on here https://github.com/weavejester/compojure/blob/1f921964801ef4ba45b7e694bc9c6a27394c1300/src/compojure/core.clj#L264, but I can’t really see where its value is used. The reason why I’m asking is that I have set the :context myself for another purpose, which completely broke my app. Now I’m trying to figure out where the breaking happens.

weavejester 2023-11-14T14:32:58.932619Z

The context macro in Compojure, and the set-context function in Ring, split the :uri of a request map into a :context and :path-info parts.

weavejester 2023-11-14T14:33:57.359339Z

So for example:

(compojure/context "/foo"
  (compojure/GET "/bar" []
    "This will match /foo/bar. The context is /foo, and the path-info is /bar"))

DrLjótsson 2023-11-14T14:36:33.122229Z

Thanks! I was able to figure out that setting :context myself broke metosin's ring-swagger library. But I managed to solve it. 🙂

DrLjótsson 2023-11-14T14:37:10.341489Z

Also, if I read the source right, the context let-binding is never used? https://github.com/weavejester/compojure/blob/1f921964801ef4ba45b7e694bc9c6a27394c1300/src/compojure/core.clj#L258

weavejester 2023-11-14T14:43:03.036729Z

Yeah, that looks like a line that can be removed.

👍 1