Hi Pietro, Thanks for your reply.
I think that your answer is a bit over my head. I'll try to explain your answer in my own words, and please correct me if I am wrong: - There is no built in way to add HTTP headers to the built in feature of servicing static pages of the /static folder - The solution is to write my one code to serve static objects, and in that code I can do whatever I choose to do. - The example you wrote is an example of how to correctly and manually serve static objects, not using the automatic /static folder way. Thanks, Dan. On Sunday, November 4, 2012 5:38:38 PM UTC+2, Pietro Bertera wrote: > > Hi, > > 2012/11/4 Dan Shechter <[email protected] <javascript:>>: > > Is there a way to manually add HTTP headers to /static pages? I want to > > control the cache for HTTPS static objects. > > Here you can see a dummy example that add Content-type header to static > files: > > import web > import mimetypes > > def mime_type(filename): > return mimetypes.guess_type(filename)[0] or 'application/octet-stream' > > class Public: > def GET(self): > try: > file_name = web.ctx.path.split('/')[-1] > web.header('Content-type', mime_type(file_name)) > return open('./' + web.ctx.path, 'rb').read() > except IOError: > raise web.notfound() > > myApp = web.application(mapping=(), fvars=globals()) > myApp.add_mapping("/.+", "Public") > > myApp.run() > > > -- > Bertera Pietro > http://www.bertera.it > -- You received this message because you are subscribed to the Google Groups "web.py" group. To view this discussion on the web visit https://groups.google.com/d/msg/webpy/-/xtu8zAtIjw8J. 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/webpy?hl=en.
