Skip to content

Commit

Permalink
Merge pull request #836 from cosmo0920/in_http-character-cases-of-res…
Browse files Browse the repository at this point in the history
…ponse-header

In http: Use RFC suggested character cases of HTTP response header
  • Loading branch information
repeatedly committed Mar 9, 2016
2 parents 489cec0 + 7b3ad47 commit f7d6ef7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions lib/fluent/plugin/in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def on_request(path_info, params)
# Skip nil record
if record.nil?
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'}, EMPTY_GIF_IMAGE]
else
return ["200 OK", {'Content-type'=>'text/plain'}, ""]
return ["200 OK", {'Content-Type'=>'text/plain'}, ""]
end
end

Expand All @@ -168,7 +168,7 @@ def on_request(path_info, params)
record_time.nil? ? Engine.now : record_time
end
rescue
return ["400 Bad Request", {'Content-type'=>'text/plain'}, "400 Bad Request\n#{$!}\n"]
return ["400 Bad Request", {'Content-Type'=>'text/plain'}, "400 Bad Request\n#{$!}\n"]
end

# TODO server error
Expand All @@ -195,13 +195,13 @@ def on_request(path_info, params)
router.emit(tag, time, record)
end
rescue
return ["500 Internal Server Error", {'Content-type'=>'text/plain'}, "500 Internal Server Error\n#{$!}\n"]
return ["500 Internal Server Error", {'Content-Type'=>'text/plain'}, "500 Internal Server Error\n#{$!}\n"]
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'}, EMPTY_GIF_IMAGE]
else
return ["200 OK", {'Content-type'=>'text/plain'}, ""]
return ["200 OK", {'Content-Type'=>'text/plain'}, ""]
end
end

Expand Down Expand Up @@ -384,8 +384,8 @@ def closing?
end

def send_response(code, header, body)
header['Content-length'] ||= body.bytesize
header['Content-type'] ||= 'text/plain'
header['Content-Length'] ||= body.bytesize
header['Content-Type'] ||= 'text/plain'

data = %[HTTP/1.1 #{code}\r\n]
header.each_pair {|k,v|
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/test_in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_application_json

d.run do
d.expected_emits.each {|tag,time,record|
res = post("/#{tag}?time=#{time.to_s}", record.to_json, {"content-type"=>"application/json; charset=utf-8"})
res = post("/#{tag}?time=#{time.to_s}", record.to_json, {"Content-Type"=>"application/json; charset=utf-8"})
assert_equal "200", res.code
}
end
Expand Down Expand Up @@ -323,7 +323,7 @@ def on_message_complete
d.run do
# Send two requests the second one has no Content-Type in Keep-Alive
Net::HTTP.start("127.0.0.1", PORT) do |http|
req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "content-type" => "application/json"})
req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "Content-Type" => "application/json"})
res = http.request(req)

req = Net::HTTP::Get.new("/foodb/bartbl", {"connection" => "keepalive"})
Expand Down

0 comments on commit f7d6ef7

Please sign in to comment.