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
48 changes: 35 additions & 13 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@ name: Dart CI

on:
push:
tags:
# must align with the tag-pattern configured on pub.dev, often just replace
# {{version}} with [0-9]+.[0-9]+.[0-9]+
- 'v[0-9]+.[0-9]+.[0-9]+' # tag-pattern on pub.dev: 'v{{version}}'
branches:
- main
pull_request:

env:
MINIMUM_PANA_SCORE: 150

jobs:
format:
name: Verify code formatting
runs-on: ubuntu-slim
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Print version
run: dart --version
- name: Install dependencies
run: dart --version && dart pub get
- name: Verify formatting
run: dart format --set-exit-if-changed .
analyze:
needs: format
lints:
name: Analyze source code
needs: [format]
runs-on: ubuntu-slim
strategy:
fail-fast: false
Expand All @@ -28,28 +37,41 @@ jobs:
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}
- name: Print version
run: dart --version
- name: Install dependencies
run: dart pub get
run: dart --version && dart pub get
- name: Analyze project source
run: dart analyze
package_health:
name: Analyze package health
needs: [lints]
runs-on: ubuntu-slim
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Install dependencies
run: dart --version && dart pub get && dart pub global activate pana
- name: Run package analyzer
run: dart pub global run pana --exit-code-threshold $MINIMUM_PANA_SCORE
test:
needs: analyze
name: Run tests
needs: [lints]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
sdk: [stable, dev]
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}
- uses: browser-actions/setup-chrome@v2
- name: Print version
run: dart --version
- name: Install dependencies
run: dart pub get
run: dart --version && dart pub get
- name: Run tests (VM)
run: dart test --platform vm
- name: Run tests (Chrome)
run: dart test --platform chrome
- name: Run tests (Chrome, JS)
run: dart test --platform chrome --compiler dart2js
- name: Run tests (Chrome, WASM)
run: dart test --platform chrome --compiler dart2wasm
15 changes: 15 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Publish to pub.dev

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
with:
environment: pub.dev
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.3.1
* Improves documentation.

# 2.3.0
* Makes BrowserHttpClient WASM compatible by making it use "dart:js_interop" rather than "dart:html".
* Fixes various bugs.
Expand Down
4 changes: 1 addition & 3 deletions dart_test.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
platforms: [ chrome, vm, node ]
tags:
ipv6:
platforms: [ chrome, vm ]
3 changes: 3 additions & 0 deletions lib/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

/// @nodoc
library;

export 'universal_io.dart';
4 changes: 2 additions & 2 deletions lib/src/_http_headers_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ final class HttpHeadersImpl implements HttpHeaders {
this.protocolVersion, {
int defaultPortForScheme = HttpClient.defaultHttpPort,
HttpHeadersImpl? initialHeaders,
}) : _headers = HashMap<String, List<String>>(),
_defaultPortForScheme = defaultPortForScheme {
}) : _headers = HashMap<String, List<String>>(),
_defaultPortForScheme = defaultPortForScheme {
if (initialHeaders != null) {
initialHeaders._headers.forEach((name, value) => _headers[name] = value);
_contentLength = initialHeaders._contentLength;
Expand Down
20 changes: 9 additions & 11 deletions lib/src/_io_sink_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ abstract mixin class IOSinkBase implements IOSink {

@override
Future addStream(Stream<List<int>> stream) {
return stream
.listen(
(data) {
add(data);
},
onError: (error, stackTrace) {
addError(error, stackTrace);
},
cancelOnError: true,
)
.asFuture();
return stream.listen(
(data) {
add(data);
},
onError: (error, stackTrace) {
addError(error, stackTrace);
},
cancelOnError: true,
).asFuture();
}

@override
Expand Down
7 changes: 3 additions & 4 deletions lib/src/_xhr_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ final class XhrHttpClient extends BrowserHttpClient {

@override
Future<bool> Function(String host, int port, String scheme, String realm)?
authenticateProxy;
authenticateProxy;

@override
bool Function(X509Certificate cert, String host, int port)?
badCertificateCallback;
badCertificateCallback;

@override
String Function(Uri url)? findProxy;
Expand All @@ -58,8 +58,7 @@ final class XhrHttpClient extends BrowserHttpClient {
Uri url,
String? proxyHost,
int? proxyPort,
)?
f,
)? f,
) {
// TODO: implement connectionFactory
}
Expand Down
22 changes: 10 additions & 12 deletions lib/src/_xhr_http_client_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class XhrHttpClientRequest extends BrowserHttpClientRequest

@internal
XhrHttpClientRequest(this.client, this.method, this.uri)
: _supportsBody = _httpMethodSupportsBody(method) {
: _supportsBody = _httpMethodSupportsBody(method) {
// Add "User-Agent" header
final userAgent = client.userAgent;
if (userAgent != null) {
Expand Down Expand Up @@ -133,17 +133,15 @@ final class XhrHttpClientRequest extends BrowserHttpClientRequest
@override
Future<void> addStream(Stream<List<int>> stream) async {
_checkAddRequirements();
final future = stream
.listen(
(item) {
_buffer.addAll(item);
},
onError: (error) {
addError(error);
},
cancelOnError: true,
)
.asFuture(null);
final future = stream.listen(
(item) {
_buffer.addAll(item);
},
onError: (error) {
addError(error);
},
cancelOnError: true,
).asFuture(null);
_addStreamFuture = future;
await future;
_addStreamFuture = null;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/browser_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class BrowserHttpClient implements HttpClient {
/// Enables you to set [BrowserHttpClientRequest.browserRequestType] before
/// any _XHR_ request is sent to the server.
FutureOr<void> Function(BrowserHttpClientRequest request)?
onBrowserHttpClientRequestClose;
onBrowserHttpClientRequestClose;

/// Enables [CORS "credentials mode"](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials)
/// for all _XHR_ requests. Disabled by default.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/internet_address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ class InternetAddress implements dart_io.InternetAddress {
static Future<List<InternetAddress>> lookup(
String host, {
InternetAddressType type = InternetAddressType.any,
}) => throw UnimplementedError();
}) =>
throw UnimplementedError();

/// Attempts to parse [address] as a numeric address.
///
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: universal_io
version: 2.3.0
version: 2.3.1
description: Cross-platform 'dart:io' that adds browser support for HttpClient and some other
"dart:io" APIs.
homepage: https://github.com/dart-io-packages/universal_io
Expand Down
20 changes: 10 additions & 10 deletions test/http_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ void _testHttpClient({required bool isBrowser}) async {
testOn: '!browser',
);

test('TLS connection to a self-signed server succeeds with'
test(
'TLS connection to a self-signed server succeeds with'
" the help of 'badCertificateCallback'", () async {
final client = HttpClient();
client.badCertificateCallback = (certificate, host, port) {
Expand Down Expand Up @@ -500,8 +501,8 @@ Future<HttpClientResponse?> _testClient({

// Close HTTP request
final response = await httpClientRequest.close().timeout(
const Duration(milliseconds: 500),
);
const Duration(milliseconds: 500),
);
final actualResponseBody = await utf8
.decodeStream(response.cast<List<int>>())
.timeout(const Duration(seconds: 5));
Expand Down Expand Up @@ -554,13 +555,12 @@ Future _testClientMethodWithoutUri({
expect(response.statusCode, 200);
}

typedef OpenUrlFunction =
Future<HttpClientRequest> Function(
HttpClient client,
String host,
int port,
String path,
);
typedef OpenUrlFunction = Future<HttpClientRequest> Function(
HttpClient client,
String host,
int port,
String path,
);

class _ExpectedResponse {
final int status;
Expand Down
4 changes: 3 additions & 1 deletion test/platform_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
@TestOn('chrome')
library;

import 'dart:js_interop';

import 'package:test/test.dart';
import 'package:universal_io/io.dart';
import 'package:universal_io/src/js/_xhr.dart';

void main() {
if (navigator.languages.length > 0) {
final locale = navigator.languages[0];
final locale = navigator.languages[0].toDart;
test("Platform.localeName == '$locale'", () {
expect(Platform.localeName, locale);
});
Expand Down