Skip to content

fix: add User-Agent header to OpenAI client fetch (#177) - #273

Open
innocarpe wants to merge 2 commits into
lessweb:mainfrom
innocarpe:fix/177-user-agent
Open

fix: add User-Agent header to OpenAI client fetch (#177)#273
innocarpe wants to merge 2 commits into
lessweb:mainfrom
innocarpe:fix/177-user-agent

Conversation

@innocarpe

Copy link
Copy Markdown

Summary

  • Adds a default User-Agent header to outgoing OpenAI API requests.
  • Fixes 403 Your request was blocked errors from CDNs/WAFs (e.g. Cloudflare) that reject requests without a User-Agent.

Why

Custom/proxy API endpoints routed through Cloudflare or enterprise WAFs block requests arriving without a User-Agent as a basic anti-bot measure. The undici fetch wrapper used by the OpenAI client never set one, so those setups failed immediately with 403.

Changes

  • packages/core/src/common/openai-client.ts: add buildClientHeaders() which injects deepcode-cli (Node.js <version>) unless the caller already provided a header, and use it in the fetch wrapper.
  • packages/core/src/tests/openai-client.test.ts: unit tests for header injection/preservation.

Validation

  • npm run typecheck
  • npm test — new openai-client tests pass ✅

Closes #177

Some CDNs and WAFs (e.g. Cloudflare) block requests that arrive without a User-Agent. Inject a default one into the undici fetch wrapper, preserving any caller-provided headers.

(cherry picked from commit 67a33160c870c301342eb6b3a70ae01609976c7e)
The undici HeadersInit type used by buildClientHeaders does not accept the global Headers instance in this project's TS config, so switch the test to a tuple-array input.

(cherry picked from commit 8ee5241e83e602a87fd64151997dad06b79708f6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix 403 Forbidden: Add User-Agent header to OpenAI client fetch to prevent WAF/Cloudflare blocks

1 participant