File tree 2 files changed +22
-4
lines changed
test/ring/middleware/test 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 2
2
" Middleware that returns a 304 Not Modified response for responses with
3
3
Last-Modified headers."
4
4
(:require [ring.util.time :refer [parse-date]]
5
- [ring.util.response :refer [get-header header]]
5
+ [ring.util.response :refer [get-header find-header header]]
6
6
[ring.util.io :refer [close!]]))
7
7
8
8
(defn- etag-match? [request response]
35
35
(or (not-modified-since? request response)
36
36
(etag-match? request response)))))
37
37
38
+ (defn- dissoc-header [response header]
39
+ (if-some [[k _] (find-header response header)]
40
+ (update response :headers dissoc k)
41
+ response))
42
+
38
43
(defn not-modified-response
39
44
" Returns 304 or original response based on response and request.
40
45
See: wrap-not-modified."
46
51
(do (close! (:body response))
47
52
(-> response
48
53
(assoc :status 304 )
49
- (header " Content-Length" 0 )
54
+ (dissoc- header " Content-Length" )
50
55
(assoc :body nil )))
51
56
response))
52
57
Original file line number Diff line number Diff line change 71
71
last-modified " Sun, 23 Sep 2012 11:00:00 GMT"
72
72
h-resp {:status 200 :headers {" Last-Modified" last-modified} :body " " }
73
73
resp (not-modified-response h-resp (req last-modified))]
74
+ (is (= 304 (:status resp)))
74
75
(is (nil? (:body resp)))
75
- (is (= (get-in resp [:headers " Content-Length" ]) " 0 " ))))
76
+ (is (nil? (get-in resp [:headers " Content-Length" ])))))
76
77
77
78
(testing " no modification info"
78
79
(let [response {:status 200 :headers {} :body " " }]
111
112
200 304
112
113
302 302
113
114
404 404
114
- 500 500 ))))
115
+ 500 500 )))
116
+
117
+ (testing " content-type header is removed"
118
+ (let [req #(hash-map :request-method :get :headers {" if-modified-since" %})
119
+ last-modified " Sun, 23 Sep 2012 11:00:00 GMT"
120
+ h-resp {:status 200
121
+ :headers {" Last-Modified" last-modified
122
+ " Content-Length" " 11" }
123
+ :body " hello world" }
124
+ resp (not-modified-response h-resp (req last-modified))]
125
+ (is (= 304 (:status resp)))
126
+ (is (nil? (:body resp)))
127
+ (is (nil? (get-in resp [:headers " Content-Length" ]))))))
You can’t perform that action at this time.
0 commit comments