mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Add trailing slashes to advertised WebSocket URL.
This commit is contained in:
parent
fc3942b372
commit
6b4088723d
@ -22,7 +22,7 @@ export class WebSocketAdvertiser extends HttpHandler {
|
|||||||
if (socketUrl.hostname !== hostname) {
|
if (socketUrl.hostname !== hostname) {
|
||||||
throw new Error(`Invalid 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<void> {
|
public async handle({ response }: { response: HttpResponse }): Promise<void> {
|
||||||
|
@ -33,7 +33,7 @@ describe('A server with the Solid WebSockets API', (): void => {
|
|||||||
|
|
||||||
it('sets the Updates-Via header.', async(): Promise<void> => {
|
it('sets the Updates-Via header.', async(): Promise<void> => {
|
||||||
const response = await fetch(baseUrl);
|
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<void> => {
|
it('exposes the Updates-Via header via CORS.', async(): Promise<void> => {
|
||||||
|
@ -6,28 +6,28 @@ describe('A WebSocketAdvertiser', (): void => {
|
|||||||
const writer = new WebSocketAdvertiser();
|
const writer = new WebSocketAdvertiser();
|
||||||
const response = createResponse();
|
const response = createResponse();
|
||||||
await writer.handle({ response } as any);
|
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<void> => {
|
it('writes an HTTP WebSocket with port 80.', async(): Promise<void> => {
|
||||||
const writer = new WebSocketAdvertiser({ hostname: 'test.example', port: 80, protocol: 'http' });
|
const writer = new WebSocketAdvertiser({ hostname: 'test.example', port: 80, protocol: 'http' });
|
||||||
const response = createResponse();
|
const response = createResponse();
|
||||||
await writer.handle({ response } as any);
|
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<void> => {
|
it('writes an HTTP WebSocket with port 3000.', async(): Promise<void> => {
|
||||||
const writer = new WebSocketAdvertiser({ hostname: 'test.example', port: 3000, protocol: 'http' });
|
const writer = new WebSocketAdvertiser({ hostname: 'test.example', port: 3000, protocol: 'http' });
|
||||||
const response = createResponse();
|
const response = createResponse();
|
||||||
await writer.handle({ response } as any);
|
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<void> => {
|
it('writes an HTTPS WebSocket with port 443.', async(): Promise<void> => {
|
||||||
const writer = new WebSocketAdvertiser({ hostname: 'test.example', port: 443, protocol: 'https' });
|
const writer = new WebSocketAdvertiser({ hostname: 'test.example', port: 443, protocol: 'https' });
|
||||||
const response = createResponse();
|
const response = createResponse();
|
||||||
await writer.handle({ response } as any);
|
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 => {
|
it('rejects an invalid hostname.', (): void => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user