Commit 3695d162 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Set a 'Host' header on unix sockets

Workaround for a bug in the HTTPUNIX client.
parent a3712cc1
......@@ -159,6 +159,12 @@ class GitlabNet
request.set_form_data(params.merge(secret_token: secret_token))
if uri.is_a?(URI::HTTPUNIX)
# The HTTPUNIX HTTP client does not set a correct Host header. This can
# lead to 400 Bad Request responses.
request['Host'] = 'localhost'
end
request
end
......
......@@ -248,6 +248,7 @@ describe GitlabNet, vcr: true do
end
describe :http_request_for do
context 'with stub' do
let(:get) do
double(Net::HTTP::Get).tap do |get|
Net::HTTP::Get.stub(:new) { get }
......@@ -268,6 +269,18 @@ describe GitlabNet, vcr: true do
it { should_not be_nil }
end
context 'Unix socket' do
it 'sets the Host header to "localhost"' do
gitlab_net = described_class.new
gitlab_net.should_receive(:secret_token).and_return('a123')
request = gitlab_net.send(:http_request_for, :get, URI('http+unix://%2Ffoo'))
expect(request['Host']).to eq('localhost')
end
end
end
describe :cert_store do
let(:store) do
double(OpenSSL::X509::Store).tap do |store|
......
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