Skip to content

Commit 966260b

Browse files
committed
Add async arity to not-found route
1 parent 39346e4 commit 966260b

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/compojure/route.clj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@
5656
supplied response body. The response body may be anything accepted by the
5757
[[response/render]] function."
5858
[body]
59-
(fn [request]
60-
(-> (response/render body request)
61-
(status 404)
62-
(cond-> (= (:request-method request) :head) (assoc :body nil)))))
59+
(fn handler
60+
([request]
61+
(-> (response/render body request)
62+
(status 404)
63+
(cond-> (= (:request-method request) :head) (assoc :body nil))))
64+
([request respond raise]
65+
(respond (handler request)))))

test/compojure/route_test.clj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
(let [response ((route/not-found {:status 200 :body "bar"})
1313
(mock/request :get "/"))]
1414
(is (= (:status response) 404))
15-
(is (= (:body response) "bar")))))
15+
(is (= (:body response) "bar"))))
16+
(testing "async arity"
17+
(let [handler (route/not-found "baz")
18+
response (promise)
19+
exception (promise)]
20+
(handler (mock/request :get "/") response exception)
21+
(is (not (realized? exception)))
22+
(is (= (:status @response) 404))
23+
(is (= (:body @response) "baz")))))
1624

1725
(deftest resources-route
1826
(let [route (route/resources "/foo" {:root "test_files"})

0 commit comments

Comments
 (0)