~rjarry/dlrepo

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

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

Details
Message ID
<20240410085049.347830-1-julien.floret@6wind.com>
DKIM signature
pass
Download raw message
Patch: +10 -11
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] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<D0GBC9513U0C.1235Y6AQZ0KZ3@fra01>
In-Reply-To
<20240410085049.347830-1-julien.floret@6wind.com> (view parent)
DKIM signature
missing
Download raw message
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]: julien.floret@6wind.com

✓ #1191903 SUCCESS dlrepo/patches/.build.yml https://builds.sr.ht/~rjarry/job/1191903

Applied: [PATCH dlrepo] fmt: add content disposition header to redirection

Details
Message ID
<171303908470.151889.17721985965707529891@ringo>
In-Reply-To
<20240410085049.347830-1-julien.floret@6wind.com> (view parent)
DKIM signature
pass
Download raw message
Julien Floret <julien.floret@6wind.com> wrote:
> 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>
> ---

Acked-by: Robin Jarry <robin@jarry.cc>

Applied, thanks.

To git@git.sr.ht:~rjarry/dlrepo
   75d45a112ab8..7d50989d3d91  main -> main
Reply to thread Export thread (mbox)