Skip to content

Commit 58b538b

Browse files
authored
fix: properly encode user agent on WS connection (#1482)
## CLA - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required). - [ ] Code changes are tested ## Description of the changes, What, Why and How? With the recent changes to the user agent resolution within our LLC, encoding the uri component properly during building the WS url was missed. This works just fine if you're already connected, however it will fail if you're trying to connect another user. In the current state of the LLC it would only affect React Native as the other SDKs do not yet add the extra params. ## Changelog -
1 parent 77dd5ab commit 58b538b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/connection.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ export class StableWSConnection<StreamChatGenerics extends ExtendableGenerics =
189189

190190
return `${this.client.wsBaseURL}/connect?json=${qs}&api_key=${
191191
this.client.key
192-
}&authorization=${token}&stream-auth-type=${this.client.getAuthType()}&X-Stream-Client=${this.client.getUserAgent()}`;
192+
}&authorization=${token}&stream-auth-type=${this.client.getAuthType()}&X-Stream-Client=${encodeURIComponent(
193+
this.client.getUserAgent(),
194+
)}`;
193195
};
194196

195197
/**

test/unit/connection.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ describe('connection', function () {
7777
expect(data.device).to.deep.equal(device);
7878
});
7979

80+
it('should properly encode X-Stream-Client', () => {
81+
const userAgent = 'agent|val=foo bar';
82+
client.userAgent = userAgent;
83+
const url = ws._buildUrl();
84+
85+
expect(url).to.contain(encodeURIComponent(userAgent));
86+
});
87+
8088
it('should not include device if not there', function () {
8189
ws.client.options.device = undefined;
8290
const { query } = url.parse(ws._buildUrl(), true);

0 commit comments

Comments
 (0)