Commit f1750140 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'fj-49802-bug-api-set-http-headers' into 'master'

Fix bug setting http headers in Files API

See merge request gitlab-org/gitlab-ce!20938
parents dae5c266 4b36f74b
---
title: Fix bug setting http headers in Files API
merge_request: 20938
author:
type: fixed
......@@ -3,7 +3,11 @@ module API
module HeadersHelpers
def set_http_headers(header_data)
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
......
......@@ -13,6 +13,24 @@ describe API::Files do
let(:author_email) { 'user@example.org' }
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
project.add_developer(user)
end
......@@ -21,6 +39,18 @@ describe API::Files do
"/projects/#{project.id}/repository/files/#{file_path}"
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
shared_examples_for 'repository files' 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