-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add respond with empty image #480
Conversation
Thanks! |
@@ -367,5 +376,5 @@ def send_response_nobody(code, header) | |||
write data | |||
end | |||
end | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this indentation is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably an editor issue on my side
@Telmo any update? I am thinking of creating a use case tutorial with this new feature. |
I should be able to update the pul request early tomorrow morning |
Awesome! |
Added tests for respond_with_empty_img
I am running into issues with the encoding and would appreciate some help. I have set the content type to
however it seems to always return as ASCII-8BIT no matter what I do. You can see the error in TravisCI job #43097409 |
My preceding comment about 'false' => false has nothing to do with your encoding question. Sorry for the possible confusion. About your encoding, it looks like Ruby's Net::HTTP is forcing ascii-8bit encoding when the response body is deemed to be GIF. To see this, I made the following change: $ git diff lib/
diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb
index 2321a22..6a44865 100644
--- a/lib/fluent/plugin/in_http.rb
+++ b/lib/fluent/plugin/in_http.rb
@@ -171,7 +171,7 @@ module Fluent
end
if @respond_with_empty_img
- return ["200 OK", {'Content-type'=>'image/gif; charset=utf-8'}, EMPTY_GIF_IMAGE]
+ return ["200 OK", {'Content-type'=>'image/gif; charset=utf-8'}, 'hello world']
else
return ["200 OK", {'Content-type'=>'text/plain'}, ""]
end Then, when I manually run (from irb)
Note that the response's "content-type" was still "image/gif". So, I suggest that we update it as follows: $ git diff lib
diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb
index 2321a22..b221ef2 100644
--- a/lib/fluent/plugin/in_http.rb
+++ b/lib/fluent/plugin/in_http.rb
@@ -28,7 +28,7 @@ module Fluent
super
end
- EMPTY_GIF_IMAGE = "GIF89a\u0001\u0000\u0001\u0000\x80\xFF\u0000\xFF\xFF\xFF\u0000\u0000\u0000,\u0000\u0000\u0000\u000
+ EMPTY_GIF_IMAGE = "GIF89a\u0001\u0000\u0001\u0000\x80\xFF\u0000\xFF\xFF\xFF\u0000\u0000\u0000,\u0000\u0000\u0000\u000
config_param :port, :integer, :default => 9880
config_param :bind, :string, :default => '0.0.0.0' EDIT: minor clarifications. |
It seems ruby level problem, right? |
I have tried calling |
With the following change to your PR, I managed to get it to pass the test. Can you check? (EDIT: I got rid of the unnecessary update to the post parameters.) diff --git a/test/plugin/test_in_http.rb b/test/plugin/test_in_http.rb
index d2fdf7f..dd4cf5c 100644
--- a/test/plugin/test_in_http.rb
+++ b/test/plugin/test_in_http.rb
@@ -213,7 +213,8 @@ class HttpInputTest < Test::Unit::TestCase
d.expected_emits.each {|tag,time,record|
res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s})
assert_equal "200", res.code
- assert_equal Fluent::HttpInput::EMPTY_GIF_IMAGE, res.body
+ # Ruby returns ASCII-8 encoded string for GIF.
+ assert_equal Fluent::HttpInput::EMPTY_GIF_IMAGE, res.body.force_encoding("UTF-8")
}
end
end |
Updated test after hitting an issue with [Net:HTTP encoding](https://bugs.ruby-lang.org/issues/2567), thanks to @kioto for the help with this
@kiyoto thanks a lot for the help with the test. I have updated the PR, it implements the changes you made to the test and also fixes the issue with the false being a string instead of a boolean |
the rubinious tests in Travis are taking forever. This test https://travis-ci.org/fluent/fluentd/jobs/43472778 has been going for 45 minutes at the moment of updating this comment and it is still installing the gemset |
Add respond with empty image
Rubinius tests are not important so just merged. Thanks! |
Add respond with empty image Conflicts: test/plugin/test_in_http.rb
cherry-picked to v0.10 branch |
As discussed at RubyConf
Closes #86
All credit should go for @parolkar I just implemented his changes.