rest_api.py: set Content-Disposition header in `get_blob_handler()`, add `raw` mode
Before raising this MR, consider whether the following are required, and complete if so:
-
Unit tests [ ] Metrics[ ] Documentation update(s)
If not required, please explain in brief why not.
Description
This makes get_blob_handler() in rest_api.py set the Content-Disposition header so that when downloading a blob with a web browser the filename uniquely identifies it.
It also adds a check for a URL argument named raw. When equal to 1, the blob will be returned as plaintext.
Changes proposed in this merge request:
-
get_blob_handler(): add check forrawURL argument.- If present and equal to
"1", specifyContent-Type: 'text/plain; charset=utf-8' - Otherwise, set
Content-DispositiontoAttachment;filename={hash}_{size_bytes}, the convention used for tarballs (!648 (merged)).
- If present and equal to
- Update/add unit tests
Validation
Attempt to download a blob using a browser pointing it to a URL such as http://localhost:8080/api/v1/blobs/8b7ff6b52aa6f0461e94cc06a17e164b17cda39a899cae1ba03449a3551dc6f4/23.
In this case the filename populated by the browser should be 8b7ff6b52aa6f0461e94cc06a17e164b17cda39a899cae1ba03449a3551dc6f4_23.
Loading http://localhost:8080/api/v1/blobs/8b7ff6b52aa6f0461e94cc06a17e164b17cda39a899cae1ba03449a3551dc6f4/23?raw=1 should display the blob directly in the browser without formatting.