[http] use pkg:web, require Dart 3.2 (#1049)
Now supports wasm
diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml
index 35af167..b800c00 100644
--- a/.github/workflows/dart.yml
+++ b/.github/workflows/dart.yml
@@ -1,4 +1,4 @@
-# Created with package:mono_repo v6.6.0
+# Created with package:mono_repo v6.6.1
name: Dart CI
on:
push:
@@ -36,7 +36,7 @@
name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- name: mono_repo self validate
- run: dart pub global activate mono_repo 6.6.0
+ run: dart pub global activate mono_repo 6.6.1
- name: mono_repo self validate
run: dart pub global run mono_repo generate --validate
job_002:
@@ -70,16 +70,16 @@
if: "always() && steps.pkgs_http_client_conformance_tests_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/http_client_conformance_tests
job_003:
- name: "analyze_and_format; linux; Dart 3.0.0; PKGS: pkgs/http, pkgs/http_profile; `dart analyze --fatal-infos`"
+ name: "analyze_and_format; linux; Dart 3.0.0; PKG: pkgs/http_profile; `dart analyze --fatal-infos`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: "~/.pub-cache/hosted"
- key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http-pkgs/http_profile;commands:analyze_1"
+ key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http_profile;commands:analyze_1"
restore-keys: |
- os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http-pkgs/http_profile
+ os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http_profile
os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
@@ -90,6 +90,36 @@
- id: checkout
name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
+ - id: pkgs_http_profile_pub_upgrade
+ name: pkgs/http_profile; dart pub upgrade
+ run: dart pub upgrade
+ if: "always() && steps.checkout.conclusion == 'success'"
+ working-directory: pkgs/http_profile
+ - name: "pkgs/http_profile; dart analyze --fatal-infos"
+ run: dart analyze --fatal-infos
+ if: "always() && steps.pkgs_http_profile_pub_upgrade.conclusion == 'success'"
+ working-directory: pkgs/http_profile
+ job_004:
+ name: "analyze_and_format; linux; Dart 3.2.0; PKG: pkgs/http; `dart analyze --fatal-infos`"
+ runs-on: ubuntu-latest
+ steps:
+ - name: Cache Pub hosted dependencies
+ uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
+ with:
+ path: "~/.pub-cache/hosted"
+ key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0;packages:pkgs/http;commands:analyze_1"
+ restore-keys: |
+ os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0;packages:pkgs/http
+ os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0
+ os:ubuntu-latest;pub-cache-hosted
+ os:ubuntu-latest
+ - name: Setup Dart SDK
+ uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
+ with:
+ sdk: "3.2.0"
+ - id: checkout
+ name: Checkout repository
+ uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- id: pkgs_http_pub_upgrade
name: pkgs/http; dart pub upgrade
run: dart pub upgrade
@@ -99,16 +129,7 @@
run: dart analyze --fatal-infos
if: "always() && steps.pkgs_http_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/http
- - id: pkgs_http_profile_pub_upgrade
- name: pkgs/http_profile; dart pub upgrade
- run: dart pub upgrade
- if: "always() && steps.checkout.conclusion == 'success'"
- working-directory: pkgs/http_profile
- - name: "pkgs/http_profile; dart analyze --fatal-infos"
- run: dart analyze --fatal-infos
- if: "always() && steps.pkgs_http_profile_pub_upgrade.conclusion == 'success'"
- working-directory: pkgs/http_profile
- job_004:
+ job_005:
name: "analyze_and_format; linux; Dart dev; PKGS: pkgs/http, pkgs/http_client_conformance_tests, pkgs/http_profile; `dart analyze --fatal-infos`"
runs-on: ubuntu-latest
steps:
@@ -156,7 +177,7 @@
run: dart analyze --fatal-infos
if: "always() && steps.pkgs_http_profile_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/http_profile
- job_005:
+ job_006:
name: "analyze_and_format; linux; Dart dev; PKGS: pkgs/http, pkgs/http_client_conformance_tests, pkgs/http_profile; `dart format --output=none --set-exit-if-changed .`"
runs-on: ubuntu-latest
steps:
@@ -204,7 +225,7 @@
run: "dart format --output=none --set-exit-if-changed ."
if: "always() && steps.pkgs_http_profile_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/http_profile
- job_006:
+ job_007:
name: "analyze_and_format; linux; Flutter stable; PKG: pkgs/flutter_http_example; `dart format --output=none --set-exit-if-changed .`"
runs-on: ubuntu-latest
steps:
@@ -234,7 +255,7 @@
run: "dart format --output=none --set-exit-if-changed ."
if: "always() && steps.pkgs_flutter_http_example_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/flutter_http_example
- job_007:
+ job_008:
name: "analyze_and_format; linux; Flutter stable; PKG: pkgs/flutter_http_example; `flutter analyze --fatal-infos`"
runs-on: ubuntu-latest
steps:
@@ -264,17 +285,17 @@
run: flutter analyze --fatal-infos
if: "always() && steps.pkgs_flutter_http_example_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/flutter_http_example
- job_008:
- name: "unit_test; linux; Dart 3.0.0; PKG: pkgs/http; `dart run --define=no_default_http_client=true test/no_default_http_client_test.dart`"
+ job_009:
+ name: "unit_test; linux; Dart 3.0.0; PKG: pkgs/http_profile; `dart test --platform vm`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: "~/.pub-cache/hosted"
- key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http;commands:command_1"
+ key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http_profile;commands:test_2"
restore-keys: |
- os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http
+ os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http_profile
os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
@@ -285,6 +306,45 @@
- id: checkout
name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
+ - id: pkgs_http_profile_pub_upgrade
+ name: pkgs/http_profile; dart pub upgrade
+ run: dart pub upgrade
+ if: "always() && steps.checkout.conclusion == 'success'"
+ working-directory: pkgs/http_profile
+ - name: "pkgs/http_profile; dart test --platform vm"
+ run: dart test --platform vm
+ if: "always() && steps.pkgs_http_profile_pub_upgrade.conclusion == 'success'"
+ working-directory: pkgs/http_profile
+ needs:
+ - job_001
+ - job_002
+ - job_003
+ - job_004
+ - job_005
+ - job_006
+ - job_007
+ - job_008
+ job_010:
+ name: "unit_test; linux; Dart 3.2.0; PKG: pkgs/http; `dart run --define=no_default_http_client=true test/no_default_http_client_test.dart`"
+ runs-on: ubuntu-latest
+ steps:
+ - name: Cache Pub hosted dependencies
+ uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
+ with:
+ path: "~/.pub-cache/hosted"
+ key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0;packages:pkgs/http;commands:command_1"
+ restore-keys: |
+ os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0;packages:pkgs/http
+ os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0
+ os:ubuntu-latest;pub-cache-hosted
+ os:ubuntu-latest
+ - name: Setup Dart SDK
+ uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
+ with:
+ sdk: "3.2.0"
+ - id: checkout
+ name: Checkout repository
+ uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- id: pkgs_http_pub_upgrade
name: pkgs/http; dart pub upgrade
run: dart pub upgrade
@@ -302,24 +362,25 @@
- job_005
- job_006
- job_007
- job_009:
- name: "unit_test; linux; Dart 3.0.0; PKG: pkgs/http; `dart test --platform chrome`"
+ - job_008
+ job_011:
+ name: "unit_test; linux; Dart 3.2.0; PKG: pkgs/http; `dart test --platform chrome`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: "~/.pub-cache/hosted"
- key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http;commands:test_3"
+ key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0;packages:pkgs/http;commands:test_3"
restore-keys: |
- os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http
- os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0
+ os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0;packages:pkgs/http
+ os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
- sdk: "3.0.0"
+ sdk: "3.2.0"
- id: checkout
name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
@@ -340,24 +401,25 @@
- job_005
- job_006
- job_007
- job_010:
- name: "unit_test; linux; Dart 3.0.0; PKGS: pkgs/http, pkgs/http_profile; `dart test --platform vm`"
+ - job_008
+ job_012:
+ name: "unit_test; linux; Dart 3.2.0; PKG: pkgs/http; `dart test --platform vm`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: "~/.pub-cache/hosted"
- key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http-pkgs/http_profile;commands:test_2"
+ key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0;packages:pkgs/http;commands:test_2"
restore-keys: |
- os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http-pkgs/http_profile
- os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0
+ os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0;packages:pkgs/http
+ os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
- sdk: "3.0.0"
+ sdk: "3.2.0"
- id: checkout
name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
@@ -370,15 +432,6 @@
run: dart test --platform vm
if: "always() && steps.pkgs_http_pub_upgrade.conclusion == 'success'"
working-directory: pkgs/http
- - id: pkgs_http_profile_pub_upgrade
- name: pkgs/http_profile; dart pub upgrade
- run: dart pub upgrade
- if: "always() && steps.checkout.conclusion == 'success'"
- working-directory: pkgs/http_profile
- - name: "pkgs/http_profile; dart test --platform vm"
- run: dart test --platform vm
- if: "always() && steps.pkgs_http_profile_pub_upgrade.conclusion == 'success'"
- working-directory: pkgs/http_profile
needs:
- job_001
- job_002
@@ -387,7 +440,8 @@
- job_005
- job_006
- job_007
- job_011:
+ - job_008
+ job_013:
name: "unit_test; linux; Dart dev; PKG: pkgs/http; `dart run --define=no_default_http_client=true test/no_default_http_client_test.dart`"
runs-on: ubuntu-latest
steps:
@@ -425,7 +479,8 @@
- job_005
- job_006
- job_007
- job_012:
+ - job_008
+ job_014:
name: "unit_test; linux; Dart dev; PKG: pkgs/http; `dart test --platform chrome`"
runs-on: ubuntu-latest
steps:
@@ -463,7 +518,8 @@
- job_005
- job_006
- job_007
- job_013:
+ - job_008
+ job_015:
name: "unit_test; linux; Dart dev; PKGS: pkgs/http, pkgs/http_profile; `dart test --platform vm`"
runs-on: ubuntu-latest
steps:
@@ -510,7 +566,8 @@
- job_005
- job_006
- job_007
- job_014:
+ - job_008
+ job_016:
name: "unit_test; linux; Flutter stable; PKG: pkgs/flutter_http_example; `flutter test --platform chrome`"
runs-on: ubuntu-latest
steps:
@@ -548,7 +605,8 @@
- job_005
- job_006
- job_007
- job_015:
+ - job_008
+ job_017:
name: "unit_test; linux; Flutter stable; PKG: pkgs/flutter_http_example; `flutter test`"
runs-on: ubuntu-latest
steps:
@@ -586,7 +644,8 @@
- job_005
- job_006
- job_007
- job_016:
+ - job_008
+ job_018:
name: "unit_test; macos; Flutter stable; PKG: pkgs/flutter_http_example; `flutter test`"
runs-on: macos-latest
steps:
@@ -624,7 +683,8 @@
- job_005
- job_006
- job_007
- job_017:
+ - job_008
+ job_019:
name: "unit_test; windows; Flutter stable; PKG: pkgs/flutter_http_example; `flutter test`"
runs-on: windows-latest
steps:
@@ -652,3 +712,4 @@
- job_005
- job_006
- job_007
+ - job_008
diff --git a/pkgs/http/CHANGELOG.md b/pkgs/http/CHANGELOG.md
index 6d39b10..1fb4c22 100644
--- a/pkgs/http/CHANGELOG.md
+++ b/pkgs/http/CHANGELOG.md
@@ -3,6 +3,8 @@
* `BrowserClient` throws `ClientException` when the `'Content-Length'` header
is invalid.
* `IOClient` trims trailing whitespace on header values.
+* Require Dart 3.2
+* Browser: support Wasm by using `package:web`.
## 1.1.0
diff --git a/pkgs/http/lib/src/browser_client.dart b/pkgs/http/lib/src/browser_client.dart
index 9345be0..84f79e0 100644
--- a/pkgs/http/lib/src/browser_client.dart
+++ b/pkgs/http/lib/src/browser_client.dart
@@ -3,9 +3,11 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
-import 'dart:html';
+import 'dart:js_interop';
import 'dart:typed_data';
+import 'package:web/helpers.dart';
+
import 'base_client.dart';
import 'base_request.dart';
import 'byte_stream.dart';
@@ -37,7 +39,7 @@
/// The currently active XHRs.
///
/// These are aborted if the client is closed.
- final _xhrs = <HttpRequest>{};
+ final _xhrs = <XMLHttpRequest>{};
/// Whether to send credentials such as cookies or authorization headers for
/// cross-site requests.
@@ -55,19 +57,22 @@
'HTTP request failed. Client is already closed.', request.url);
}
var bytes = await request.finalize().toBytes();
- var xhr = HttpRequest();
+ var xhr = XMLHttpRequest();
_xhrs.add(xhr);
xhr
- ..open(request.method, '${request.url}', async: true)
+ ..open(request.method, '${request.url}', true)
..responseType = 'arraybuffer'
..withCredentials = withCredentials;
- request.headers.forEach(xhr.setRequestHeader);
+ for (var header in request.headers.entries) {
+ xhr.setRequestHeader(header.key, header.value);
+ }
var completer = Completer<StreamedResponse>();
unawaited(xhr.onLoad.first.then((_) {
- if (xhr.responseHeaders['content-length'] case final contentLengthHeader?
- when !_digitRegex.hasMatch(contentLengthHeader)) {
+ if (xhr.responseHeaders['content-length'] case final contentLengthHeader
+ when contentLengthHeader != null &&
+ !_digitRegex.hasMatch(contentLengthHeader)) {
completer.completeError(ClientException(
'Invalid content-length header [$contentLengthHeader].',
request.url,
@@ -76,7 +81,7 @@
}
var body = (xhr.response as ByteBuffer).asUint8List();
completer.complete(StreamedResponse(
- ByteStream.fromBytes(body), xhr.status!,
+ ByteStream.fromBytes(body), xhr.status,
contentLength: body.length,
request: request,
headers: xhr.responseHeaders,
@@ -91,7 +96,7 @@
StackTrace.current);
}));
- xhr.send(bytes);
+ xhr.send(bytes.toJS);
try {
return await completer.future;
@@ -112,3 +117,30 @@
_xhrs.clear();
}
}
+
+extension on XMLHttpRequest {
+ Map<String, String> get responseHeaders {
+ // from Closure's goog.net.Xhrio.getResponseHeaders.
+ var headers = <String, String>{};
+ var headersString = getAllResponseHeaders();
+ var headersList = headersString.split('\r\n');
+ for (var header in headersList) {
+ if (header.isEmpty) {
+ continue;
+ }
+
+ var splitIdx = header.indexOf(': ');
+ if (splitIdx == -1) {
+ continue;
+ }
+ var key = header.substring(0, splitIdx).toLowerCase();
+ var value = header.substring(splitIdx + 2);
+ if (headers.containsKey(key)) {
+ headers[key] = '${headers[key]}, $value';
+ } else {
+ headers[key] = value;
+ }
+ }
+ return headers;
+ }
+}
diff --git a/pkgs/http/lib/src/client.dart b/pkgs/http/lib/src/client.dart
index 9bceb88..85d933a 100644
--- a/pkgs/http/lib/src/client.dart
+++ b/pkgs/http/lib/src/client.dart
@@ -12,7 +12,7 @@
import 'base_client.dart';
import 'base_request.dart';
import 'client_stub.dart'
- if (dart.library.html) 'browser_client.dart'
+ if (dart.library.js_interop) 'browser_client.dart'
if (dart.library.io) 'io_client.dart';
import 'exception.dart';
import 'response.dart';
diff --git a/pkgs/http/lib/src/client_stub.dart b/pkgs/http/lib/src/client_stub.dart
index 1a34d50..6384fd0 100644
--- a/pkgs/http/lib/src/client_stub.dart
+++ b/pkgs/http/lib/src/client_stub.dart
@@ -6,4 +6,4 @@
/// Implemented in `browser_client.dart` and `io_client.dart`.
BaseClient createClient() => throw UnsupportedError(
- 'Cannot create a client without dart:html or dart:io.');
+ 'Cannot create a client without dart:js_interop or dart:io.');
diff --git a/pkgs/http/pubspec.yaml b/pkgs/http/pubspec.yaml
index ec23e2d..3df7a30 100644
--- a/pkgs/http/pubspec.yaml
+++ b/pkgs/http/pubspec.yaml
@@ -1,15 +1,16 @@
name: http
-version: 1.1.1-wip
+version: 1.1.1
description: A composable, multi-platform, Future-based API for HTTP requests.
repository: https://github.com/dart-lang/http/tree/master/pkgs/http
environment:
- sdk: ^3.0.0
+ sdk: ^3.2.0
dependencies:
async: ^2.5.0
http_parser: ^4.0.0
meta: ^1.3.0
+ web: ^0.4.0
dev_dependencies:
dart_flutter_team_lints: ^1.0.0
diff --git a/pkgs/http/test/html/utils.dart b/pkgs/http/test/html/utils.dart
index abe5808..501c621 100644
--- a/pkgs/http/test/html/utils.dart
+++ b/pkgs/http/test/html/utils.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import 'dart:html';
+import 'package:web/helpers.dart';
export '../utils.dart';
diff --git a/tool/ci.sh b/tool/ci.sh
index 26395d2..44ea987 100755
--- a/tool/ci.sh
+++ b/tool/ci.sh
@@ -1,9 +1,10 @@
#!/bin/bash
-# Created with package:mono_repo v6.6.0
+# Created with package:mono_repo v6.6.1
# Support built in commands on windows out of the box.
+
# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter")
-# then "flutter" is called instead of "pub".
+# then "flutter pub" is called instead of "dart pub".
# This assumes that the Flutter SDK has been installed in a previous step.
function pub() {
if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then
@@ -12,18 +13,13 @@
command dart pub "$@"
fi
}
-# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter")
-# then "flutter" is called instead of "pub".
-# This assumes that the Flutter SDK has been installed in a previous step.
+
function format() {
- if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then
- command flutter format "$@"
- else
- command dart format "$@"
- fi
+ command dart format "$@"
}
+
# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter")
-# then "flutter" is called instead of "pub".
+# then "flutter analyze" is called instead of "dart analyze".
# This assumes that the Flutter SDK has been installed in a previous step.
function analyze() {
if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then