def file_2(self, *tokens):
"""Outputs the contents of the file, named by the SHA hash
name in the request path, directly to the client."""
method = cherrypy.request.method
if method == "HEAD":
try:
fhash = tokens[0]
except IndexError:
fhash = None
try:
fpath = self.repo.file(fhash,
pub=self._get_req_pub())
except srepo.RepositoryFileNotFoundError as e:
raise cherrypy.HTTPError(http_client.NOT_FOUND,
str(e))
except srepo.RepositoryError as e:
# Treat any remaining repository error as a 404,
# but log the error and include the real failure
# information.
cherrypy.log("Request failed: {0}".format(
str(e)))
raise cherrypy.HTTPError(http_client.NOT_FOUND,
str(e))
csize, chashes = misc.compute_compressed_attrs(fhash,
file_path=fpath)
response = cherrypy.response
for i, attr in enumerate(chashes):
response.headers["X-Ipkg-Attr-{0}".format(i)] = \
"{0}={1}".format(attr, chashes[attr])
# set expiration of response to one day
self.__set_response_expires("file", 86400, 86400)
return serve_file(fpath, "application/data")
return self.file_1(*tokens)
评论列表
文章目录