Hi All,

>From previous posts it would appear that to modify the response headers
all I should have to do is to import cherrypy and to set the
cherrypy.response.headers dictionary.  But when I attempt to do that I
get the following:

cherrypy.response.headers['Cache-Control'] = 'max-age=120'
TypeError: object does not support item assignment

So... I found that cherrypy.response.headers is == to None.
So... I set cherrypy.response.headers = {} and I'm able to proceed.
But... when sniffing the traffic I don't see what I would hope to see
in the headers.  I.E. I'm not seeing my header settings.  To confirm
this, if I put the content_type='text/csv' in the @turbogears.expose()
method and access the /csv URL I'll get prompted by Firefox to choose
what to do with the file but if I try to set the
cherrypy.response.headers['Content-Type'] = 'text/csv' and access the
/csv URL I get my csv file's content to the browser without getting
prompted by Firefox about how to handle the csv file.

My question is with Cherrypy (v2.1) is there some bit of more
code/configuration that I have to apply before I'm able to effectively
modify the cherrypy.response.headers?

Here's my complete controllers.py code:

import cherrypy
import turbogears
from turbogears import controllers

class Root(controllers.Root):
    @turbogears.expose(html="csvtest.templates.hcview")
    def index(self):
        import time
        return dict(now=time.ctime())

    @turbogears.expose()
    def csv(self):
        print cherrypy.response.headers
        cherrypy.response.headers = {}
        cherrypy.response.headers['Content-Type'] = 'text/csv'
        cherrypy.response.headers['Cache-Control'] = 'max-age=120'
        fp = open('csvtest/static/sample.csv','r')
        str = fp.read()
        return str

What I hope to eventually accomplish is provide a service that will
serve up a csv file that can be cached on the client.  The csv file is
referenced by an applet embedded in the page returned by the index
method (via the csvtest.templates.hcview template).  I hope to
demonstrate that the csv file which may be large and doesn't change
often can be cached on the client.

Suggestions and ideas are welcome!

Thanks in advance!
Evan


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to