5
5
# import asyncio
6
6
7
7
from .common import get_auth_instance
8
- from .download import FileDownloadProxy
8
+ from .download import FileDownloadProxy , ContainerArchiveDownloadProxy
9
9
10
10
11
11
async def handle_get_object (
@@ -23,9 +23,49 @@ async def handle_get_object(
23
23
)
24
24
25
25
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
+
26
31
await resp .prepare (request )
27
32
28
33
# Create a task for writing the output into the StreamResponse
29
34
await download .a_write_to_response (resp )
30
35
31
36
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