File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed
test/ring/middleware/test Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change 3333 " Adds a Content-Length header to the response. See: wrap-content-length."
3434 {:added " 1.15" }
3535 [response]
36- (if (resp/get-header response " content-length" )
37- response
38- (if-let [size (body-size-in-bytes (:body response) response)]
39- (-> response (resp/header " Content-Length" (str size)))
40- response)))
36+ (when response
37+ (if (resp/get-header response " content-length" )
38+ response
39+ (if-let [size (body-size-in-bytes (:body response) response)]
40+ (-> response (resp/header " Content-Length" (str size)))
41+ response))))
4142
4243(defn wrap-content-length
4344 " Middleware that adds a Content-Length header to the response, if the
Original file line number Diff line number Diff line change 2828 :headers {}
2929 :body (java.io.File. " test/ring/assets/plain.txt" )})
3030 (get-in [:headers " Content-Length" ])))))
31- (testing " nil"
31+ (testing " nil body "
3232 (is (= " 0" (-> (content-length-response
3333 {:status 200 , :headers {}, :body nil })
3434 (get-in [:headers " Content-Length" ])))))
35+ (testing " nil response"
36+ (is (nil? (content-length-response nil ))))
3537 (testing " other data"
3638 (is (nil? (-> (content-length-response
3739 {:status 200
You can’t perform that action at this time.
0 commit comments