fix(api): Set API identifying headers on all HTTP requests (CODY-4209) #6102
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes CODY-4209
Sets the
X-Requested-With
flag on all HTTP requests. I tested this locally with VSCode, Eclipse, JetBrains, Cody Web and the Cody CLI and for each of them (in concert with these two other PRs) saw the headers appear in the logs when I made a chat interaction.vscode
jetbrains
eclipse
web
cody-cli
We might consider either prepending each name with
sourcegraph-
if we want to be very explicit that it's our apps, but I think it's pretty clear with the current values and it's consistent with the clientName and CodyIDE values used through out the codebase today.The one tricky bit here is Cody Web because at least when developing locally, the requests to the SG instance are CORS requests and by default the local server is not a trusted origin. In the two linked PRs I added the headers to the trusted list and added the default vite server URL to the local trusted origins. I think that we shouldn't have to do anything for production because they shouldn't be CORS requests then right?
Are there any other places might I need to check or update to make sure this works?
Edit: I just added the
if
statement to exclude these headers if we're in development mode. If we like that I can probably close the dev-private PR and we won't have to make any changes to S2.Test plan
Tested manually to see that the HTTP header was present
Changelog
Sets the
X-Requested-With
header on all HTTP requests.