fluent/fluentd — pull request #400 by komamitsu (2014-08-10 07:04:53+00:00)
Title: in_http: Initialize @content_type per request not per connection

This is a minor issue but I think we'd better fix it for the future.

In in_http plugin, `@content_type` is initialized only in `Fluent::HttpInput::Handler#initialize`. But with Keep-Alive, the instance can handle multiple-requests. In case that the first request has a Content-Type and the second request doesn't have any Content-Type, the Handler instance holds the first Content-Type even while handling the second request.

With adding the following debug log, we can see that in_http hold the wrong Content-Type while dealing with the second request.

```
def on_message_complete
return if closing?

@env['REMOTE_ADDR'] = @remote_addr if @remote_addr

+ puts "content_type: #{@content_type}"
+
uri = URI.parse(@parser.request_url)
params = WEBrick::HTTPUtils.parse_query(uri.query)

if @format != 'default'
params[EVENT_RECORD_PARAMETER] = @body
```

And send multiple requests in one connection like this:

```
require 'net/http'

Net::HTTP.start('127.0.0.1', 9880){|x|
req = Net::HTTP::Post.new('/db/tbl', {'Content-Type' => 'application/json'})
req.body = '{"a":123}'
x.request(req)

req = Net::HTTP::Get.new('/db/tbl')
x.request(req)
}
```

in_http plugin output this log. According to it, in_http handled the second request as having `Content-Type: application/json` despite it had no Content-Type actually.

```
content_type: application/json
2014-08-10 14:25:50 +0900 db.tbl: {"a":123}
content_type: application/json
```

With this pull request, it output as follows

```
content_type: application/json
2014-08-10 14:27:12 +0900 db.tbl: {"a":123}
content_type:
```

Actually, this issue doesn't matter to in_http itself at the present. But we can run into this wrong behavior when extending in_http plugin.