~rjarry/dlrepo

dlrepo: fmt: add content disposition header to redirection v1 APPLIED

Julien Floret: 1
 fmt: add content disposition header to redirection

 1 files changed, 10 insertions(+), 11 deletions(-)
#1191903 .build.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rjarry/dlrepo/patches/50873/mbox | git am -3
Learn more about email & git

[PATCH dlrepo] fmt: add content disposition header to redirection Export this patch

When issuing a GET or HEAD request on a format folder that contains a
single artifact file, the response is an HTTP redirection to that
file. In that case, add a "Content-Disposition" HTTP header to the
response, so that it can be used with e.g. "curl -JOL" to save the
downloaded file using the actual file name instead of that of the
format folder.

Signed-off-by: Julien Floret <julien.floret@6wind.com>
Acked-by: Thomas Faivre <thomas.faivre@6wind.com>
---
 dlrepo/views/fmt.py | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/dlrepo/views/fmt.py b/dlrepo/views/fmt.py
index 0c48289b2e6f..5a2cb1105d2f 100644
--- a/dlrepo/views/fmt.py
+++ b/dlrepo/views/fmt.py
@@ -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())


-- 
2.39.2
dlrepo/patches/.build.yml: SUCCESS in 43s

[fmt: add content disposition header to redirection][0] from [Julien Floret][1]

[0]: https://lists.sr.ht/~rjarry/dlrepo/patches/50873
[1]: mailto:julien.floret@6wind.com

✓ #1191903 SUCCESS dlrepo/patches/.build.yml https://builds.sr.ht/~rjarry/job/1191903
Julien Floret <julien.floret@6wind.com> wrote: