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

FB fbo2 at gmx.net
Tue Oct 17 06:21:50 EDT 2006


Hi,

On Tue, Oct 17, 2006 at 12:53:48PM +1300, Andrew Groom wrote:
> 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)

You should do this in the __call__() method. This is the default view of an
advanced IFile implementation of mine:

class AutoFileView(BrowserView):
   def __call__(self):
      self.request.response.setHeader('Content-Type',
                                            self.context.contentType)
      self.request.response.setHeader('Content-Length',
                                            self.context.getSize())
      return self.context.data

Regards,

Frank


More information about the Zope3-users mailing list