Commit cef83ef4 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Generate correct ETags when sending Git blobs

Calling `#stale?` already generates and sets the response ETag so we
should not set it manually.

Setting it manually actually broke caching because Rails now has extra
validators that is combined with the `blob.id` that we provide.
https://github.com/rails/rails/blob/v6.0.3.3/actionpack/lib/action_controller/metal/conditional_get.rb#L277
parent 3ce94109
......@@ -44,7 +44,6 @@ module SendsBlob
Blob::CACHE_TIME
end
response.etag = blob.id
!stale
end
......
---
title: Cache repository raw endpoint
merge_request: 47225
author:
type: changed
......@@ -220,6 +220,23 @@ RSpec.describe Projects::RawController do
end
end
end
describe 'caching' do
def request_file
get(:show, params: { namespace_id: project.namespace, project_id: project, id: 'master/README.md' })
end
context 'when If-None-Match header is set' do
it 'returns a 304 status' do
request_file
request.headers['If-None-Match'] = response.headers['ETag']
request_file
expect(response).to have_gitlab_http_status(:not_modified)
end
end
end
end
def execute_raw_requests(requests:, project:, file_path:, **params)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment