Oh, my apologies. You also need to pass the request map to the render
method.

    (-> (io/resource "public/html/confirm.html")
        (cr/render request)
        (resp/header "Cache-Control" "no-cache, no-store"))

You could also write it as:

    (-> (resp/resource-response "public/html/confirm.html)
        (resp/content-type "text/html; charset=utf-8")
        (resp/header "Cache-Control" "no-cache, no-store"))

Or write some middleware:

    (defn wrap-cache-control [handler cache-control]
      (fn [request]
        (some-> (handler request)
                (resp/header "Cache-Control" cache-control))))

- James


On 27 May 2015 at 13:01, Jonathon McKitrick <jmckitr...@gmail.com> wrote:

> Hmm.  I tried this:
>
> (-> (io/resource "public/html/confirm.html")
>              (cr/render)
>              (resp/header "Cache-Control" "no-cache, no-store"))
>
> and got this:
>
> Exception in thread "main" java.lang.IllegalArgumentException: No single
> method: render of interface: compojure.response.Renderable found for
> function: render of protocol: Renderable, compiling:(pts/server.clj:483:14)
>
> On Tuesday, May 26, 2015 at 8:43:21 AM UTC-4, James Reeves wrote:
>>
>> Compojure uses the compojure.response/render protocol method to turn
>> values like URLs into Ring responses. So you could write:
>>
>>     (-> (io/resource "public/html/confirm.html")
>>         (compojure.response/render)
>>         (response/header "X-Foo" "Bar"))
>>
>> Or you could use some middleware, if the header is standard across your
>> application. Or since you know that you're delivering a HTML file, you
>> could also write:
>>
>>     (-> (response/resource-response "public/html/confirm.html")
>>         (response/content-type "text/html; charset=utf-8")
>>         (response/header "X-Foo" "Bar"))
>>
>> That should result in the same thing, as the only thing Compojure does
>> that Ring doesn't is try to make an educated guess about the content type.
>>
>> - James
>>
>> On 26 May 2015 at 13:22, Jonathon McKitrick <jmcki...@gmail.com> wrote:
>>
>>> I have a GET route returning the result of this:
>>>
>>> (io/resource "public/html/confirm.html")
>>>
>>> but I need to add Cache-Control headers.  Since the `resource` function
>>> returns a java.net.URL object, how can I add headers?  The normal Ring way
>>> with ring.util.response/header only operates on a Ring response.
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@googlegroups.com
>>> Note that posts from new members are moderated - please be patient with
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> clojure+u...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+u...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to