Skip to content

Commit

Permalink
Include 'Content-Type' header in transport_options
Browse files Browse the repository at this point in the history
Starting with Elasticsearch 5.3, rest requests without an explicit
Content-Type are deprecated and it'll log a warning for every request
that is sent without a Content-Type header.

I addressed this in a similar manner to how `elasticsearch-ruby` did,
see [1], [2].

[1]: elastic/elasticsearch-ruby#400
[2]: elastic/elasticsearch-ruby@76f8679
  • Loading branch information
mthssdrbrg committed Apr 13, 2017
1 parent 83f978f commit ce123ee
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fluent/plugin/out_elasticsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def client
resurrect_after: @resurrect_after,
retry_on_failure: 5,
transport_options: {
headers: { 'Content-Type' => 'application/json' },
request: { timeout: @request_timeout },
ssl: { verify: @ssl_verify, ca_file: @ca_file }
}
Expand Down
1 change: 1 addition & 0 deletions lib/fluent/plugin/out_elasticsearch_dynamic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def client(host)
resurrect_after: @resurrect_after,
retry_on_failure: 5,
transport_options: {
headers: { 'Content-Type' => 'application/json' },
request: { timeout: @request_timeout },
ssl: { verify: @ssl_verify, ca_file: @ca_file }
}
Expand Down
10 changes: 10 additions & 0 deletions test/plugin/test_out_elasticsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ def test_single_host_params_and_defaults
assert_equal nil, host1[:path]
end

def test_content_type_header
stub_request(:head, "http://localhost:9200/").
to_return(:status => 200, :body => "", :headers => {})
elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
with(headers: { "Content-Type" => "application/json" })
driver.emit(sample_record)
driver.run
assert_requested(elastic_request)
end

def test_writes_to_default_index
stub_elastic_ping
stub_elastic
Expand Down
10 changes: 10 additions & 0 deletions test/plugin/test_out_elasticsearch_dynamic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ def test_single_host_params_and_defaults
assert_equal nil, host1[:path]
end

def test_content_type_header
stub_request(:head, "http://localhost:9200/").
to_return(:status => 200, :body => "", :headers => {})
elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
with(headers: { "Content-Type" => "application/json" })
driver.emit(sample_record)
driver.run
assert_requested(elastic_request)
end

def test_writes_to_default_index
stub_elastic_ping
stub_elastic
Expand Down

0 comments on commit ce123ee

Please sign in to comment.