Skip to content

feat: Set User-agent header when requesting schema over HTTP(S)#1226

Open
svifred wants to merge 2 commits intoredhat-developer:mainfrom
svifred:user-agent
Open

feat: Set User-agent header when requesting schema over HTTP(S)#1226
svifred wants to merge 2 commits intoredhat-developer:mainfrom
svifred:user-agent

Conversation

@svifred
Copy link
Copy Markdown

@svifred svifred commented Apr 13, 2026

What does this PR do?

Some CDNs block requests, when User-agent header is unset. This PR adds the User-agent header til HTTP(S) requests for schemas.

What issues does this PR fix or reference?

No issue in GitHub, but problem has been spotted "in the wild", where CloudFlare challenges requests for schemas in VS Code.

Is it tested? How?

Only tested in unit tests.

Note on AI assistance

Extensive AI assistance was used to create this PR, specifically Claude Sonnet 4.6 using OpenCode.

svifred added 2 commits April 13, 2026 10:52
Include a well-formed RFC 9110-compliant User-Agent on all direct xhr calls
when fetching schemas over HTTP or HTTPS:

  yaml-language-server/<version> (RedHat) node/<nodeVersion> (<platform>)

The server version is read from YAML_LANGUAGE_SERVER_VERSION, the Node.js
version from process.versions.node, and the platform from process.platform.
All three are guarded with typeof-process checks for browser/web worker
safety, falling back to 'unknown' for the version and omitting the runtime
and platform tokens entirely in non-Node environments.
Cover version from env var, 'unknown' fallback, http:// parity,
Accept-Encoding preservation, successful response handling, and
xhr error rejection.
@svifred svifred requested a review from datho7561 as a code owner April 13, 2026 12:03
@datho7561
Copy link
Copy Markdown
Contributor

This seems like it would be pretty helpful. Do you have an example of a schema behind a CDN that rejects requests without a User-Agent to test against?

@svifred
Copy link
Copy Markdown
Author

svifred commented Apr 17, 2026

This seems like it would be pretty helpful. Do you have an example of a schema behind a CDN that rejects requests without a User-Agent to test against?

I'll see what I can dig up without referencing enterprise internal infrastructure. Stay tuned!

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.

2 participants