Skip to content

Commit

Permalink
Merge pull request #697 from dekelpilli/master
Browse files Browse the repository at this point in the history
fix: fix bug where http ring handler would cause :path to be applied twice
  • Loading branch information
opqdonut authored Sep 25, 2024
2 parents 86871a6 + f1ec7bb commit e2c63d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/reitit-http/src/reitit/http.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
(interceptor/queue executor))
router-opts (-> (r/options router)
(assoc ::interceptor/queue (partial interceptor/queue executor))
(dissoc :data) ; data is already merged into routes
(dissoc :data :path) ; data and path already take effect in routes
(cond-> (seq interceptors)
(update-in [:data :interceptors] (partial into (vec interceptors)))))
router (reitit.http/router (r/routes router) router-opts) ;; will re-compile the interceptors
Expand Down
19 changes: 18 additions & 1 deletion test/clj/reitit/http_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,24 @@

(testing "all named routes can be matched"
(doseq [name (r/route-names router)]
(is (= name (-> (r/match-by-name router name) :data :name))))))))
(is (= name (-> (r/match-by-name router name) :data :name)))))))

(testing "path prefixed routes"
(let [router (http/router
[["/all" {:handler handler}]
["/get" {:get {:handler handler}}]
["/users" {:get handler}]]
{:path "/api"})
app (http/ring-handler router nil {:executor sieppari/executor})]

(testing "router can be extracted"
(is (= (r/routes router)
(r/routes (http/get-router app)))))

(testing "handler resolved original router routes"
(doseq [router-path (mapv first (r/routes router))]
(is (= 200
(:status (app {:uri router-path :request-method :get})))))))))

(def enforce-roles-interceptor
{:enter (fn [{{::keys [roles] :as request} :request :as ctx}]
Expand Down

0 comments on commit e2c63d6

Please sign in to comment.