[Twisted-web] Content-disposition and static.File

Maarten ter Huurne maarten at treewalker.org
Fri Aug 29 04:50:56 EDT 2008

On Friday 29 August 2008, tarjei wrote:

> def locateChild(self, ctx):
>    request = inevow.IRequest(ctx)
>    request.setHeader("content-disposition"
> ,"attachment;filename=foo.pdf")
>    return static.File(self.path_to_file)
> This works well (except I do not get to define the filename) if I do not
> add the content-disposition header, but when I do that twisted just
> explodes into an exception.

What is that exception exactly?

One thing to be careful with is that in HTTP headers only ASCII is allowed. 
If your file name is a unicode object (even if it only contains ASCII 
characters), 16-bit characters will be sent in the HTTP headers and the 
browser will not like that. But in my experience this does not cause 
exceptions (maybe it should, though).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part.
Url : http://twistedmatrix.com/pipermail/twisted-web/attachments/20080829/3d311937/attachment.pgp

More information about the Twisted-web mailing list