Commit 325aceb0 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '280553-cache-raw-endpoint' into 'master'

Fix generation of ETag when sending Git blobs

See merge request gitlab-org/gitlab!47225
parents 143a310a cef83ef4
......@@ -44,7 +44,6 @@ module SendsBlob
Blob::CACHE_TIME
end
response.etag = blob.id
!stale
end
......
......@@ -12,7 +12,6 @@ class Projects::RawController < Projects::ApplicationController
before_action :authorize_download_code!
before_action :show_rate_limit, only: [:show], unless: :external_storage_request?
before_action :assign_ref_vars
before_action :no_cache_headers, only: [:show]
before_action :redirect_to_external_storage, only: :show, if: :static_objects_external_storage_enabled?
feature_category :source_code_management
......
---
title: Cache repository raw endpoint
merge_request: 47225
author:
type: changed
......@@ -33,11 +33,6 @@ RSpec.describe Projects::RawController do
it_behaves_like 'project cache control headers'
it_behaves_like 'content disposition headers'
it_behaves_like 'uncached response' do
before do
subject
end
end
end
context 'image header' do
......@@ -225,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)
......
......@@ -537,13 +537,16 @@ RSpec.describe API::Files do
expect(response).to have_gitlab_http_status(:ok)
end
it_behaves_like 'uncached response' do
before do
url = route('.gitignore') + "/raw"
expect(Gitlab::Workhorse).to receive(:send_git_blob)
it 'sets no-cache headers' do
url = route('.gitignore') + "/raw"
expect(Gitlab::Workhorse).to receive(:send_git_blob)
get api(url, current_user), params: params
end
get api(url, current_user), params: params
expect(response.headers["Cache-Control"]).to include("no-store")
expect(response.headers["Cache-Control"]).to include("no-cache")
expect(response.headers["Pragma"]).to eq("no-cache")
expect(response.headers["Expires"]).to eq("Fri, 01 Jan 1990 00:00:00 GMT")
end
context 'when mandatory params are not given' do
......
# frozen_string_literal: true
#
# Negates lib/gitlab/no_cache_headers.rb
#
RSpec.shared_examples 'cached response' do
it 'defines a cached header response' do
expect(response.headers["Cache-Control"]).not_to include("no-store", "no-cache")
expect(response.headers["Pragma"]).not_to eq("no-cache")
expect(response.headers["Expires"]).not_to eq("Fri, 01 Jan 1990 00:00:00 GMT")
end
end
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