Permalink
Browse files

content-type middleware handles nil responses gracefully

  • Loading branch information...
1 parent 2f2179d commit 929b165f60061505cd0a10fa06aca6799242e5ec @weavejester weavejester committed Mar 5, 2011
View
2 ring-core/src/ring/middleware/content_type.clj
@@ -15,7 +15,7 @@
ring.util.mime-types/default-mime-types"
[handler & [opts]]
(fn [req]
- (let [resp (handler req)]
+ (if-let [resp (handler req)]
(if (get-in resp [:headers "Content-Type"])
resp
(let [mime-type (ext-mime-type (:uri req) (:mime-types opts))]
View
6 ring-core/test/ring/middleware/content_type_test.clj
@@ -23,4 +23,8 @@
(is (= (handler {:uri "/foo/bar.xxxaaa"})
{:headers {"Content-Type" "application/octet-stream"}}))
(is (= (handler {:uri "/foo/bar"})
- {:headers {"Content-Type" "application/octet-stream"}})))))
+ {:headers {"Content-Type" "application/octet-stream"}}))))
+
+ (testing "nil response"
+ (let [handler (wrap-content-type (constantly nil))]
+ (is (nil? (handler {:uri "/foo/bar.txt"}))))))

0 comments on commit 929b165

Please sign in to comment.