add datadog deflate encoding

This commit is contained in:
Ulric Qin 2021-12-29 14:59:05 +08:00
parent 3700f7a10b
commit 904d09d91c
1 changed files with 12 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package router
import (
"compress/gzip"
"compress/zlib"
"encoding/json"
"fmt"
"io/ioutil"
@ -162,7 +163,9 @@ func datadogSeries(c *gin.Context) {
var bs []byte
var err error
if c.GetHeader("Content-Encoding") == "gzip" {
enc := c.GetHeader("Content-Encoding")
if enc == "gzip" {
r, err := gzip.NewReader(c.Request.Body)
if err != nil {
c.String(400, err.Error())
@ -170,6 +173,14 @@ func datadogSeries(c *gin.Context) {
}
defer r.Close()
bs, err = ioutil.ReadAll(r)
} else if enc == "deflate" {
r, err := zlib.NewReader(c.Request.Body)
if err != nil {
c.String(400, err.Error())
return
}
defer r.Close()
bs, err = ioutil.ReadAll(r)
} else {
defer c.Request.Body.Close()
bs, err = ioutil.ReadAll(c.Request.Body)