Skip to content

Commit 86a81e1

Browse files
committed
feat: add User-Agent header to HTTP/HTTPS schema fetch requests
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.
1 parent 0ae5603 commit 86a81e1

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/languageservice/services/schemaRequestHandler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ export const schemaRequestHandler = async (
8888
}
8989

9090
// Send the HTTP(S) schema content request and return the result
91-
const headers = { 'Accept-Encoding': 'gzip, deflate' };
91+
const version = (typeof process !== 'undefined' && process.env.YAML_LANGUAGE_SERVER_VERSION) || 'unknown';
92+
const nodeVersion = typeof process !== 'undefined' && process.versions?.node ? ` node/${process.versions.node}` : '';
93+
const platform = typeof process !== 'undefined' && process.platform ? ` (${process.platform})` : '';
94+
const headers = {
95+
'Accept-Encoding': 'gzip, deflate',
96+
'User-Agent': `yaml-language-server/${version} (RedHat)${nodeVersion}${platform}`,
97+
};
9298
return xhr({ url: uri, followRedirects: 5, headers }).then(
9399
(response) => {
94100
return response.responseText;

0 commit comments

Comments
 (0)