[Zope3-Users] Setting custom content type when publishing a resource

Andrew Groom andrew at reurbanise.co.nz
Mon Oct 16 19:53:48 EDT 2006


Hi All,

I want to do something that feels like it should be really simple: set a 
  specific content type when a particular resource is published (a 
Firefox extension, a binary .xpi file if it helps). Any ideas how I 
could do that ? I've tried playing round with variations of:

class XPIPublisherView (BrowserView):

     def __init__ (self, context, request):
         self.context = context
         self.request = request

         # Override the default publication so we can set the content 
type on the way out.
         pub = XPIPublication('')
         self.request.setPublication(pub)

class XPIPublication (DefaultPublication):

     def afterCall (self, request, ob):
         import pdb; pdb.set_trace()
         request.response.setHeader('Content-Type', 
'application/x-xpinstall')

     def endRequest (self, request, ob):
         import pdb; pdb.set_trace()
         request.response.setHeader('Content-Type', 
'application/x-xpinstall')

but neither the afterCall or endRequest hooks are getting called. I also 
tried creating a __call__ method in XPIPublisherView and explicitly 
creating a FileResource to return, but that started to seem like hard work.

I'm floundering here, so any help would be much appreciated.

Failing the above approach, is there an easy way to modify the 
content-type for all resources with a given extension ? That would be OK.

Cheers, Andrew.
-----------------------------------
Reurbanise - Urban Sustainability
ph: (03) 3528 055, mobile: 0274 992 569
http://www.reurbanise.co.nz


More information about the Zope3-users mailing list