Fix bug setting http headers in Files API

parent dae5c266
---
title: Fix bug setting http headers in Files API
merge_request: 20938
author:
type: fixed
...@@ -3,7 +3,11 @@ module API ...@@ -3,7 +3,11 @@ module API
module HeadersHelpers module HeadersHelpers
def set_http_headers(header_data) def set_http_headers(header_data)
header_data.each do |key, value| header_data.each do |key, value|
header "X-Gitlab-#{key.to_s.split('_').collect(&:capitalize).join('-')}", value if value.is_a?(Enumerable)
raise ArgumentError.new("Header value should be a string")
end
header "X-Gitlab-#{key.to_s.split('_').collect(&:capitalize).join('-')}", value.to_s
end end
end end
end end
......
...@@ -13,6 +13,24 @@ describe API::Files do ...@@ -13,6 +13,24 @@ describe API::Files do
let(:author_email) { 'user@example.org' } let(:author_email) { 'user@example.org' }
let(:author_name) { 'John Doe' } let(:author_name) { 'John Doe' }
let(:helper) do
fake_class = Class.new do
include ::API::Helpers::HeadersHelpers
attr_reader :headers
def initialize
@headers = {}
end
def header(key, value)
@headers[key] = value
end
end
fake_class.new
end
before do before do
project.add_developer(user) project.add_developer(user)
end end
...@@ -21,6 +39,18 @@ describe API::Files do ...@@ -21,6 +39,18 @@ describe API::Files do
"/projects/#{project.id}/repository/files/#{file_path}" "/projects/#{project.id}/repository/files/#{file_path}"
end end
context 'http headers' do
it 'converts value into string' do
helper.set_http_headers(test: 1)
expect(helper.headers).to eq({ 'X-Gitlab-Test' => '1' })
end
it 'raises exception if value is an Enumerable' do
expect { helper.set_http_headers(test: [1]) }.to raise_error(ArgumentError)
end
end
describe "HEAD /projects/:id/repository/files/:file_path" do describe "HEAD /projects/:id/repository/files/:file_path" do
shared_examples_for 'repository files' do shared_examples_for 'repository files' do
it 'returns file attributes in headers' do it 'returns file attributes in headers' do
......
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