diff --git a/base_interface.go b/base_interface.go index 60c04bda..62437725 100644 --- a/base_interface.go +++ b/base_interface.go @@ -1,6 +1,8 @@ package sendgrid import ( + "bytes" + "compress/gzip" "context" "errors" "net/http" @@ -61,6 +63,15 @@ func (cl *Client) Send(email *mail.SGMailV3) (*rest.Response, error) { // SendWithContext sends an email through Twilio SendGrid with context.Context. func (cl *Client) SendWithContext(ctx context.Context, email *mail.SGMailV3) (*rest.Response, error) { cl.Body = mail.GetRequestBody(email) + if cl.Headers["Content-Encoding"] == "gzip" { + var gzipped bytes.Buffer + gz := gzip.NewWriter(&gzipped) + defer gz.Close() + if _, err := gz.Write(cl.Body); err != nil { + return nil, err + } + cl.Body = gzipped.Bytes() + } return MakeRequestWithContext(ctx, cl.Request) }