Skip to content

Commit

Permalink
distributor: fix snappy pb POST request handling (#3407) (#3408)
Browse files Browse the repository at this point in the history
Signed-off-by: Dr. Jan-Philip Gehrcke <jp@opstrace.com>
  • Loading branch information
jgehrcke authored Mar 1, 2021
1 parent 877f524 commit 0f881fb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/distributor/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func ParseRequest(r *http.Request) (*logproto.PushRequest, error) {
switch contentEncoding {
case "":
body = lokiutil.NewSizeReader(r.Body)
case "snappy":
// Snappy-decoding is done by `util.ParseProtoReader(..., util.RawSnappy)` below.
// Pass on body bytes. Note: HTTP clients do not need to set this header,
// but they sometimes do. See #3407.
body = lokiutil.NewSizeReader(r.Body)
case "gzip":
gzipReader, err := gzip.NewReader(r.Body)
if err != nil {
Expand Down Expand Up @@ -145,6 +150,8 @@ func ParseRequest(r *http.Request) (*logproto.PushRequest, error) {
}

default:
// When no content-type header is set or when it is set to
// `application/x-protobuf`: expect snappy compression.
if err := util.ParseProtoReader(r.Context(), body, int(r.ContentLength), math.MaxInt32, &req, util.RawSnappy); err != nil {
return nil, err
}
Expand Down

0 comments on commit 0f881fb

Please sign in to comment.