Permalink
Browse files

Add content-disposition header.

This makes sure the file is downloaded, and saved under the correct local
name.
  • Loading branch information...
1 parent 69d5d8c commit bcc7aed49e522daff4a6f0eb90ab1c598422477c @geertj geertj committed Dec 21, 2011
Showing with 2 additions and 0 deletions.
  1. +2 −0 server.py
View
@@ -45,8 +45,10 @@ def _serve_file(self, fin):
def serve_file(self, fname, size=None):
fin = file(fname)
+ basename = os.path.split(fname)[1].encode('ascii')
headers = []
headers.append(('Content-Type', 'application/octet-stream'))
+ headers.append(('Content-Disposition', 'attachment; filename=%s' % basename))
if size is None:
fin.seek(0, 2); size = fin.tell(); fin.seek(0)
headers.append(('Content-Length', str(size)))

0 comments on commit bcc7aed

Please sign in to comment.