From 20bd1737c4cf9c20e78cb1222f0c9b984dcab11a Mon Sep 17 00:00:00 2001 From: minoic Date: Mon, 16 Dec 2024 09:15:03 -0800 Subject: [PATCH] update: upgrade web package to v1.1.0 --- lib/src/client/transport/xhr_transport.dart | 33 +++++++-------------- pubspec.yaml | 2 +- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/lib/src/client/transport/xhr_transport.dart b/lib/src/client/transport/xhr_transport.dart index 1de0eb78..e41a7f39 100644 --- a/lib/src/client/transport/xhr_transport.dart +++ b/lib/src/client/transport/xhr_transport.dart @@ -59,12 +59,14 @@ class XhrTransportStream implements GrpcTransportStream { if (_incomingProcessor.isClosed) { return; } - // TODO: dart-lang/web#285 use 'if' for now - if (_request.readyState == XMLHttpRequest.HEADERS_RECEIVED) { - _onHeadersReceived(); - } else if (_request.readyState == XMLHttpRequest.DONE) { - _onRequestDone(); - _close(); + switch (_request.readyState) { + case XMLHttpRequest.HEADERS_RECEIVED: + _onHeadersReceived(); + break; + case XMLHttpRequest.DONE: + _onRequestDone(); + _close(); + break; } }); @@ -99,7 +101,7 @@ class XhrTransportStream implements GrpcTransportStream { bool _validateResponseState() { try { validateHttpStatusAndContentType( - _request.status, _parseHeaders(_request.getAllResponseHeaders()), + _request.status, _request.responseHeaders, rawResponse: _request.responseText); return true; } catch (e, st) { @@ -113,8 +115,7 @@ class XhrTransportStream implements GrpcTransportStream { if (!_validateResponseState()) { return; } - _incomingMessages - .add(GrpcMetadata(_parseHeaders(_request.getAllResponseHeaders()))); + _incomingMessages.add(GrpcMetadata(_request.responseHeaders)); } void _onRequestDone() { @@ -138,20 +139,6 @@ class XhrTransportStream implements GrpcTransportStream { _onDone(this); } - Map _parseHeaders(String rawHeaders) { - final headers = {}; - final lines = rawHeaders.split('\r\n'); - for (var line in lines) { - final index = line.indexOf(': '); - if (index != -1) { - final key = line.substring(0, index); - final value = line.substring(index + 2); - headers[key] = value; - } - } - return headers; - } - @override Future terminate() async { _close(); diff --git a/pubspec.yaml b/pubspec.yaml index cde369f2..02b3047a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ dependencies: http2: ^2.2.0 protobuf: '>=2.0.0 <4.0.0' clock: ^1.1.1 - web: ^1.0.0 + web: ^1.1.0 dev_dependencies: build_runner: ^2.0.0