diff --git a/CHANGELOG.md b/CHANGELOG.md index 20ae757029b6a..880107c65ff21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Main * [4400](https://github.com/grafana/loki/pull/4400) **trevorwhitney**: Config: automatically apply memberlist config too all rings when provided +* [4443](https://github.com/grafana/loki/pull/4443) **DylanGuedes**: Loki: Change how push API checks for contentType # 2.3.0 (2021/08/06) diff --git a/pkg/loghttp/push/push.go b/pkg/loghttp/push/push.go index dcd0eceb6493d..fba001e26d6ba 100644 --- a/pkg/loghttp/push/push.go +++ b/pkg/loghttp/push/push.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "math" + "mime" "net/http" "time" @@ -78,8 +79,14 @@ func ParseRequest(logger log.Logger, userID string, r *http.Request, tenantsRete req logproto.PushRequest ) + contentType, _ /* params */, err := mime.ParseMediaType(contentType) + if err != nil { + return nil, err + } + switch contentType { case applicationJSON: + var err error // todo once https://github.com/weaveworks/common/commit/73225442af7da93ec8f6a6e2f7c8aafaee3f8840 is in Loki. diff --git a/pkg/loghttp/push/push_test.go b/pkg/loghttp/push/push_test.go index 60e7ef67e88aa..c0970bd450d4b 100644 --- a/pkg/loghttp/push/push_test.go +++ b/pkg/loghttp/push/push_test.go @@ -72,6 +72,27 @@ func TestParseRequest(t *testing.T) { contentEncoding: `snappy`, valid: false, }, + { + path: `/loki/api/v1/push`, + body: gzipString(`{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1570818238000000000", "fizzbuzz" ] ] }]}`), + contentType: `application/json; charset=utf-8`, + contentEncoding: `gzip`, + valid: true, + }, + { + path: `/loki/api/v1/push`, + body: gzipString(`{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1570818238000000000", "fizzbuzz" ] ] }]}`), + contentType: `application/jsonn; charset=utf-8`, + contentEncoding: `gzip`, + valid: false, + }, + { + path: `/loki/api/v1/push`, + body: gzipString(`{"streams": [{ "stream": { "foo4": "bar2" }, "values": [ [ "1570818238000000000", "fizzbuzz" ] ] }]}`), + contentType: `application/json; charsetutf-8`, + contentEncoding: `gzip`, + valid: false, + }, } // Testing input array