diff --git a/src/compojure/core.clj b/src/compojure/core.clj index df35656c..c9766fa5 100644 --- a/src/compojure/core.clj +++ b/src/compojure/core.clj @@ -106,11 +106,13 @@ "Returns a function that will only call the handler if the method and path match the request." [method path handler] - (if-method method - (if-route path - (wrap-route-middleware - (fn [request] - (response/render (handler request) request)))))) + (let [route-info [(or method :any) (str path)]] + (if-method method + (if-route path + (wrap-route-middleware + (fn [request] + (let [request (assoc request :compojure/route route-info)] + (response/render (handler request) request)))))))) (defn compile-route "Compile a route in the form (method path bindings & body) into a function. diff --git a/test/compojure/core_test.clj b/test/compojure/core_test.clj index dc4b62f0..c5c42598 100644 --- a/test/compojure/core_test.clj +++ b/test/compojure/core_test.clj @@ -37,7 +37,7 @@ (assoc :params {:y "bar"}))] ((GET "/:x" [x :as r] (is (= x "foo")) - (is (= (dissoc r :params :route-params) + (is (= (dissoc r :params :route-params :compojure/route) (dissoc req :params))) nil) req))) @@ -249,3 +249,16 @@ (dotimes [_ 10] (handler (mock/request :get "/foo"))) (is (= @counter 1))))) + +(deftest route-information-test + (let [route (GET "/foo/:id" req req) + request (route (mock/request :get "/foo/1"))] + (testing "request has matched route information" + (is (= (request :compojure/route) + [:get "/foo/:id"])))) + + (let [route (ANY "/foo/:id" req req) + request (route (mock/request :post "/foo/1" {}))] + (testing "ANY request has matched route information" + (is (= (request :compojure/route) + [:any "/foo/:id"])))))