diff --git a/elasticsearch-transport/lib/elasticsearch/transport/transport/http/manticore.rb b/elasticsearch-transport/lib/elasticsearch/transport/transport/http/manticore.rb index 43607a17cd..c29046ba92 100644 --- a/elasticsearch-transport/lib/elasticsearch/transport/transport/http/manticore.rb +++ b/elasticsearch-transport/lib/elasticsearch/transport/transport/http/manticore.rb @@ -93,6 +93,10 @@ def perform_request(method, path, params={}, body=nil) def __build_connections @request_options = {} + if options[:transport_options] && options[:transport_options][:headers] + @request_options[:headers] = options[:transport_options][:headers] + end + if options.key?(:headers) @request_options[:headers] = options[:headers] end diff --git a/elasticsearch-transport/test/unit/transport_manticore_test.rb b/elasticsearch-transport/test/unit/transport_manticore_test.rb index 802f93a0c6..e37b1e52d8 100644 --- a/elasticsearch-transport/test/unit/transport_manticore_test.rb +++ b/elasticsearch-transport/test/unit/transport_manticore_test.rb @@ -75,6 +75,19 @@ class Elasticsearch::Transport::Transport::HTTP::ManticoreTest < Test::Unit::Tes assert_equal response.status, 200 end + should "set headers from 'transport_options'" do + options = { + :transport_options => { + :headers => { "Content-Type" => "foo/bar"} + } + } + + transport = Manticore.new :hosts => [ { :host => 'localhost', :port => 8080 } ], :options => options + + assert_equal('foo/bar', transport.connections.first.connection.instance_variable_get(:@options)[:headers]['Content-Type']) + # TODO: Needs to check @request_options + end + should "handle HTTP methods" do @transport.connections.first.connection.expects(:delete).with('http://127.0.0.1:8080//', {}).returns(stub_everything) @transport.connections.first.connection.expects(:head).with('http://127.0.0.1:8080//', {}).returns(stub_everything)