Except, and I may be missing something here, you would then have the
opposite problem. Routes couldn't overwrite middleware.
I asked James about this before:
On Sun, May 24, 2009 at 5:31 AM, James Reeves<> wrote:
> 2009/5/21 Luke Renn <>:
>> 1. If I implement with-header the way you describe in your post, then
>> it'll always set the header even if it's already set, so:
>>
>> ; From your post
>> (defn with-header
>> "Sets the specified header and value on the response."
>> [handler header value]
>> (fn [request]
>> (let [response (handler request)]
>> (assoc-in response [:headers header] value))))
>>
>> (defroutes example-app
>> (GET "/" [{:headers {"From" "Route"}} (get-example)]))
>>
>> (decorate example-app
>> (with-header "From" "Middleware"))
>>
>> ...will result in Middleware. I would think if the route sets
>> something then the middleware shouldn't overwrite it.
>>
>> How about with-headers that does a merge?
>
> This seems a sensible idea.
with-headers should probably just take an overwrite parameter.
The issue I was describing with text/html is a special case. The code
to default was written before there was a with-headers. Since neither
with-headers nor the defaulting overwrite headers, the first one
wins. In the case of text/html, that would be the defaulting. The
route still gets priority so you can (even now) override it. Once
with-headers was added we should have removed the defaulting as it
breaks with-headers for text/html. It should be handled with
something like the with-mimetypes I gisted above anyway.
Luke