From 71c39fcd4722cb37f4ac59d7f43c2d1bde70558e Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 7 Jan 2026 16:11:01 +0000 Subject: [PATCH] set content-type json on API requests --- internal/api/api.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/api/api.go b/internal/api/api.go index e0bc234558..5f750c1d4a 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -174,6 +174,10 @@ func (c *client) createHTTPRequest(ctx context.Context, method, p string, body i if *c.opts.Flags.trace { req.Header.Set("X-Sourcegraph-Should-Trace", "true") } + + // Set before additional headers, in case of an override. + req.Header.Set("Content-Type", "application/json") + for k, v := range c.opts.AdditionalHeaders { req.Header.Set(k, v) } @@ -322,6 +326,10 @@ func (r *request) curlCmd() (string, error) { if r.client.opts.AccessToken != "" { s += fmt.Sprintf(" %s \\\n", shellquote.Join("-H", "Authorization: token "+r.client.opts.AccessToken)) } + // Preserve overrides if Content-Type is set + if r.client.opts.AdditionalHeaders["Content-Type"] == "" { + r.client.opts.AdditionalHeaders["Content-Type"] = "application/json" + } for k, v := range r.client.opts.AdditionalHeaders { s += fmt.Sprintf(" %s \\\n", shellquote.Join("-H", k+": "+v)) }