Make package strong, also add analysis options file
diff --git a/analysis_options.yaml b/analysis_options.yaml
new file mode 100644
index 0000000..a10d4c5
--- /dev/null
+++ b/analysis_options.yaml
@@ -0,0 +1,2 @@
+analyzer:
+ strong-mode: true
diff --git a/lib/src/web_socket_handler.dart b/lib/src/web_socket_handler.dart
index 266a9dc..4c405f0 100644
--- a/lib/src/web_socket_handler.dart
+++ b/lib/src/web_socket_handler.dart
@@ -5,7 +5,6 @@
import 'dart:convert';
import 'package:shelf/shelf.dart';
-import 'package:stream_channel/stream_channel.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
/// A class that exposes a handler for upgrading WebSocket requests.
@@ -27,8 +26,8 @@
var connection = request.headers['Connection'];
if (connection == null) return _notFound();
- var tokens = connection.toLowerCase().split(',')
- .map((token) => token.trim());
+ var tokens =
+ connection.toLowerCase().split(',').map((token) => token.trim());
if (!tokens.contains('upgrade')) return _notFound();
var upgrade = request.headers['Upgrade'];
@@ -59,18 +58,18 @@
// unexpected origins, we ensure that malicious JavaScript is unable to fake
// a WebSocket handshake.
var origin = request.headers['Origin'];
- if (origin != null && _allowedOrigins != null &&
+ if (origin != null &&
+ _allowedOrigins != null &&
!_allowedOrigins.contains(origin.toLowerCase())) {
return _forbidden('invalid origin "$origin".');
}
var protocol = _chooseProtocol(request);
request.hijack((untypedChannel) {
- var channel = (untypedChannel as StreamChannel).cast<List<int>>();
+ var channel = untypedChannel.cast<List<int>>();
var sink = UTF8.encoder.startChunkedConversion(channel.sink);
- sink.add(
- "HTTP/1.1 101 Switching Protocols\r\n"
+ sink.add("HTTP/1.1 101 Switching Protocols\r\n"
"Upgrade: websocket\r\n"
"Connection: Upgrade\r\n"
"Sec-WebSocket-Accept: ${WebSocketChannel.signKey(key)}\r\n");
@@ -100,20 +99,20 @@
}
/// Returns a 404 Not Found response.
- Response _notFound() => _htmlResponse(404, "404 Not Found",
- "Only WebSocket connections are supported.");
+ Response _notFound() => _htmlResponse(
+ 404, "404 Not Found", "Only WebSocket connections are supported.");
/// Returns a 400 Bad Request response.
///
/// [message] will be HTML-escaped before being included in the response body.
- Response _badRequest(String message) => _htmlResponse(400, "400 Bad Request",
- "Invalid WebSocket upgrade request: $message");
+ Response _badRequest(String message) => _htmlResponse(
+ 400, "400 Bad Request", "Invalid WebSocket upgrade request: $message");
/// Returns a 403 Forbidden response.
///
/// [message] will be HTML-escaped before being included in the response body.
- Response _forbidden(String message) => _htmlResponse(403, "403 Forbidden",
- "WebSocket upgrade refused: $message");
+ Response _forbidden(String message) => _htmlResponse(
+ 403, "403 Forbidden", "WebSocket upgrade refused: $message");
/// Creates an HTTP response with the given [statusCode] and an HTML body with
/// [title] and [message].