Skip to content

Commit

Permalink
Merge branch 'master' into chore/ci
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Jan 20, 2024
2 parents 1fab635 + ccefa7c commit 63491a9
Show file tree
Hide file tree
Showing 36 changed files with 722 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cupertino.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
matrix:
# Test on the minimum supported flutter version and the latest
# version.
flutter-version: ["3.10.0", "any"]
flutter-version: ["3.16.0", "any"]
steps:
- uses: actions/checkout@v4
- uses: futureware-tech/simulator-action@v3
Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/dart.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Contributing :heart:

Want to contribute? Great! First, read this page (including the small print at
the end).

### Before you contribute

Before we can use your code, you must sign the
[Google Individual Contributor License Agreement](https://cla.developers.google.com/about/google-individual)
(CLA), which you can do online. The CLA is necessary mainly because you own the
copyright to your changes, even after your contribution becomes part of our
codebase, so we need your permission to use and distribute your code. We also
need to be sure of various other things—for instance that you'll tell us if you
know that your code infringes on other people's patents. You don't have to sign
the CLA until after you've submitted your code for review and a member has
approved it, but you must do it before we can put your code into our codebase.

Before you start working on a larger contribution, you should get in touch with
us first through the issue tracker with your idea so that we can help out and
possibly guide you. Coordinating up front makes it much easier to avoid
frustration later on.

### Code reviews

All submissions, including submissions by project members, require review.

### File headers

All files in the project must start with the following header.

```dart
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// 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.
```

### The small print

Contributions made by corporations are covered by a different agreement than the
one above, the
[Software Grant and Corporate Contributor License Agreement](https://developers.google.com/open-source/cla/corporate).

## A word about conduct

We pledge to maintain an open and welcoming environment :hugs:.
For details, see our
[code of conduct](https://dart.dev/community/code-of-conduct).
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ and the browser.
| [cronet_http](pkgs/cronet_http/) | An Android Flutter plugin that provides access to the [Cronet](https://developer.android.com/guide/topics/connectivity/cronet/reference/org/chromium/net/package-summary) HTTP client. | [![pub package](https://img.shields.io/pub/v/cronet_http.svg)](https://pub.dev/packages/cronet_http) |
| [cupertino_http](pkgs/cupertino_http/) | A macOS/iOS Flutter plugin that provides access to the [Foundation URL Loading System](https://developer.apple.com/documentation/foundation/url_loading_system). | [![pub package](https://img.shields.io/pub/v/cupertino_http.svg)](https://pub.dev/packages/cupertino_http) |
| [flutter_http_example](pkgs/flutter_http_example/) | An Flutter app that demonstrates how to configure and use `package:http`. ||

## Contributing

If you'd like to contribute to any of these packages, see the
[Contributing Guide](CONTRIBUTING.md).
3 changes: 2 additions & 1 deletion pkgs/cronet_http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 1.0.1-wip
## 1.1.0

* Use `package:http_image_provider` in the example application.
* Support Android API 21+.
* Support `BaseResponseWithUrl`.

## 1.0.0

Expand Down
2 changes: 2 additions & 0 deletions pkgs/cronet_http/example/integration_test/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Future<void> testConformance() async {
() => testAll(
CronetClient.defaultCronetEngine,
canStreamRequestBody: false,
canReceiveSetCookieHeaders: true,
canSendCookieHeaders: true,
));

group('from cronet engine', () {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/cronet_http/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Demonstrates how to use the cronet_http plugin.
publish_to: 'none'

environment:
sdk: ^3.0.0
sdk: ^3.2.0

dependencies:
cronet_http:
Expand Down
19 changes: 18 additions & 1 deletion pkgs/cronet_http/lib/src/cronet_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ import 'jni/jni_bindings.dart' as jb;
final _digitRegex = RegExp(r'^\d+$');
const _bufferSize = 10 * 1024; // The size of the Cronet read buffer.

/// This class can be removed when `package:http` v2 is released.
class _StreamedResponseWithUrl extends StreamedResponse
implements BaseResponseWithUrl {
@override
final Uri url;

_StreamedResponseWithUrl(super.stream, super.statusCode,
{required this.url,
super.contentLength,
super.request,
super.headers,
super.isRedirect,
super.reasonPhrase});
}

/// The type of caching to use when making HTTP requests.
enum CacheMode {
disabled,
Expand Down Expand Up @@ -163,9 +178,11 @@ jb.UrlRequestCallbackProxy_UrlRequestCallbackInterface _urlRequestCallbacks(
case final contentLengthHeader?:
contentLength = int.parse(contentLengthHeader);
}
responseCompleter.complete(StreamedResponse(
responseCompleter.complete(_StreamedResponseWithUrl(
responseStream!.stream,
responseInfo.getHttpStatusCode(),
url: Uri.parse(
responseInfo.getUrl().toDartString(releaseOriginal: true)),
contentLength: contentLength,
reasonPhrase: responseInfo
.getHttpStatusText()
Expand Down
4 changes: 2 additions & 2 deletions pkgs/cronet_http/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: cronet_http
version: 1.0.1-wip
version: 1.1.0
description: >-
An Android Flutter plugin that provides access to the Cronet HTTP client.
repository: https://github.com/dart-lang/http/tree/master/pkgs/cronet_http
Expand All @@ -11,7 +11,7 @@ environment:
dependencies:
flutter:
sdk: flutter
http: '>=0.13.4 <2.0.0'
http: ^1.2.0
jni: ^0.7.2

dev_dependencies:
Expand Down
3 changes: 2 additions & 1 deletion pkgs/cupertino_http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.2.1-wip
## 1.3.0

* Use `package:http_image_provider` in the example application.
* Support `BaseResponseWithUrl`.

## 1.2.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('defaultSessionConfiguration', () {
testAll(CupertinoClient.defaultSessionConfiguration);
testAll(
CupertinoClient.defaultSessionConfiguration,
canReceiveSetCookieHeaders: true,
canSendCookieHeaders: true,
);
});
group('fromSessionConfiguration', () {
final config = URLSessionConfiguration.ephemeralSessionConfiguration();
testAll(() => CupertinoClient.fromSessionConfiguration(config),
canWorkInIsolates: false);
testAll(
() => CupertinoClient.fromSessionConfiguration(config),
canWorkInIsolates: false,
canReceiveSetCookieHeaders: true,
canSendCookieHeaders: true,
);
});
}
4 changes: 2 additions & 2 deletions pkgs/cupertino_http/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ^3.0.0
flutter: '>=3.10.0'
sdk: ^3.2.0
flutter: ^3.16.0

dependencies:
cupertino_http:
Expand Down
20 changes: 19 additions & 1 deletion pkgs/cupertino_http/lib/src/cupertino_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,27 @@ import 'cupertino_api.dart';

final _digitRegex = RegExp(r'^\d+$');

/// This class can be removed when `package:http` v2 is released.
class _StreamedResponseWithUrl extends StreamedResponse
implements BaseResponseWithUrl {
@override
final Uri url;

_StreamedResponseWithUrl(super.stream, super.statusCode,
{required this.url,
super.contentLength,
super.request,
super.headers,
super.isRedirect,
super.reasonPhrase});
}

class _TaskTracker {
final responseCompleter = Completer<URLResponse>();
final BaseRequest request;
final responseController = StreamController<Uint8List>();
int numRedirects = 0;
Uri? lastUrl; // The last URL redirected to.

_TaskTracker(this.request);

Expand Down Expand Up @@ -180,6 +196,7 @@ class CupertinoClient extends BaseClient {
++taskTracker.numRedirects;
if (taskTracker.request.followRedirects &&
taskTracker.numRedirects <= taskTracker.request.maxRedirects) {
taskTracker.lastUrl = request.url;
return request;
}
return null;
Expand Down Expand Up @@ -292,9 +309,10 @@ class CupertinoClient extends BaseClient {
);
}

return StreamedResponse(
return _StreamedResponseWithUrl(
taskTracker.responseController.stream,
response.statusCode,
url: taskTracker.lastUrl ?? request.url,
contentLength: response.expectedContentLength == -1
? null
: response.expectedContentLength,
Expand Down
8 changes: 4 additions & 4 deletions pkgs/cupertino_http/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: cupertino_http
version: 1.2.1-wip
version: 1.3.0
description: >-
A macOS/iOS Flutter plugin that provides access to the Foundation URL
Loading System.
repository: https://github.com/dart-lang/http/tree/master/pkgs/cupertino_http

environment:
sdk: ^3.0.0
flutter: '>=3.10.0' # If changed, update test matrix.
sdk: ^3.2.0
flutter: ^3.16.0 # If changed, update test matrix.

dependencies:
async: ^2.5.0
ffi: ^2.1.0
flutter:
sdk: flutter
http: '>=0.13.4 <2.0.0'
http: ^1.2.0

dev_dependencies:
dart_flutter_team_lints: ^2.0.0
Expand Down
5 changes: 4 additions & 1 deletion pkgs/http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## 1.1.3-wip
## 1.2.0

* Add `MockClient.pngResponse`, which makes it easier to fake image responses.
* Added the ability to fetch the URL of the response through `BaseResponseWithUrl`.
* Add the ability to get headers as a `Map<String, List<String>` to
`BaseResponse`.

## 1.1.2

Expand Down
5 changes: 3 additions & 2 deletions pkgs/http/lib/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import 'src/streamed_request.dart';

export 'src/base_client.dart';
export 'src/base_request.dart';
export 'src/base_response.dart';
export 'src/base_response.dart'
show BaseResponse, BaseResponseWithUrl, HeadersWithSplitValues;
export 'src/byte_stream.dart';
export 'src/client.dart' hide zoneClient;
export 'src/exception.dart';
Expand All @@ -25,7 +26,7 @@ export 'src/multipart_request.dart';
export 'src/request.dart';
export 'src/response.dart';
export 'src/streamed_request.dart';
export 'src/streamed_response.dart';
export 'src/streamed_response.dart' show StreamedResponse;

/// Sends an HTTP HEAD request with the given headers to the given URL.
///
Expand Down
26 changes: 19 additions & 7 deletions pkgs/http/lib/src/base_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,25 @@ abstract class BaseRequest {
try {
var response = await client.send(this);
var stream = onDone(response.stream, client.close);
return StreamedResponse(ByteStream(stream), response.statusCode,
contentLength: response.contentLength,
request: response.request,
headers: response.headers,
isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase);

if (response case BaseResponseWithUrl(:final url)) {
return StreamedResponseV2(ByteStream(stream), response.statusCode,
contentLength: response.contentLength,
request: response.request,
headers: response.headers,
isRedirect: response.isRedirect,
url: url,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase);
} else {
return StreamedResponse(ByteStream(stream), response.statusCode,
contentLength: response.contentLength,
request: response.request,
headers: response.headers,
isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase);
}
} catch (_) {
client.close();
rethrow;
Expand Down
Loading

0 comments on commit 63491a9

Please sign in to comment.