From: Brian Warner Date: Wed, 13 Aug 2008 02:04:10 +0000 (-0700) Subject: web: use get_size_of_best_version for HEAD requests, provide correct content-type X-Git-Url: https://git.rkrishnan.org/zeppelin?a=commitdiff_plain;h=4d6b504883e8fa5f53fc325bbb85a01cc92c4d36;p=tahoe-lafs%2Ftahoe-lafs.git web: use get_size_of_best_version for HEAD requests, provide correct content-type --- diff --git a/src/allmydata/web/filenode.py b/src/allmydata/web/filenode.py index 185ab1dd..7777132e 100644 --- a/src/allmydata/web/filenode.py +++ b/src/allmydata/web/filenode.py @@ -9,7 +9,6 @@ from nevow import url, rend from nevow.inevow import IRequest from allmydata.interfaces import IDownloadTarget, ExistingChildError -from allmydata.mutable.common import MODE_READ from allmydata.immutable.upload import FileHandle from allmydata.util import log @@ -184,18 +183,18 @@ class FileNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin): t = get_arg(req, "t", "").strip() if t: raise WebError("GET file: bad t=%s" % t) + # if we have a filename, use it to get the content-type + filename = get_arg(req, "filename", self.name) or "unknown" + gte = static.getTypeAndEncoding + ctype, encoding = gte(filename, + static.File.contentTypes, + static.File.contentEncodings, + defaultType="text/plain") + req.setHeader("content-type", ctype) + if encoding: + req.setHeader("content-encoding", encoding) if self.node.is_mutable(): - # update the servermap to get the size of this file without - # downloading the full contents. - d = self.node.get_servermap(MODE_READ) - def _got_servermap(smap): - ver = smap.best_recoverable_version() - if not ver: - raise WebError("Unable to recover this file", - http.NOT_FOUND) - length = smap.size_of_version(ver) - return length - d.addCallback(_got_servermap) + d = self.node.get_size_of_best_version() # otherwise, we can get the size from the URI else: d = defer.succeed(self.node.get_size())