Make sure status is an integer when set

This commit is contained in:
Akinori MUSHA 2016-11-23 11:16:14 +09:00
parent a94cd7fd6d
commit 9074f3115e
2 changed files with 5 additions and 5 deletions

View file

@ -134,7 +134,7 @@ module Agents
* `_response_`: A response object with the following keys:
* `status`: HTTP status as integer. (Almost always 200) When parsing `data_from_event`, this is set to the value of the `status` key in the incoming Event.
* `status`: HTTP status as integer. (Almost always 200) When parsing `data_from_event`, this is set to the value of the `status` key in the incoming Event, if it is a number or a string convertible to an integer.
* `headers`: Response headers; for example, `{{ _response_.headers.Content-Type }}` expands to the value of the Content-Type header. Keys are insensitive to cases and -/_. When parsing `data_from_event`, this is constructed from the value of the `headers` key in the incoming Event.
@ -694,7 +694,7 @@ module Agents
# Integer value of HTTP status
def status
@object.payload[:status]
Integer(@object.payload[:status]) rescue nil
end
# The URL

View file

@ -1198,7 +1198,7 @@ fire: hot
'value' => '{{ value }}',
'url' => '{{ url | to_uri: _response_.url }}',
'type' => '{{ _response_.headers.content_type }}',
'status' => '{{ _response_.status }}'
'status' => '{{ _response_.status | as_object }}'
}
)
end
@ -1207,7 +1207,7 @@ fire: hot
expect {
@checker.receive([@event])
}.to change { Event.count }.by(1)
expect(@checker.events.last.payload).to eq({ 'value' => 'world', 'url' => 'http://example.com/world', 'type' => 'application/json', 'status' => '200' })
expect(@checker.events.last.payload).to eq({ 'value' => 'world', 'url' => 'http://example.com/world', 'type' => 'application/json', 'status' => 200 })
end
it "should support merge mode" do
@ -1216,7 +1216,7 @@ fire: hot
expect {
@checker.receive([@event])
}.to change { Event.count }.by(1)
expect(@checker.events.last.payload).to eq(@event.payload.merge('value' => 'world', 'url' => 'http://example.com/world', 'type' => 'application/json', 'status' => '200'))
expect(@checker.events.last.payload).to eq(@event.payload.merge('value' => 'world', 'url' => 'http://example.com/world', 'type' => 'application/json', 'status' => 200))
end
it "should output an error when nothing can be found at the path" do