Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
z-vr committed Mar 11, 2017
2 parents 72c4445 + 0b4741a commit aac4d04
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 3.1.1
- Handle empty bodies correctly
## 3.1.0
- Use rufus-scheduler for more flexible scheduling. Many thanks to [@hummingV](https://github.com/hummingV) for this contribution. ([#58](https://github.com/logstash-plugins/logstash-input-http_poller/pull/58))

Expand Down
12 changes: 10 additions & 2 deletions lib/logstash/inputs/http_poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,16 @@ def request_async(queue, name, request)

private
def handle_success(queue, name, request, response, execution_time)
@codec.decode(response.body) do |decoded|
event = @target ? LogStash::Event.new(@target => decoded.to_hash) : decoded
body = response.body
# If there is a usable response. HEAD requests are `nil` and empty get
# responses come up as "" which will cause the codec to not yield anything
if body && body.size > 0
@codec.decode(body) do |decoded|
event = @target ? LogStash::Event.new(@target => decoded.to_hash) : decoded
handle_decoded_event(queue, name, request, response, event, execution_time)
end
else
event = ::LogStash::Event.new
handle_decoded_event(queue, name, request, response, event, execution_time)
end
end
Expand Down
2 changes: 1 addition & 1 deletion logstash-input-http_poller.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'logstash-input-http_poller'
s.version = '3.1.0'
s.version = '3.1.1'
s.licenses = ['Apache License (2.0)']
s.summary = "Poll HTTP endpoints with Logstash."
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand Down
11 changes: 10 additions & 1 deletion spec/inputs/http_poller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@

describe "a valid request and decoded response" do
let(:payload) { {"a" => 2, "hello" => ["a", "b", "c"]} }
let(:response_body) { LogStash::Json.dump(payload) }
let(:opts) { default_opts }
let(:instance) {
klass.new(opts)
Expand All @@ -414,7 +415,7 @@
instance.register
u = url.is_a?(Hash) ? url["url"] : url # handle both complex specs and simple string URLs
instance.client.stub(u,
:body => LogStash::Json.dump(payload),
:body => response_body,
:code => code
)
allow(instance).to receive(:decorate)
Expand All @@ -430,6 +431,14 @@
end

include_examples("matching metadata")

context "with an empty body" do
let(:response_body) { "" }
it "should return an empty event" do
instance.send(:run_once, queue)
expect(event.get("[_http_poller_metadata][response_headers][content-length]")).to eql("0")
end
end

context "with metadata omitted" do
let(:opts) {
Expand Down

0 comments on commit aac4d04

Please sign in to comment.