Skip to content

Commit

Permalink
Set Accept header to 'application/json' for GraphQL queries (#7312)
Browse files Browse the repository at this point in the history
## Changes

This PR fixes setting `Accept` header to `'application/json'` which is
required by some proxies to work.

## Test plan

Tested with a local reverse proxy.

Prerequisites (YOUR_TOKEN is a token configured for your user at
YOUR_INSTANCE):

1. Right cody_setting.json configuration:

```
{
  "cody.override.serverEndpoint":  "https://localhost:443",

  "cody.auth.externalProviders": [
    {
      "endpoint": "https://localhost:443",
      "executable": {
        "commandLine": ["echo '{ \"headers\": { \"Authorization\": \"token YOUR_TOKEN\" } }'"],
        "shell": "/bin/bash"
      }
    },
```
2. Proxy running in the console: mitmproxy -m
reverse:https://YOUR_INSTANCE/ -p 443

Then you can start cody, and in the proxy console you should be able to
inspect one of the graphql requests and see something like this:


![image](https://github.com/user-attachments/assets/10a2f62a-0abb-440c-ac6e-49bd1eb0de73)
  • Loading branch information
pkukielka authored Mar 4, 2025
1 parent 8c831bd commit d669832
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/shared/src/sourcegraph-api/graphql/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ export class SourcegraphGraphQLAPIClient {
signal?.throwIfAborted()

const headers = new Headers(config.configuration?.customHeaders as HeadersInit | undefined)
headers.set('Content-Type', 'application/json; charset=utf-8')

if (config.clientState.anonymousUserID && !process.env.CODY_WEB_DONT_SET_SOME_HEADERS) {
headers.set('X-Sourcegraph-Actor-Anonymous-UID', config.clientState.anonymousUserID)
}
Expand All @@ -1615,6 +1615,7 @@ export class SourcegraphGraphQLAPIClient {

addTraceparent(headers)
addCodyClientIdentificationHeaders(headers)
setJSONAcceptContentTypeHeaders(headers)

try {
await addAuthHeaders(config.auth, headers, url)
Expand Down

0 comments on commit d669832

Please sign in to comment.