Skip to content

Commit

Permalink
ingest: batch endpoint: support gzipped content
Browse files Browse the repository at this point in the history
  • Loading branch information
absorbb committed Dec 20, 2023
1 parent 9b471f2 commit 3693c0f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ingest/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"compress/gzip"
"crypto/sha512"
"encoding/base64"
"encoding/json"
Expand Down Expand Up @@ -226,7 +227,14 @@ func (r *Router) BatchHandler(c *gin.Context) {
rError = r.ResponseError(c, http.StatusBadRequest, "invalid content type", false, fmt.Errorf("%s. Expected: application/json", c.ContentType()), true)
return
}
err := json.NewDecoder(c.Request.Body).Decode(&payload)
bodyReader := c.Request.Body
var err error
if strings.Contains(c.GetHeader("Content-Encoding"), "gzip") {
bodyReader, err = gzip.NewReader(bodyReader)
}
if err == nil {
err = json.NewDecoder(bodyReader).Decode(&payload)
}
if err != nil {
err = fmt.Errorf("Client Ip: %s: %v", utils.NvlString(c.GetHeader("X-Real-Ip"), c.GetHeader("X-Forwarded-For"), c.ClientIP()), err)
rError = r.ResponseError(c, http.StatusOK, "error parsing message", false, err, true)
Expand Down

0 comments on commit 3693c0f

Please sign in to comment.