change: Use solid-0.1 as protocol string.

See https://github.com/solid/solid-spec/pull/230
This commit is contained in:
Ruben Verborgh 2021-01-14 15:00:26 +01:00 committed by Joachim Van Herwegen
parent 748476afbb
commit 5bb7822dc7
3 changed files with 14 additions and 17 deletions

View File

@ -6,10 +6,10 @@ import { WebSocketHandler } from '../server/WebSocketHandler';
import { parseForwarded } from '../util/HeaderUtil';
import type { ResourceIdentifier } from './representation/ResourceIdentifier';
const VERSION = 'solid/0.1.0-alpha';
const VERSION = 'solid-0.1';
/**
* Implementation of Solid WebSockets API Spec solid/0.1.0-alpha
* Implementation of Solid WebSockets API Spec solid-0.1
* at https://github.com/solid/solid-spec/blob/master/api-websockets.md
*/
class WebSocketListener extends EventEmitter {
@ -30,7 +30,6 @@ class WebSocketListener extends EventEmitter {
public start({ headers, socket }: HttpRequest): void {
// Greet the client
this.sendMessage('protocol', VERSION);
this.sendMessage('warning', 'Unstandardized protocol version, proceed with care');
// Verify the WebSocket protocol version
const protocolHeader = headers['sec-websocket-protocol'];
@ -116,7 +115,7 @@ class WebSocketListener extends EventEmitter {
/**
* Provides live update functionality following
* the Solid WebSockets API Spec solid/0.1.0-alpha
* the Solid WebSockets API Spec solid-0.1
*/
export class UnsecureWebSocketsProtocol extends WebSocketHandler {
private readonly logger = getLoggerFor(this);

View File

@ -49,7 +49,7 @@ describe('A server with the Solid WebSockets API behind a proxy', (): void => {
const messages = new Array<string>();
beforeAll(async(): Promise<void> => {
client = new WebSocket(`ws://localhost:${port}`, [ 'solid/0.1.0-alpha' ], { headers });
client = new WebSocket(`ws://localhost:${port}`, [ 'solid-0.1' ], { headers });
client.on('message', (message: string): any => messages.push(message));
await new Promise((resolve): any => client.on('open', resolve));
});
@ -64,8 +64,7 @@ describe('A server with the Solid WebSockets API behind a proxy', (): void => {
it('sends the protocol version.', (): void => {
expect(messages).toEqual([
'protocol solid/0.1.0-alpha',
'warning Unstandardized protocol version, proceed with care',
'protocol solid-0.1',
]);
});

View File

@ -22,7 +22,7 @@ describe('An UnsecureWebSocketsProtocol', (): void => {
const upgradeRequest = {
headers: {
host: 'mypod.example',
'sec-websocket-protocol': 'solid/0.1.0-alpha, other/1.0.0',
'sec-websocket-protocol': 'solid-0.1, other/1.0.0',
},
socket: {
secure: true,
@ -36,9 +36,8 @@ describe('An UnsecureWebSocketsProtocol', (): void => {
});
it('sends a protocol message.', (): void => {
expect(webSocket.messages).toHaveLength(2);
expect(webSocket.messages.shift()).toBe('protocol solid/0.1.0-alpha');
expect(webSocket.messages.shift()).toBe('warning Unstandardized protocol version, proceed with care');
expect(webSocket.messages).toHaveLength(1);
expect(webSocket.messages.shift()).toBe('protocol solid-0.1');
});
it('warns when receiving an unexpected message.', (): void => {
@ -146,9 +145,9 @@ describe('An UnsecureWebSocketsProtocol', (): void => {
socket: {},
} as any as HttpRequest;
await protocol.handle({ webSocket, upgradeRequest } as any);
expect(webSocket.messages).toHaveLength(3);
expect(webSocket.messages).toHaveLength(2);
expect(webSocket.messages.pop())
.toBe('warning Missing Sec-WebSocket-Protocol header, expected value \'solid/0.1.0-alpha\'');
.toBe('warning Missing Sec-WebSocket-Protocol header, expected value \'solid-0.1\'');
expect(webSocket.close).toHaveBeenCalledTimes(0);
});
@ -161,8 +160,8 @@ describe('An UnsecureWebSocketsProtocol', (): void => {
socket: {},
} as any as HttpRequest;
await protocol.handle({ webSocket, upgradeRequest } as any);
expect(webSocket.messages).toHaveLength(3);
expect(webSocket.messages.pop()).toBe('error Client does not support protocol solid/0.1.0-alpha');
expect(webSocket.messages).toHaveLength(2);
expect(webSocket.messages.pop()).toBe('error Client does not support protocol solid-0.1');
expect(webSocket.close).toHaveBeenCalledTimes(1);
expect(webSocket.listenerCount('message')).toBe(0);
expect(webSocket.listenerCount('close')).toBe(0);
@ -174,13 +173,13 @@ describe('An UnsecureWebSocketsProtocol', (): void => {
const upgradeRequest = {
headers: {
forwarded: 'proto=https;host=other.example',
'sec-websocket-protocol': 'solid/0.1.0-alpha',
'sec-websocket-protocol': 'solid-0.1',
},
socket: {},
} as any as HttpRequest;
await protocol.handle({ webSocket, upgradeRequest } as any);
webSocket.emit('message', 'sub https://other.example/protocol/foo');
expect(webSocket.messages).toHaveLength(3);
expect(webSocket.messages).toHaveLength(2);
expect(webSocket.messages.pop()).toBe('ack https://other.example/protocol/foo');
});
});