Skip to content

Commit

Permalink
Merge pull request #250 from mthssdrbrg/content-type-header
Browse files Browse the repository at this point in the history
Include 'Content-Type' header in `transport_options`
  • Loading branch information
gihad authored Apr 29, 2017
2 parents 83f978f + ce123ee commit a3749f7
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 a3749f7

Please sign in to comment.