Comments (9)
Thanks Donny, nice catch - seems like this would be worth a quick PR.
from logstash-filter-http.
There is a closely related issue... If you use verb => "HEAD"
and the response headers set the content type to application/json then body is nil and it blows up a few lines earlier in the other branch of the content-type test. The error logged is "JSON parsing error {:message=>"class org.jruby.RubyNil cannot be cast to class org.jruby.RubyIO"
from logstash-filter-http.
^^^ is correct, the plugin is not handling HEAD requests (or simply nil
bodies) gracefully.
in those cases the whole logic should be skipped e.g.
def process_response(body, headers, event)
content_type, _ = headers.fetch("content-type", "").split(";")
event.set(@target_headers, headers)
return if body.nil? # new line added
if content_type == "application/json"
# ...
this would need some tests - worth a PR if anyone is up for one.
from logstash-filter-http.
Duplicate #39
I will close my issue
from logstash-filter-http.
Hi! Would it be unseemly of me to "bump" this issue?
We're experiencing that this plugin crashes with an exception (crashing logstash) when we make an http
request that returns an HTTP 204. It seems that Ruby does not populate the response body in this case, but the plugin unconditionally accesses the response body in process_response
, which is called for all HTTP statuses in the 200
to 299
range.
from logstash-filter-http.
Just for reference, a workaround for those who stuck, is to use ruby plugin like this example
ruby {
# POST http://bonita:8080/bonita/loginservice
# returns 204 empty body and X-Bonita-API-Token and JSESSIONID cookies
code => "
require 'uri'
require 'net/http'
uri = URI('http://bonita:8080/bonita/loginservice')
res = Net::HTTP.post_form(uri, 'username' => 'admin', 'password' => 'admin')
cookies = res['set-cookie'].split(';')
cookies.each do |cookie|
if cookie.include? 'JSESSIONID'
event.set('[@metadata][JSESSIONID]', cookie.split('=')[2])
end
if cookie.include? 'X-Bonita-API-Token'
event.set('[@metadata][X-Bonita-API-Token]', cookie.split('=')[2])
end
end
"
}
from logstash-filter-http.
the plugin is not handling HEAD requests (or simply
nil
bodies) gracefully. in those cases the whole logic should be skipped e.g.
This was implemented in PR 40.
from logstash-filter-http.
Hi! Sorry, but PR #40 does not address the issue described. The PR skips attempting to process the response body when the request verb is HEAD. However, there are other situations in the HTTP protocol where we do not expect a response body, for example, HTTP 204.
If a GET is performed and the response is HTTP 204, the code will continue to try and access the response body, which causes an unhandled exception in ruby.
from logstash-filter-http.
You are right, PR 40 implements "return if @verb == 'HEAD'", which handles one case, but "return if body.nil?" which @kares suggested would handle more. It is a one line change if anyone wants to do it...
from logstash-filter-http.
Related Issues (20)
- Implement native caching for higher scale lookups HOT 4
- Debug message causes Fatal error HOT 2
- Add ability to disable SSL certificate validation HOT 4
- Cannot send Content-Type header HOT 6
- Documentation Mismatch HOT 1
- Unable to add event field to http body HOT 3
- Unhelpful error message when body is hash and body_format is text
- Unable to parse Json with one field or none + needed clarity on target_body parameter
- Implement ECS-Compatibility Mode
- Authentication username and password are not interpolated
- Is it possible to do PUT requests from this plugin HOT 1
- Friendlier handling of non 200 response codes HOT 2
- tag_on_request_failure and tag_on_json_failure are not documented
- Handle Empty body in HTTP response HOT 1
- Doesn't respect quoted characters HOT 3
- Plugin crashes when it receives Array type of content-type header.
- Need clarification on sending data as json
- Some APIs allow for batch processing, how can we provide batch support?
- Add support to extract a value from the response.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logstash-filter-http.