Skip to content

Commit

Permalink
[CLIENT] Added proper handling of headers in client options to the Ma…
Browse files Browse the repository at this point in the history
…nticore adapter

The Manticore adapter doesn't handle the `transport_options` in the same way
as the Faraday and Curb adapters.

The addition of a default 'Content-Type' header in 76f8679
(#400) didn't work then, and this patch fixes it.

Related:

    * #400
    * logstash-plugins/logstash-input-elasticsearch#55
    * logstash-plugins/logstash-input-elasticsearch#56
  • Loading branch information
karmi committed Feb 7, 2017
1 parent 76f8679 commit 908ade4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions elasticsearch-transport/test/unit/transport_manticore_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 908ade4

Please sign in to comment.