Skip to content

Fix Content-Disposition header

Peter-Jan Brone requested to merge content-disposition-for-archives into master

MERGE REQUEST

MR Guidelines

Overview

This MR properly sets the 'Content-Disposition' header for content that is returned as an archive, and is thus not supposed to be inlined by the browser. This will properly give the download a filename, which was not the case before. It also sets the correct extension for 'zip', '.tar' and '.tar.gz' archives.

Current State

Currently, there are two things that can be improved.

  • the 'Content-Disposition' header is not set, this results in an unpredictable filename
  • the 'Content-Type' for the TarGz format is incorrect, resulting in an incorrect extension (because the filename was not specified)

The filename is not entirely unpredictable, it will be set to the skylink. Which is not the worst thing, but also not ideal. Also, visiting the url with or without a trailing slash, results in different behavior that depends on the browser.

The following 2 urls: https://siasky.dev/_BmRFbjQIyTINOCHi0pf6qkUZmZxn3cPvON5PG8J8CmcsA?format=zip https://siasky.dev/_BmRFbjQIyTINOCHi0pf6qkUZmZxn3cPvON5PG8J8CmcsA/?format=zip will also result in different behavior. On Chrome it will download the link with the trailing slash as download.zip. In Firefox it shows a popup asking to save a nameless file, but then goes and downloads it as [skylink].zip

If we download using the format=targz, the resulting file has a .gtar extension. I expected that to be .tar.gz. I think this comes from the fact that we set the Content-Type header to "application/x-gtar", which is technically probably not 100% correct. The browser does not have a Content-Disposition header, and thus does a best effort, and gives it a gtar extension based on the Content-Type header.

I found tar is not an officially supported type. (https://superuser.com/questions/901962/what-is-the-correct-mime-type-for-a-tar-gz-file#:~:text=2%20Answers&text=As%20of%20August%202012%2C%20the,officially%20only%20a%20compressed%20file.)

This MR changes the extension to .tar.gz and also sets the Content-Type header to application/x-gzip, as suggested in the article. This is theoretically a Compatability issue, but at the same time, it is a bug fix...

Example for Visual Changes

N/A

Checklist

Review and complete the checklist to ensure that the MR is complete before assigned to an approver.

  • All new methods or updated methods have clear docstrings
  • Testing added or updated for new methods
  • Any new packages are added to Makefile and .gitlab-ci.yml
  • API documentation updated for API updates
  • Module README.md updated for changes to workflow
  • Issue added to Sia-UI repo for new supporting features
  • Changelog File Created
Edited by Peter-Jan Brone

Merge request reports