feat: Set User-agent header when requesting schema over HTTP(S)#1226
feat: Set User-agent header when requesting schema over HTTP(S)#1226datho7561 merged 2 commits intoredhat-developer:mainfrom
Conversation
|
This seems like it would be pretty helpful. Do you have an example of a schema behind a CDN that rejects requests without a |
I'll see what I can dig up without referencing enterprise internal infrastructure. Stay tuned! |
@datho7561 You may use https://schema.bankdata.dk/schemas/automation-highway-yaml/1/schema.json
Please note, that not all values of user agent is treated equally, meaning |
datho7561
left a comment
There was a problem hiding this comment.
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.
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.
What does this PR do?
Some CDNs block requests, when
User-agentheader is unset. This PR adds theUser-agentheader 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.