Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Add ability to deflate gzip'd payloads in HttpListenInput #1921

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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-??-??)
===================

Expand Down
6 changes: 6 additions & 0 deletions docs/source/config/inputs/httplisten.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion plugins/http/http_listen_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package http

import (
"compress/gzip"
"crypto/tls"
"errors"
"fmt"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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()))
}
Expand Down