Skip to content

Commit d6da9fb

Browse files
authored
Don't attempt to mutate the user-agent header, punt on sending environment variables (#153)
1 parent 21894e9 commit d6da9fb

2 files changed

Lines changed: 3 additions & 21 deletions

File tree

src/__tests__/directLine.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test("#setConnectionStatusFallback", () => {
2929
});
3030

3131
describe("#commonHeaders", () => {
32-
const botAgent = "DirectLine/3.0 (directlinejs/test-version; custom-bot-agent)";
32+
const botAgent = "DirectLine/3.0 (directlinejs; custom-bot-agent)";
3333
let botConnection;
3434

3535
beforeEach(() => {
@@ -42,12 +42,11 @@ describe("#commonHeaders", () => {
4242
// @ts-ignore
4343
expect(botConnection.commonHeaders()).toEqual({
4444
"Authorization": "Bearer secret-token",
45-
"User-Agent": `${botAgent} (${window.navigator.userAgent})`,
4645
"x-ms-bot-agent": botAgent
4746
});
4847
})
4948

50-
test('appends node environment agent when in node', () => {
49+
test.skip('appends node environment agent when in node', () => {
5150
// @ts-ignore
5251
delete window.navigator
5352
// @ts-ignore

src/directLine.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -889,31 +889,14 @@ export class DirectLine implements IBotConnection {
889889
}
890890

891891
private commonHeaders() {
892-
if (!this._userAgent) {
893-
try {
894-
this._userAgent = window.navigator.userAgent || '';
895-
} catch {
896-
try {
897-
// set node user agent
898-
// @ts-ignore
899-
const os = require('os');
900-
const { arch, platform, version } = process;
901-
this._userAgent = `Node.js,Version=${version}; ${platform} ${os.release()}; ${arch}`
902-
} catch {
903-
// no-op
904-
}
905-
}
906-
}
907-
908892
return {
909893
"Authorization": `Bearer ${this.token}`,
910-
"User-Agent": `${this._botAgent} (${this._userAgent})`,
911894
"x-ms-bot-agent": this._botAgent
912895
};
913896
}
914897

915898
private getBotAgent(customAgent: string = ''): string {
916-
let clientAgent = `directlinejs/${process.env.VERSION || '0.0.0'}`
899+
let clientAgent = 'directlinejs'
917900

918901
if (customAgent) {
919902
clientAgent += `; ${customAgent}`

0 commit comments

Comments
 (0)