diff --git a/lib/flagsmith/sdk/api_client.rb b/lib/flagsmith/sdk/api_client.rb index fc16eb3..6a0a487 100644 --- a/lib/flagsmith/sdk/api_client.rb +++ b/lib/flagsmith/sdk/api_client.rb @@ -32,7 +32,7 @@ def build_headers(faraday, config) faraday.headers['Content-Type'] = 'application/json' faraday.headers['X-Environment-Key'] = config.environment_key faraday.headers['User-Agent'] = Flagsmith::SDK::Utils.user_agent - faraday.headers.merge(config.custom_headers) + faraday.headers.merge!(config.custom_headers) end def configure_logger(faraday, config) diff --git a/spec/sdk/api_client_spec.rb b/spec/sdk/api_client_spec.rb index 9da806b..9c92038 100644 --- a/spec/sdk/api_client_spec.rb +++ b/spec/sdk/api_client_spec.rb @@ -18,5 +18,18 @@ expected_user_agent = "flagsmith-ruby-sdk/#{Flagsmith::VERSION}" expect(connection.headers['User-Agent']).to eq(expected_user_agent) end + + it 'applies custom_headers alongside the default headers' do + custom_config = Flagsmith::Config.new( + environment_key: 'test-key', + api_url: 'https://edge.api.flagsmith.com/api/v1/', + custom_headers: { 'Authorization' => 'Bearer proxy-token', 'X-Proxy-Token' => 'abc' } + ) + connection = described_class.new(custom_config).instance_variable_get(:@conn) + + expect(connection.headers['Authorization']).to eq('Bearer proxy-token') + expect(connection.headers['X-Proxy-Token']).to eq('abc') + expect(connection.headers['X-Environment-Key']).to eq('test-key') + end end end