HiI would like to be able to add cache-control headers (and possibly other headers) that are specific for the given route (meaning that it can't be done in a wrapper).
(defn wrap-respoonse-header [h header value] (fn [req] (assoc-in (h req) [:headers header] value))) (defresource foo-resource :handle-ok "FOO!") (defroutes app (ANY "/FOO" [] (wrap-response-header foo-resource "X-TEST" "whatever"))) |
(defresource foo-resource | |
:handle-ok (fn [_] (ring-response "FOO" {:headers "X-Test" "whatever"}))) |
(defroutes app-test
(wrap-respoonse-header (ANY "/foo" [] (resource :available-media-types ["text/html"]
:handle-ok "<html>Hello, Internet.</html>"))
"Cache-Control" "max-age=60s"))
and then using ring.server.standalone to service the route.
Pragma: no-cache
Date: Wed, 26 Aug 2015 14:31:39 GMT
Last-Modified: Wed, 26 Aug 2015 14:31:38 GMT
Server: nginx/1.8.0
Vary: Accept
Content-Type: text/html;charset=UTF-8
Cache-Control: no-cache, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: keep-alive
Content-Length: 29
Expires: Wed, 26 Aug 2015 14:31:38 GMT
<html>Hello, Internet.</html>
Here is a simple example of what I am seeing:(defroutes app-test
(wrap-respoonse-header (ANY "/foo" [] (resource :available-media-types ["text/html"]
:handle-ok "<html>Hello, Internet.</html>"))
"Cache-Control" "max-age=60s"))
and then using ring.server.standalone to service the route.
Pragma: no-cache
Date: Wed, 26 Aug 2015 14:31:39 GMT
Last-Modified: Wed, 26 Aug 2015 14:31:38 GMT
Server: nginx/1.8.0
Vary: Accept
Content-Type: text/html;charset=UTF-8
Cache-Control: no-cache, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: keep-alive
Content-Length: 29
Expires: Wed, 26 Aug 2015 14:31:38 GMT
<html>Hello, Internet.</html>