diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 2f58e625..81c03343 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - sdk: [3.2.0, dev] + sdk: [3.4.0, dev] steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 @@ -60,7 +60,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - sdk: [3.2.0, dev] + sdk: [3.4.0, dev] platform: [vm, chrome] exclude: # We only run Chrome tests on Linux. No need to run them diff --git a/lib/src/client/transport/xhr_transport.dart b/lib/src/client/transport/xhr_transport.dart index d3293e8e..69cb78a8 100644 --- a/lib/src/client/transport/xhr_transport.dart +++ b/lib/src/client/transport/xhr_transport.dart @@ -46,12 +46,14 @@ class XhrTransportStream implements GrpcTransportStream { @override StreamSink> get outgoingMessages => _outgoingMessages.sink; - XhrTransportStream(this._request, {required ErrorHandler onError, required onDone}) + XhrTransportStream(this._request, + {required ErrorHandler onError, required onDone}) : _onError = onError, _onDone = onDone { - _outgoingMessages.stream - .map(frame) - .listen((data) => _request.send(Int8List.fromList(data).toJS), cancelOnError: true, onError: _onError); + _outgoingMessages.stream.map(frame).listen( + (data) => _request.send(Int8List.fromList(data).toJS), + cancelOnError: true, + onError: _onError); _request.onReadyStateChange.listen((_) { if (_incomingProcessor.isClosed) { @@ -72,7 +74,8 @@ class XhrTransportStream implements GrpcTransportStream { if (_incomingProcessor.isClosed) { return; } - _onError(GrpcError.unavailable('XhrConnection connection-error'), StackTrace.current); + _onError(GrpcError.unavailable('XhrConnection connection-error'), + StackTrace.current); terminate(); }); @@ -81,7 +84,9 @@ class XhrTransportStream implements GrpcTransportStream { return; } final responseText = _request.responseText; - final bytes = Uint8List.fromList(responseText.substring(_requestBytesRead).codeUnits).buffer; + final bytes = Uint8List.fromList( + responseText.substring(_requestBytesRead).codeUnits) + .buffer; _requestBytesRead = responseText.length; _incomingProcessor.add(bytes); }); @@ -89,12 +94,14 @@ class XhrTransportStream implements GrpcTransportStream { _incomingProcessor.stream .transform(GrpcWebDecoder()) .transform(grpcDecompressor()) - .listen(_incomingMessages.add, onError: _onError, onDone: _incomingMessages.close); + .listen(_incomingMessages.add, + onError: _onError, onDone: _incomingMessages.close); } bool _validateResponseState() { try { - validateHttpStatusAndContentType(_request.status, _parseHeaders(_request.getAllResponseHeaders()), + validateHttpStatusAndContentType( + _request.status, _parseHeaders(_request.getAllResponseHeaders()), rawResponse: _request.responseText); return true; } catch (e, st) { @@ -108,7 +115,8 @@ class XhrTransportStream implements GrpcTransportStream { if (!_validateResponseState()) { return; } - _incomingMessages.add(GrpcMetadata(_parseHeaders(_request.getAllResponseHeaders()))); + _incomingMessages + .add(GrpcMetadata(_parseHeaders(_request.getAllResponseHeaders()))); } void _onRequestDone() { @@ -116,7 +124,11 @@ class XhrTransportStream implements GrpcTransportStream { return; } if (_request.status != 200) { - _onError(GrpcError.unavailable('Request failed with status: ${_request.status}', null, _request.responseText), + _onError( + GrpcError.unavailable( + 'Request failed with status: ${_request.status}', + null, + _request.responseText), StackTrace.current); return; } @@ -162,7 +174,8 @@ class XhrClientConnection implements ClientConnection { @override String get scheme => uri.scheme; - void _initializeRequest(XMLHttpRequest request, Map metadata) { + void _initializeRequest( + XMLHttpRequest request, Map metadata) { metadata.forEach((key, value) { request.setRequestHeader(key, value); }); @@ -175,7 +188,8 @@ class XhrClientConnection implements ClientConnection { XMLHttpRequest createHttpRequest() => XMLHttpRequest(); @override - GrpcTransportStream makeRequest(String path, Duration? timeout, Map metadata, ErrorHandler onError, + GrpcTransportStream makeRequest(String path, Duration? timeout, + Map metadata, ErrorHandler onError, {CallOptions? callOptions}) { // gRPC-web headers. if (_getContentTypeHeader(metadata) == null) { @@ -185,7 +199,8 @@ class XhrClientConnection implements ClientConnection { } var requestUri = uri.resolve(path); - if (callOptions is WebCallOptions && callOptions.bypassCorsPreflight == true) { + if (callOptions is WebCallOptions && + callOptions.bypassCorsPreflight == true) { requestUri = cors.moveHttpHeadersToQueryParam(metadata, requestUri); } @@ -197,7 +212,8 @@ class XhrClientConnection implements ClientConnection { // Must set headers after calling open(). _initializeRequest(request, metadata); - final transportStream = XhrTransportStream(request, onError: onError, onDone: _removeStream); + final transportStream = + XhrTransportStream(request, onError: onError, onDone: _removeStream); _requests.add(transportStream); return transportStream; }