@@ 4,6 4,7 @@
import asyncio
import logging
+import os
from typing import Callable
from aiohttp import web
@@ 149,16 150,7 @@ class FormatFileView(BaseView):
yield "/~{user}/products/{product}/{variant}/{product_branch}/{version}/{format}"
async def head(self):
- fmt = _get_format(self.repo(), self.request.match_info, self.access_granted)
- if fmt.is_dirty():
- raise web.HTTPNotFound()
- url = fmt.url()
- files = list(fmt.get_digests().keys())
- if len(files) == 1:
- url += files[0]
- if url != self.request.path:
- raise web.HTTPFound(url)
- return web.Response()
+ return await self.get()
async def get(self):
"""
@@ 168,9 160,16 @@ class FormatFileView(BaseView):
redirect to /branches/$branch/$tag/$job/$format/
"""
fmt = _get_format(self.repo(), self.request.match_info, self.access_granted)
+ if fmt.is_dirty():
+ raise web.HTTPNotFound()
files = list(fmt.get_digests().keys())
if len(files) == 1 and files[0] != "index.html":
- return web.HTTPFound(fmt.url() + files[0])
+ return web.HTTPFound(
+ fmt.url() + files[0],
+ headers={
+ "Content-Disposition": f"attachment; filename={os.path.basename(files[0])}"
+ },
+ )
return web.HTTPFound(fmt.url())