55# import asyncio
66
77from .common import get_auth_instance
8- from .download import FileDownloadProxy
8+ from .download import FileDownloadProxy , ContainerArchiveDownloadProxy
99
1010
1111async def handle_get_object (
@@ -23,9 +23,49 @@ async def handle_get_object(
2323 )
2424
2525 resp = aiohttp .web .StreamResponse ()
26+
27+ # Create headers
28+ resp .headers ["Content-Type" ] = download .get_type ()
29+ resp .headers ["Content-Length" ] = str (download .get_size ())
30+
2631 await resp .prepare (request )
2732
2833 # Create a task for writing the output into the StreamResponse
2934 await download .a_write_to_response (resp )
3035
3136 return resp
37+
38+
39+ async def handle_get_container (
40+ request : aiohttp .web .Request
41+ ) -> aiohttp .web .StreamResponse :
42+ """Handle a request for getting container contents as an archive."""
43+ auth = get_auth_instance (request )
44+
45+ resp = aiohttp .web .StreamResponse ()
46+
47+ project = request .match_info ["project" ]
48+ container = request .match_info ["container" ]
49+
50+ # Create headers
51+ resp .headers ["Content-Type" ] = "binary/octet-stream"
52+ # Don't give content length, as the content length depends on
53+ # compressibility
54+ # Suggest {project_name}-{container}.tar as file name
55+ disp_header = f'attachment; filename="{ project } -{ container } .tar"'
56+ resp .headers ["Content-Disposition" ] = disp_header
57+
58+ await resp .prepare (request )
59+
60+ download = ContainerArchiveDownloadProxy (
61+ auth ,
62+ project ,
63+ container
64+ )
65+
66+ await download .a_begin_container_download ()
67+
68+ # Create a task for writing the tarball into the StreamResponse
69+ await download .a_write_to_response (resp )
70+
71+ return resp
0 commit comments