Skip to content

Commit a1e3c35

Browse files
committed
go: Set Content-type on put requests
Also fix bug where GET request would send `null` as the body
1 parent eae9aaa commit a1e3c35

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Diff for: go/internal/svix_http_client.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,23 @@ func ExecuteRequest[ReqBody any, ResBody any](
5252
if err != nil {
5353
return nil, err
5454
}
55-
encodedBody, err := json.Marshal(jsonBody)
56-
if err != nil {
57-
return nil, err
58-
}
59-
req, err := http.NewRequestWithContext(ctx, method, urlStr, bytes.NewBuffer(encodedBody))
60-
if err != nil {
61-
return nil, err
55+
var req *http.Request
56+
if jsonBody != nil {
57+
encodedBody, err := json.Marshal(jsonBody)
58+
if err != nil {
59+
return nil, err
60+
}
61+
req, err = http.NewRequestWithContext(ctx, method, urlStr, bytes.NewBuffer(encodedBody))
62+
if err != nil {
63+
return nil, err
64+
}
65+
req.Header.Set("content-type", "application/json")
66+
} else {
67+
req, err = http.NewRequestWithContext(ctx, method, urlStr, &bytes.Buffer{})
68+
if err != nil {
69+
return nil, err
70+
}
71+
6272
}
6373

6474
req.Header.Set("svix-req-id", strconv.FormatUint(rand.Uint64(), 10))

0 commit comments

Comments
 (0)