Skip to content

Package details page: fix the download link

🔭 Context

The package registry UI has a page that details a package and its files. Example.

Each file can be clicked to be downloaded. This is handled by a rails controller.

Technically the #send_upload function needs to cover different situations. One of them is when object storage is enabled and the proxy download is enabled too.

In this configuration, the object storage signed url will be sent to workhorse and it will get the file from the url and return it back to the client. For a file download, there are a few headers that we need to set. Among other things, the Content-Disposition header which will control how to "present" file. This will be used by the browser to present the download file prompt. This prompt will read the filename of that header to use it as the name of the file to save locally.

(A) We can instruct the object storage provider to send this header and we do see with a specific query parameter.

(B) Parallel to the above, in Augment GCS signed URLs with GitLab metadata fo... (!147207 - merged), we added metrics for Google Cloud Storage. Those metrics are sent to the object storage provider as query parameters and are only enabled for Google Cloud Storage and gitlab.com.

The order that the logic flows is (A) and then (B). In Package registry: downloading files from UI doe... (#461968 - closed), we had reports that the download prompt was not use the proper filename anymore. It turns out that (B) was overwriting query parameters. So any parameter set in (A) would get lost.

This MR fixes this typebug by merging query parameters in (B) so that values from (A) and (B) are sent back (unless (B) is actually doing a real overwrite (same parameter name) but that's not the case).

Please note that (A) is still behind a feature flag and this will only happen with it is enabled.

🤔 What does this MR do and why?

  • In the GCS metrics signed url concern, update the code to merge the :query values instead of overwriting.
  • Add a related spec in the package files controller download action.

🏎 MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

🌈 Screenshots or screen recordings

On master:

Screenshot_2024-05-16_at_12.06.01

With this MR:

Screenshot_2024-05-16_at_13.35.41

How to set up and validate locally

  1. Enable the feature flag: Feature.enable(:augment_gcs_signed_url_with_metadata).
  2. Enable object storage.
  3. In app/uploaders/packages/gcs_signed_url_metadata.rb, comment out the guard on Google provider and .com?.
  4. Upload a package (any format).
  5. Browse the Package Registry, open the package details page.

1️⃣ On master

  1. Download one of the uploaded files. It will open the download browser prompt with download for the suggested filename. 💥

2️⃣ With this MR

  1. Download one of the uploaded files. It will open the download browser prompt with correct filename for the suggested filename.

Merge request reports