From 6b4088723dcafb0756a34e1ff8b41f86014b8fb4 Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Mon, 30 Nov 2020 00:36:02 +0100 Subject: [PATCH] fix: Add trailing slashes to advertised WebSocket URL. --- src/server/middleware/WebSocketAdvertiser.ts | 2 +- test/integration/WebSocketsProtocol.test.ts | 2 +- test/unit/server/middleware/WebSocketAdvertiser.test.ts | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/server/middleware/WebSocketAdvertiser.ts b/src/server/middleware/WebSocketAdvertiser.ts index fdd083454..bb121175c 100644 --- a/src/server/middleware/WebSocketAdvertiser.ts +++ b/src/server/middleware/WebSocketAdvertiser.ts @@ -22,7 +22,7 @@ export class WebSocketAdvertiser extends HttpHandler { if (socketUrl.hostname !== hostname) { throw new Error(`Invalid hostname: ${hostname}`); } - this.socketUrl = socketUrl.href.slice(0, -1); + this.socketUrl = socketUrl.href; } public async handle({ response }: { response: HttpResponse }): Promise { diff --git a/test/integration/WebSocketsProtocol.test.ts b/test/integration/WebSocketsProtocol.test.ts index a976aca4f..d3d64ef1b 100644 --- a/test/integration/WebSocketsProtocol.test.ts +++ b/test/integration/WebSocketsProtocol.test.ts @@ -33,7 +33,7 @@ describe('A server with the Solid WebSockets API', (): void => { it('sets the Updates-Via header.', async(): Promise => { const response = await fetch(baseUrl); - expect(response.headers.get('Updates-Via')).toBe(`ws://localhost:${port}`); + expect(response.headers.get('Updates-Via')).toBe(`ws://localhost:${port}/`); }); it('exposes the Updates-Via header via CORS.', async(): Promise => { diff --git a/test/unit/server/middleware/WebSocketAdvertiser.test.ts b/test/unit/server/middleware/WebSocketAdvertiser.test.ts index d4c8d7a56..5421c5346 100644 --- a/test/unit/server/middleware/WebSocketAdvertiser.test.ts +++ b/test/unit/server/middleware/WebSocketAdvertiser.test.ts @@ -6,28 +6,28 @@ describe('A WebSocketAdvertiser', (): void => { const writer = new WebSocketAdvertiser(); const response = createResponse(); await writer.handle({ response } as any); - expect(response.getHeaders()).toEqual({ 'updates-via': 'ws://localhost' }); + expect(response.getHeaders()).toEqual({ 'updates-via': 'ws://localhost/' }); }); it('writes an HTTP WebSocket with port 80.', async(): Promise => { const writer = new WebSocketAdvertiser({ hostname: 'test.example', port: 80, protocol: 'http' }); const response = createResponse(); await writer.handle({ response } as any); - expect(response.getHeaders()).toEqual({ 'updates-via': 'ws://test.example' }); + expect(response.getHeaders()).toEqual({ 'updates-via': 'ws://test.example/' }); }); it('writes an HTTP WebSocket with port 3000.', async(): Promise => { const writer = new WebSocketAdvertiser({ hostname: 'test.example', port: 3000, protocol: 'http' }); const response = createResponse(); await writer.handle({ response } as any); - expect(response.getHeaders()).toEqual({ 'updates-via': 'ws://test.example:3000' }); + expect(response.getHeaders()).toEqual({ 'updates-via': 'ws://test.example:3000/' }); }); it('writes an HTTPS WebSocket with port 443.', async(): Promise => { const writer = new WebSocketAdvertiser({ hostname: 'test.example', port: 443, protocol: 'https' }); const response = createResponse(); await writer.handle({ response } as any); - expect(response.getHeaders()).toEqual({ 'updates-via': 'wss://test.example' }); + expect(response.getHeaders()).toEqual({ 'updates-via': 'wss://test.example/' }); }); it('rejects an invalid hostname.', (): void => {