@@ -31,8 +31,10 @@ class MultiProtocolHttpServer {
31
31
final _http2Connections = < http2.ServerTransportConnection > {};
32
32
33
33
MultiProtocolHttpServer ._(this ._serverSocket, this ._settings) {
34
- _http11Controller =
35
- _ServerSocketController (_serverSocket.address, _serverSocket.port);
34
+ _http11Controller = _ServerSocketController (
35
+ _serverSocket.address,
36
+ _serverSocket.port,
37
+ );
36
38
_http11Server = HttpServer .listenOn (_http11Controller.stream);
37
39
}
38
40
@@ -45,8 +47,11 @@ class MultiProtocolHttpServer {
45
47
///
46
48
/// See also [startServing] .
47
49
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 {
50
55
context.setAlpnProtocols (['h2' , 'h2-14' , 'http/1.1' ], true );
51
56
var secureServer = await SecureServerSocket .bind (address, port, context);
52
57
return MultiProtocolHttpServer ._(secureServer, settings);
@@ -63,21 +68,27 @@ class MultiProtocolHttpServer {
63
68
///
64
69
/// It is expected that [callbackHttp11] and [callbackHttp2] will never throw
65
70
/// 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
+ }) {
69
76
// 1. Start listening on the real [SecureServerSocket].
70
77
_serverSocket.listen ((SecureSocket socket) {
71
78
var protocol = socket.selectedProtocol;
72
79
if (protocol == null || protocol == 'http/1.1' ) {
73
80
_http11Controller.addHttp11Socket (socket);
74
81
} 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
+ );
77
86
_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
+ );
81
92
} else {
82
93
socket.destroy ();
83
94
throw Exception ('Unexpected negotiated ALPN protocol: $protocol .' );
@@ -93,11 +104,12 @@ class MultiProtocolHttpServer {
93
104
/// Closes this [MultiProtocolHttpServer] .
94
105
///
95
106
/// 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
+ );
101
113
}
102
114
103
115
/// An internal helper class.
0 commit comments