diff --git a/CHANGES.txt b/CHANGES.txt index 6ce3297df..8b109189d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -51,6 +51,8 @@ Features * Added iowait percentage output field in filter procstat (#1888). +* Added ability to deflate gzip'd payloads in HttpListenInput. + 0.10.1 (2016-??-??) =================== diff --git a/docs/source/config/inputs/httplisten.rst b/docs/source/config/inputs/httplisten.rst index 99ced5141..6bea01b8e 100644 --- a/docs/source/config/inputs/httplisten.rst +++ b/docs/source/config/inputs/httplisten.rst @@ -72,6 +72,12 @@ Config: encryption. This will only have any impact if `use_tls` is set to true. See :ref:`tls`. +.. versionadded:: 0.11 + +- deflate (bool): + If true and a request has the "Content-Encoding" header set to "gzip", attempt + to deflate the body. + Example: .. code-block:: ini diff --git a/plugins/http/http_listen_input.go b/plugins/http/http_listen_input.go index 215144a81..ca6195533 100644 --- a/plugins/http/http_listen_input.go +++ b/plugins/http/http_listen_input.go @@ -17,6 +17,7 @@ package http import ( + "compress/gzip" "crypto/tls" "errors" "fmt" @@ -52,6 +53,7 @@ type HttpListenInputConfig struct { Username string `toml:"username"` Password string `toml:"password"` Key string `toml:"api_key"` + Deflate bool `toml:"deflate"` // Set to true if the TCP connection should be tunneled through TLS. // Requires additional Tls config section. UseTls bool `toml:"use_tls"` @@ -198,7 +200,17 @@ func (hli *HttpListenInput) RequestHandler(w http.ResponseWriter, req *http.Requ if !sRunner.UseMsgBytes() { sRunner.SetPackDecorator(hli.makePackDecorator(req)) } - err = sRunner.SplitStreamNullSplitterToEOF(req.Body, nil) + + if req.Header.Get("Content-Encoding") == "gzip" && hli.conf.Deflate { + gz, err := gzip.NewReader(req.Body) + defer gz.Close() + if err == nil { + err = sRunner.SplitStreamNullSplitterToEOF(gz, nil) + } + } else { + err = sRunner.SplitStreamNullSplitterToEOF(req.Body, nil) + } + if err != nil && err != io.EOF { hli.ir.LogError(fmt.Errorf("receiving request body: %s", err.Error())) }