@@ -31,8 +31,10 @@ class MultiProtocolHttpServer {
3131 final _http2Connections = < http2.ServerTransportConnection > {};
3232
3333 MultiProtocolHttpServer ._(this ._serverSocket, this ._settings) {
34- _http11Controller =
35- _ServerSocketController (_serverSocket.address, _serverSocket.port);
34+ _http11Controller = _ServerSocketController (
35+ _serverSocket.address,
36+ _serverSocket.port,
37+ );
3638 _http11Server = HttpServer .listenOn (_http11Controller.stream);
3739 }
3840
@@ -45,8 +47,11 @@ class MultiProtocolHttpServer {
4547 ///
4648 /// See also [startServing] .
4749 static Future <MultiProtocolHttpServer > bind (
48- Object ? address, int port, SecurityContext context,
49- {http2.ServerSettings ? settings}) async {
50+ Object ? address,
51+ int port,
52+ SecurityContext context, {
53+ http2.ServerSettings ? settings,
54+ }) async {
5055 context.setAlpnProtocols (['h2' , 'h2-14' , 'http/1.1' ], true );
5156 var secureServer = await SecureServerSocket .bind (address, port, context);
5257 return MultiProtocolHttpServer ._(secureServer, settings);
@@ -63,21 +68,27 @@ class MultiProtocolHttpServer {
6368 ///
6469 /// It is expected that [callbackHttp11] and [callbackHttp2] will never throw
6570 /// an exception (i.e. these must take care of error handling themselves).
66- void startServing (void Function (HttpRequest ) callbackHttp11,
67- void Function (http2.ServerTransportStream ) callbackHttp2,
68- {void Function (dynamic error, StackTrace )? onError}) {
71+ void startServing (
72+ void Function (HttpRequest ) callbackHttp11,
73+ void Function (http2.ServerTransportStream ) callbackHttp2, {
74+ void Function (dynamic error, StackTrace )? onError,
75+ }) {
6976 // 1. Start listening on the real [SecureServerSocket].
7077 _serverSocket.listen ((SecureSocket socket) {
7178 var protocol = socket.selectedProtocol;
7279 if (protocol == null || protocol == 'http/1.1' ) {
7380 _http11Controller.addHttp11Socket (socket);
7481 } else if (protocol == 'h2' || protocol == 'h2-14' ) {
75- var connection = http2.ServerTransportConnection .viaSocket (socket,
76- settings: _settings);
82+ var connection = http2.ServerTransportConnection .viaSocket (
83+ socket,
84+ settings: _settings,
85+ );
7786 _http2Connections.add (connection);
78- connection.incomingStreams.listen (_http2Controller.add,
79- onError: onError,
80- onDone: () => _http2Connections.remove (connection));
87+ connection.incomingStreams.listen (
88+ _http2Controller.add,
89+ onError: onError,
90+ onDone: () => _http2Connections.remove (connection),
91+ );
8192 } else {
8293 socket.destroy ();
8394 throw Exception ('Unexpected negotiated ALPN protocol: $protocol .' );
@@ -93,11 +104,12 @@ class MultiProtocolHttpServer {
93104 /// Closes this [MultiProtocolHttpServer] .
94105 ///
95106 /// Completes once everything has been successfully shut down.
96- Future close ({bool force = false }) =>
97- _serverSocket.close ().whenComplete (() => Future .wait ([
98- _http11Server.close (force: force),
99- for (var c in _http2Connections) force ? c.terminate () : c.finish ()
100- ]));
107+ Future close ({bool force = false }) => _serverSocket.close ().whenComplete (
108+ () => Future .wait ([
109+ _http11Server.close (force: force),
110+ for (var c in _http2Connections) force ? c.terminate () : c.finish (),
111+ ]),
112+ );
101113}
102114
103115/// An internal helper class.
0 commit comments