From 44840bad2e0a527bce07f5e0e57069579607104c Mon Sep 17 00:00:00 2001 From: Kieren Hynd Date: Fri, 29 Apr 2016 13:18:13 +0100 Subject: [PATCH] Add ability to deflate gzip'd payloads in HttpListenInput --- CHANGES.txt | 2 ++ docs/source/config/inputs/httplisten.rst | 6 ++++++ plugins/http/http_listen_input.go | 14 +++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) 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())) }