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 33
33
" Adds a Content-Length header to the response. See: wrap-content-length."
34
34
{:added " 1.15" }
35
35
[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))))
41
42
42
43
(defn wrap-content-length
43
44
" Middleware that adds a Content-Length header to the response, if the
Original file line number Diff line number Diff line change 28
28
:headers {}
29
29
:body (java.io.File. " test/ring/assets/plain.txt" )})
30
30
(get-in [:headers " Content-Length" ])))))
31
- (testing " nil"
31
+ (testing " nil body "
32
32
(is (= " 0" (-> (content-length-response
33
33
{:status 200 , :headers {}, :body nil })
34
34
(get-in [:headers " Content-Length" ])))))
35
+ (testing " nil response"
36
+ (is (nil? (content-length-response nil ))))
35
37
(testing " other data"
36
38
(is (nil? (-> (content-length-response
37
39
{:status 200
You can’t perform that action at this time.
0 commit comments