Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/http2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,14 @@ jobs:
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

# Run tests on a matrix consisting of two dimensions:
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
# 2. release channel: dev
test:
needs: analyze
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [3.2, dev]
sdk: [3.7, stable, dev]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
Expand Down
4 changes: 3 additions & 1 deletion pkgs/http2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## 2.3.2-wip
## 3.0.0-wip

- Require Dart SDK `3.7.0`.

## 2.3.1

Expand Down
13 changes: 9 additions & 4 deletions pkgs/http2/example/display_headers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ void main(List<String> args) async {
Future<Socket> connect(Uri uri) async {
var useSSL = uri.scheme == 'https';
if (useSSL) {
var secureSocket = await SecureSocket.connect(uri.host, uri.port,
supportedProtocols: ['h2']);
var secureSocket = await SecureSocket.connect(
uri.host,
uri.port,
supportedProtocols: ['h2'],
);
if (secureSocket.selectedProtocol != 'h2') {
throw Exception('Failed to negogiate http/2 via alpn. Maybe server '
"doesn't support http/2.");
throw Exception(
'Failed to negogiate http/2 via alpn. Maybe server '
"doesn't support http/2.",
);
}
return secureSocket;
} else {
Expand Down
46 changes: 29 additions & 17 deletions pkgs/http2/lib/multiprotocol_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ class MultiProtocolHttpServer {
final _http2Connections = <http2.ServerTransportConnection>{};

MultiProtocolHttpServer._(this._serverSocket, this._settings) {
_http11Controller =
_ServerSocketController(_serverSocket.address, _serverSocket.port);
_http11Controller = _ServerSocketController(
_serverSocket.address,
_serverSocket.port,
);
_http11Server = HttpServer.listenOn(_http11Controller.stream);
}

Expand All @@ -45,8 +47,11 @@ class MultiProtocolHttpServer {
///
/// See also [startServing].
static Future<MultiProtocolHttpServer> bind(
Object? address, int port, SecurityContext context,
{http2.ServerSettings? settings}) async {
Object? address,
int port,
SecurityContext context, {
http2.ServerSettings? settings,
}) async {
context.setAlpnProtocols(['h2', 'h2-14', 'http/1.1'], true);
var secureServer = await SecureServerSocket.bind(address, port, context);
return MultiProtocolHttpServer._(secureServer, settings);
Expand All @@ -63,21 +68,27 @@ class MultiProtocolHttpServer {
///
/// It is expected that [callbackHttp11] and [callbackHttp2] will never throw
/// an exception (i.e. these must take care of error handling themselves).
void startServing(void Function(HttpRequest) callbackHttp11,
void Function(http2.ServerTransportStream) callbackHttp2,
{void Function(dynamic error, StackTrace)? onError}) {
void startServing(
void Function(HttpRequest) callbackHttp11,
void Function(http2.ServerTransportStream) callbackHttp2, {
void Function(dynamic error, StackTrace)? onError,
}) {
// 1. Start listening on the real [SecureServerSocket].
_serverSocket.listen((SecureSocket socket) {
var protocol = socket.selectedProtocol;
if (protocol == null || protocol == 'http/1.1') {
_http11Controller.addHttp11Socket(socket);
} else if (protocol == 'h2' || protocol == 'h2-14') {
var connection = http2.ServerTransportConnection.viaSocket(socket,
settings: _settings);
var connection = http2.ServerTransportConnection.viaSocket(
socket,
settings: _settings,
);
_http2Connections.add(connection);
connection.incomingStreams.listen(_http2Controller.add,
onError: onError,
onDone: () => _http2Connections.remove(connection));
connection.incomingStreams.listen(
_http2Controller.add,
onError: onError,
onDone: () => _http2Connections.remove(connection),
);
} else {
socket.destroy();
throw Exception('Unexpected negotiated ALPN protocol: $protocol.');
Expand All @@ -93,11 +104,12 @@ class MultiProtocolHttpServer {
/// Closes this [MultiProtocolHttpServer].
///
/// Completes once everything has been successfully shut down.
Future close({bool force = false}) =>
_serverSocket.close().whenComplete(() => Future.wait([
_http11Server.close(force: force),
for (var c in _http2Connections) force ? c.terminate() : c.finish()
]));
Future close({bool force = false}) => _serverSocket.close().whenComplete(
() => Future.wait([
_http11Server.close(force: force),
for (var c in _http2Connections) force ? c.terminate() : c.finish(),
]),
);
}

/// An internal helper class.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/http2/lib/src/artificial_server_socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'dart:io';
class ArtificialServerSocket extends StreamView<Socket>
implements ServerSocket {
ArtificialServerSocket(this.address, this.port, Stream<Socket> stream)
: super(stream);
: super(stream);

// ########################################################################
// These are the methods of [ServerSocket] in addition to [Stream<Socket>].
Expand Down
11 changes: 7 additions & 4 deletions pkgs/http2/lib/src/async_utils/async_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ class BufferedSink {
// Currently `_doneFuture` will just complete normally if the sink
// cancelled.
};
_doneFuture =
Future.wait([_controller.stream.pipe(dataSink), dataSink.done]);
_doneFuture = Future.wait([
_controller.stream.pipe(dataSink),
dataSink.done,
]);
}

/// The underlying sink.
Expand All @@ -88,7 +90,7 @@ class BufferedBytesWriter {
final BufferedSink _bufferedSink;

BufferedBytesWriter(StreamSink<List<int>> outgoing)
: _bufferedSink = BufferedSink(outgoing);
: _bufferedSink = BufferedSink(outgoing);

/// An indicator whether the underlying sink is buffering at the moment.
BufferIndicator get bufferIndicator => _bufferedSink.bufferIndicator;
Expand All @@ -100,7 +102,8 @@ class BufferedBytesWriter {
void add(List<int> data) {
if (_builder.length > 0) {
throw StateError(
'Cannot trigger an asynchronous write while there is buffered data.');
'Cannot trigger an asynchronous write while there is buffered data.',
);
}
_bufferedSink.sink.add(data);
}
Expand Down
Loading