Skip to content

Commit d34af9f

Browse files
committed
Merge pull request #4 from zyegfryed/master
Add absolute redirect support for resource creation
2 parents 564b5c9 + 4644158 commit d34af9f

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/ring/middleware/absolute_redirects.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(:import [java.net URL MalformedURLException]))
77

88
(defn- redirect? [response]
9-
(#{301 302 303 307} (:status response)))
9+
(#{201 301 302 303 307} (:status response)))
1010

1111
(defn- get-header-key [response ^String header-name]
1212
(->> response :headers keys

test/ring/middleware/absolute_redirects_test.clj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(:use clojure.test
33
ring.middleware.absolute-redirects
44
[ring.mock.request :only [request]]
5-
[ring.util.response :only [redirect response content-type]]))
5+
[ring.util.response :only [redirect response content-type created]]))
66

77
(deftest test-wrap-absolute-redirects
88
(testing "relative redirects"
@@ -37,4 +37,9 @@
3737
resp (handler (request :get "/"))]
3838
(is (= (:status resp) 302))
3939
(is (= (:headers resp) {"Location" "http://localhost/foo"
40-
"Content-Type" "text/plain"})))))
40+
"Content-Type" "text/plain"}))))
41+
(testing "resource creation"
42+
(let [handler (wrap-absolute-redirects (constantly (created "/bar/1")))
43+
resp (handler (request :post "/bar"))]
44+
(is (= (:status resp) 201))
45+
(is (= (:headers resp) {"Location" "http://localhost/bar/1"})))))

0 commit comments

Comments
 (0)