Skip to content

Commit 932463c

Browse files
committed
fix: Revert "fix: Use Authorization header for sending access_token to WebSocket API"
This reverts commit 7f01cb3.
1 parent 1e50c87 commit 932463c

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

src/adapters/clients.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ export function createStreamingAPIClient(
8383
{
8484
constructorParameters: [
8585
config.resolvePath("/api/v1/streaming"),
86-
[],
87-
{
88-
headers: config.getHeaders(),
89-
},
86+
config.getProtocols(),
9087
],
9188
implementation: props.implementation,
9289
maxAttempts: config.getMaxAttempts(),

src/adapters/config/web-socket-config.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("WebSocketConfigImpl", () => {
3131
);
3232
});
3333

34-
it("creates websocket header with token when supported", () => {
34+
it("creates websocket protocol with token when supported", () => {
3535
const config = new WebSocketConfigImpl(
3636
{
3737
streamingApiUrl: "wss://mastodon.social",
@@ -40,10 +40,10 @@ describe("WebSocketConfigImpl", () => {
4040
new SerializerNativeImpl(),
4141
);
4242

43-
expect(config.getHeaders()).toEqual({ Authorization: "Bearer token" });
43+
expect(config.getProtocols()).toEqual(["token"]);
4444
});
4545

46-
it("creates websocket header without token when not supported", () => {
46+
it("creates websocket protocol without token when not supported", () => {
4747
const config = new WebSocketConfigImpl(
4848
{
4949
streamingApiUrl: "wss://mastodon.social",
@@ -53,7 +53,7 @@ describe("WebSocketConfigImpl", () => {
5353
new SerializerNativeImpl(),
5454
);
5555

56-
expect(config.getHeaders()).toEqual({});
56+
expect(config.getProtocols()).toEqual([]);
5757
});
5858

5959
it("gets max attempts with retry true", () => {

src/adapters/config/web-socket-config.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,15 @@ export class WebSocketConfigImpl implements WebSocketConfig {
6262
private readonly serializer: Serializer,
6363
) {}
6464

65-
getHeaders(): Record<string, string> {
65+
getProtocols(protocols: readonly string[] = []): string[] {
6666
if (
6767
this.props.useInsecureAccessToken ||
6868
this.props.accessToken == undefined
6969
) {
70-
return {};
70+
return [...protocols];
7171
}
7272

73-
return {
74-
Authorization: `Bearer ${this.props.accessToken}`,
75-
};
73+
return [this.props.accessToken, ...protocols];
7674
}
7775

7876
resolvePath(path: string, params: Record<string, unknown> = {}): URL {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface WebSocketConfig {
22
getMaxAttempts(): number;
3-
getHeaders(): Record<string, string>;
3+
getProtocols(protocols?: readonly string[]): string[];
44
resolvePath(path: string, params?: Record<string, unknown>): URL;
55
}

0 commit comments

Comments
 (0)