Artifacts API: ETag caching is broken, same ETag value returned always

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

GitLab documentation suggests using the ETag and If-None-Match headers to avoid unnecessary load on the server when checking for changes: https://docs.gitlab.com/ee/development/polling.html

A regression was introduced many months ago, this caching approach no longer works when using the single artifact download API: /projects/:id/jobs/artifacts/:ref_name/raw/*artifact_path?job=name

Steps to reproduce

I have created a repository that reproduces this issue on public the GitLab.com instance.

  1. Fork repository https://gitlab.com/intgr/ci-artifacts-test
  2. Edit file artifact.txt, commit and wait for the CI to pass
  3. Send a request at the artifact API while saving headers (change repo name intgr%2Fci-artifacts-test as needed)
    GET https://gitlab.com/api/v4/projects/intgr%2Fci-artifacts-test/jobs/artifacts/main/raw/output/artifact.txt?job=compile
    Observe that the returned ETag header is Etag: W/"12ae32cb1ec02d01eda3581b127c1fee"
  4. Edt artifact.txt, commit, wait CI again
  5. Send a request with If-None-Match header with the previous ETag
    GET https://gitlab.com/api/v4/projects/intgr%2Fci-artifacts-test/jobs/artifacts/main/raw/output/artifact.txt?job=compile
    If-None-Match: W/"12ae32cb1ec02d01eda3581b127c1fee"
    GitLab responds with 304 Not Modified response code, as if the artifact had NOT changed!
  6. If you retry the request from step # 3, note that the ETag header still has the same value. But the HTTP body content has actually changed!

Output of checks

This bug happens on GitLab.com

Edited by 🤖 GitLab Bot 🤖