commit | bf8554ff80089bf88de262503f85dc3610d79ecf | [log] [tgz] |
---|---|---|
author | Nate Bosch <nbosch@google.com> | Wed Jan 27 08:38:42 2021 -0800 |
committer | GitHub <noreply@github.com> | Wed Jan 27 08:38:42 2021 -0800 |
tree | 3c283526ef321a0efd6f3698a4920f20a3f511cb | |
parent | fe1ce13114bb7318e140587f21ebec4cbb127ef3 [diff] |
Ignore protocol header if handler did not specify allowed protocols (#28) Closes #27 The spec says "if the server does not agree to any of the client's requested subprotocols, the only acceptable value is null". The mozilla docs for implementing a web socket server say "The client may close the connection if it doesn't get the subprotocol it wants." From this I take it that the safest thing to do is to ignore the protocols. A server which wants to be more careful can handle the `null` protocol in whatever way makes sense. - Add a null check before searching for overlap in protocol. - Remove the explicit check for `protocols` with 2 argument callback. - Rename `protocols` to `requestProtocols`. - Add tests demonstrating new behavior, remove test for ArgumentError.
shelf_web_socket
is a Shelf handler for establishing WebSocket connections. It exposes a single function, webSocketHandler, which calls an onConnection
callback with a WebSocketChannel object for every connection that's established.
import 'package:shelf/shelf_io.dart' as shelf_io; import 'package:shelf_web_socket/shelf_web_socket.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; void main() { var handler = webSocketHandler((webSocket) { webSocket.stream.listen((message) { webSocket.sink.add("echo $message"); }); }); shelf_io.serve(handler, 'localhost', 8080).then((server) { print('Serving at ws://${server.address.host}:${server.port}'); }); }