Setting response headers when using withFormat

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting response headers when using withFormat

Sir Mix a Lot
Hi.

I'm currently trying to set response headers in a Grails Application serving an AJAX client. The responses are rendered by a controller in XML using the appropriate XML DSL.

withFormat {
                        xml {
                                render(contentType: 'text/xml') {
                                        filters {
                                                productcategories {
                                                        for ( prodCat in prodCats ) {

ETC....ETC

Now I was also hoping to set some additional performance statistics in the HTTP headers. I have been trying to do this using a Grails filter:

def filters = {
                all(controller: '*', action: '*') {
                        before = {
                               
                        }
                        after = {
                             def timing = getProcessingTime()
                             resp.setHeader(PROCESSING_TIME_ATTRIBUTE, timing.toString());
                        }

This doesn't work because the response has already been written by the DSL. The headers don't appear in the response.

I understand that you can't write to the response stream if it's already been written so it looks like this approach is doomed to failure unless someone has an additional ideas.

(FYI, the reason I'm writing these stats to the response is so I can collect some stats on network performance as some of the application clients have poor connections due to their geographical location)

If anyone has a work around or any additional ideas I would be most grateful. Thanks in advance.

Reply | Threaded
Open this post in threaded view
|

Re: Setting response headers when using withFormat

burtbeckwith
Please ask usage questions on the User list.

Burt