Skip to content

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

Merged
datho7561 merged 2 commits intoredhat-developer:mainfrom
svifred:user-agent
Apr 22, 2026
Merged

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

Conversation

@svifred
Copy link
Copy Markdown
Contributor

@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 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
Contributor 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!

@svifred
Copy link
Copy Markdown
Contributor Author

svifred commented Apr 22, 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?

@datho7561 You may use https://schema.bankdata.dk/schemas/automation-highway-yaml/1/schema.json

  • curl -v https://schema.bankdata.dk/schemas/automation-highway-yaml/1/schema.json results in 403 Forbidden with a CloudFlare error page.
  • curl -v -H "User-Agent: yaml-language-server/dev" https://schema.bankdata.dk/schemas/automation-highway-yaml/1/schema.json results in 200 OK and the schema.

Please note, that not all values of user agent is treated equally, meaning yaml-language-server is accepted, other values may not be.

Copy link
Copy Markdown
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified it works with that schema you linked. Thanks, Steffen!

I'm going to replicate this on the vscode-yaml side, since on VS Code, the language server forwards the request to the client to resolve, and the code on the client that does the resolving also doesn't set a User-Agent.

@datho7561 datho7561 added the bug label Apr 22, 2026
@datho7561 datho7561 added this to the 1.23.0 milestone Apr 22, 2026
svifred added 2 commits April 22, 2026 18:04
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.
@datho7561 datho7561 merged commit 93b9e72 into redhat-developer:main Apr 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants