File tree Expand file tree Collapse file tree 4 files changed +27
-2
lines changed Expand file tree Collapse file tree 4 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,9 @@ The following configuration keys are supported:
107107 Any redirects to relative URLs will be turned into redirects to
108108 absolute URLs, to better conform to the HTTP spec.
109109
110+ - ` :conent-length ` -
111+ Adds the standard Ring [ content-length] [ 17 ] middleware.
112+
110113 - ` :content-types ` -
111114 Adds the standard Ring [ content-type] [ 3 ] middleware.
112115
@@ -194,6 +197,7 @@ The following configuration keys are supported:
194197[ 14 ] : https://ring-clojure.github.io/ring/ring.middleware.file.html
195198[ 15 ] : https://ring-clojure.github.io/ring/ring.middleware.resource.html
196199[ 16 ] : https://ring-clojure.github.io/ring-websocket-middleware/ring.websocket.keepalive.html
200+ [ 17 ] : https://ring-clojure.github.io/ring/ring.middleware.content-length.html
197201
198202## License
199203
Original file line number Diff line number Diff line change 44 :license {:name " The MIT License"
55 :url " http://opensource.org/licenses/MIT" }
66 :dependencies [[org.clojure/clojure " 1.9.0" ]
7- [ring/ring-core " 1.15.0 " ]
7+ [ring/ring-core " 1.15.1 " ]
88 [ring/ring-ssl " 0.4.0" ]
99 [ring/ring-headers " 0.4.0" ]
1010 [ring/ring-anti-forgery " 1.4.0" ]
Original file line number Diff line number Diff line change 1313 [ring.middleware.resource :refer [wrap-resource]]
1414 [ring.middleware.file :refer [wrap-file]]
1515 [ring.middleware.not-modified :refer [wrap-not-modified]]
16+ [ring.middleware.content-length :refer [wrap-content-length]]
1617 [ring.middleware.content-type :refer [wrap-content-type]]
1718 [ring.middleware.default-charset :refer [wrap-default-charset]]
1819 [ring.middleware.absolute-redirects :refer [wrap-absolute-redirects]]
2829 :keywordize true }
2930 :responses {:not-modified-responses true
3031 :absolute-redirects false
32+ :content-length true
3133 :content-types true
3234 :default-charset " utf-8" }})
3335
5456 :static {:resources " public" }
5557 :responses {:not-modified-responses true
5658 :absolute-redirects false
59+ :content-length true
5760 :content-types true
5861 :default-charset " utf-8" }
5962 :websocket {:keepalive true }})
120123 (wrap wrap-content-type (get-in config [:responses :content-types ] false ))
121124 (wrap wrap-default-charset (get-in config [:responses :default-charset ] false ))
122125 (wrap wrap-not-modified (get-in config [:responses :not-modified-responses ] false ))
126+ (wrap wrap-content-length (get-in config [:responses :content-length ] false ))
123127 (wrap wrap-x-headers (:security config))
124128 (wrap wrap-hsts (get-in config [:security :hsts ] false ))
125129 (wrap wrap-ssl-redirect (get-in config [:security :ssl-redirect ] false ))
Original file line number Diff line number Diff line change 268268 (Thread/sleep 41 )
269269 (wsp/on-close listener socket 1000 " " )
270270 (Thread/sleep 20 )
271- (is (= 4 @ping-count)))))
271+ (is (= 4 @ping-count))))
272+
273+ (testing " content-length"
274+ (let [handler (-> (constantly
275+ (-> (response " foobar" )
276+ (content-type " text/plain; charset=UTF-8" )))
277+ (wrap-defaults api-defaults))
278+ resp (handler (request :get " /" ))]
279+ (is (= resp {:status 200
280+ :headers {" Content-Type" " text/plain; charset=UTF-8"
281+ " Content-Length" " 6" }
282+ :body " foobar" })))
283+ (let [handler (-> (constantly
284+ (-> (response " foobar" )
285+ (content-type " text/plain; charset=UTF-8" )))
286+ (wrap-defaults site-defaults))
287+ resp (handler (request :get " /" ))]
288+ (is (= " 6" (get-in resp [:headers " Content-Length" ]))))))
You can’t perform that action at this time.
0 commit comments