diff --git a/pkg/client/client_venafi_cloud.go b/pkg/client/client_venafi_cloud.go index 7e317faf..0738f420 100644 --- a/pkg/client/client_venafi_cloud.go +++ b/pkg/client/client_venafi_cloud.go @@ -2,6 +2,7 @@ package client import ( "bytes" + "compress/gzip" "crypto" "crypto/ecdsa" "crypto/ed25519" @@ -260,13 +261,20 @@ func (c *VenafiCloudClient) Post(path string, body io.Reader) (*http.Response, e return nil, err } - req, err := http.NewRequest(http.MethodPost, fullURL(c.baseURL, path), body) + encodedBody := &bytes.Buffer{} + gz := gzip.NewWriter(encodedBody) + if _, err := io.Copy(gz, body); err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodPost, fullURL(c.baseURL, path), encodedBody) if err != nil { return nil, err } req.Header.Set("Accept", "application/json") req.Header.Set("Content-Type", "application/json") + req.Header.Set("Content-Encoding", "gzip") if len(token.accessToken) > 0 { req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token.accessToken)) diff --git a/pkg/client/client_venconn.go b/pkg/client/client_venconn.go index f614ecd0..c2d335ad 100644 --- a/pkg/client/client_venconn.go +++ b/pkg/client/client_venconn.go @@ -2,6 +2,7 @@ package client import ( "bytes" + "compress/gzip" "context" "crypto/x509" "encoding/base64" @@ -157,7 +158,10 @@ func (c *VenConnClient) PostDataReadingsWithOptions(readings []*api.DataReading, DataGatherTime: time.Now().UTC(), DataReadings: readings, } - data, err := json.Marshal(payload) + + encodedBody := &bytes.Buffer{} + gz := gzip.NewWriter(encodedBody) + err = json.NewEncoder(gz).Encode(payload) if err != nil { return err } @@ -165,7 +169,7 @@ func (c *VenConnClient) PostDataReadingsWithOptions(readings []*api.DataReading, // The path parameter "no" is a dummy parameter to make the Venafi Cloud // backend happy. This parameter, named `uploaderID` in the backend, is not // actually used by the backend. - req, err := http.NewRequest(http.MethodPost, fullURL(token.BaseURL, "/v1/tlspk/upload/clusterdata/no"), bytes.NewBuffer(data)) + req, err := http.NewRequest(http.MethodPost, fullURL(token.BaseURL, "/v1/tlspk/upload/clusterdata/no"), encodedBody) if err != nil { return err }