Skip to content

Commit aac4d04

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 72c4445 + 0b4741a commit aac4d04

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 3.1.1
2+
- Handle empty bodies correctly
13
## 3.1.0
24
- 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))
35

lib/logstash/inputs/http_poller.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,16 @@ def request_async(queue, name, request)
269269

270270
private
271271
def handle_success(queue, name, request, response, execution_time)
272-
@codec.decode(response.body) do |decoded|
273-
event = @target ? LogStash::Event.new(@target => decoded.to_hash) : decoded
272+
body = response.body
273+
# If there is a usable response. HEAD requests are `nil` and empty get
274+
# responses come up as "" which will cause the codec to not yield anything
275+
if body && body.size > 0
276+
@codec.decode(body) do |decoded|
277+
event = @target ? LogStash::Event.new(@target => decoded.to_hash) : decoded
278+
handle_decoded_event(queue, name, request, response, event, execution_time)
279+
end
280+
else
281+
event = ::LogStash::Event.new
274282
handle_decoded_event(queue, name, request, response, event, execution_time)
275283
end
276284
end

logstash-input-http_poller.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-input-http_poller'
3-
s.version = '3.1.0'
3+
s.version = '3.1.1'
44
s.licenses = ['Apache License (2.0)']
55
s.summary = "Poll HTTP endpoints with Logstash."
66
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"

spec/inputs/http_poller_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@
398398

399399
describe "a valid request and decoded response" do
400400
let(:payload) { {"a" => 2, "hello" => ["a", "b", "c"]} }
401+
let(:response_body) { LogStash::Json.dump(payload) }
401402
let(:opts) { default_opts }
402403
let(:instance) {
403404
klass.new(opts)
@@ -414,7 +415,7 @@
414415
instance.register
415416
u = url.is_a?(Hash) ? url["url"] : url # handle both complex specs and simple string URLs
416417
instance.client.stub(u,
417-
:body => LogStash::Json.dump(payload),
418+
:body => response_body,
418419
:code => code
419420
)
420421
allow(instance).to receive(:decorate)
@@ -430,6 +431,14 @@
430431
end
431432

432433
include_examples("matching metadata")
434+
435+
context "with an empty body" do
436+
let(:response_body) { "" }
437+
it "should return an empty event" do
438+
instance.send(:run_once, queue)
439+
expect(event.get("[_http_poller_metadata][response_headers][content-length]")).to eql("0")
440+
end
441+
end
433442

434443
context "with metadata omitted" do
435444
let(:opts) {

0 commit comments

Comments
 (0)