From 98a423df2abc915c1c10d7bda175636b60a6094b Mon Sep 17 00:00:00 2001 From: Marius Iversen Date: Mon, 27 Jul 2020 11:48:04 +0200 Subject: [PATCH] adding possibility to override content-type checks, it was breaking certain webhooks that is not able to set content-headers at all. Still defaults to application/json (#20232) --- .../docs/inputs/input-http-endpoint.asciidoc | 17 +++++++++++++++++ x-pack/filebeat/input/http_endpoint/config.go | 2 ++ x-pack/filebeat/input/http_endpoint/input.go | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/x-pack/filebeat/docs/inputs/input-http-endpoint.asciidoc b/x-pack/filebeat/docs/inputs/input-http-endpoint.asciidoc index 2a949b01d26..18d60e9e145 100644 --- a/x-pack/filebeat/docs/inputs/input-http-endpoint.asciidoc +++ b/x-pack/filebeat/docs/inputs/input-http-endpoint.asciidoc @@ -41,6 +41,17 @@ Custom response example: prefix: "json" ---- +Disable Content-Type checks +["source","yaml",subs="attributes"] +---- +{beatname_lc}.inputs: +- type: http_endpoint + enabled: true + listen_address: 192.168.1.1 + content_type: "" + prefix: "json" +---- + Basic auth and SSL example: ["source","yaml",subs="attributes"] ---- @@ -80,6 +91,12 @@ If `basic_auth` is enabled, this is the username used for authentication against If `basic_auth` is eanbled, this is the password used for authentication against the HTTP listener. Requires `username` to also be set. +[float] +==== `content_type` + +By default the input expects the incoming POST to include a Content-Type of `application/json` to try to enforce the incoming data to be valid JSON. +In certain scenarios when the source of the request is not able to do that, it can be overwritten with another value or set to null + [float] ==== `response_code` diff --git a/x-pack/filebeat/input/http_endpoint/config.go b/x-pack/filebeat/input/http_endpoint/config.go index 41e97489cec..acd549e77ee 100644 --- a/x-pack/filebeat/input/http_endpoint/config.go +++ b/x-pack/filebeat/input/http_endpoint/config.go @@ -23,6 +23,7 @@ type config struct { ListenPort string `config:"listen_port"` URL string `config:"url"` Prefix string `config:"prefix"` + ContentType string `config:"content_type"` } func defaultConfig() config { @@ -36,6 +37,7 @@ func defaultConfig() config { ListenPort: "8000", URL: "/", Prefix: "json", + ContentType: "application/json", } } diff --git a/x-pack/filebeat/input/http_endpoint/input.go b/x-pack/filebeat/input/http_endpoint/input.go index c79fd2cba22..e21fb4325b2 100644 --- a/x-pack/filebeat/input/http_endpoint/input.go +++ b/x-pack/filebeat/input/http_endpoint/input.go @@ -87,7 +87,7 @@ func (e *httpEndpoint) Run(ctx v2.Context, publisher stateless.Publisher) error username: e.config.Username, password: e.config.Password, method: http.MethodPost, - contentType: "application/json", + contentType: e.config.ContentType, } handler := &httpHandler{