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
4 changes: 2 additions & 2 deletions .github/workflows/cupertino.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
matrix:
# Test on the minimum supported flutter version and the latest
# version.
flutter-version: ["3.24.0", "any"]
flutter-version: ["3.32.0", "any"]
# It would be nice to test on older versions of macOS but macOS 13 is
# the oldest supported by GitHub.
os: [macos-13, macos-latest]
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
matrix:
# Test on the minimum supported flutter version and the latest
# version.
flutter-version: ["3.24.0", "any"]
flutter-version: ["3.32.0", "any"]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: subosito/flutter-action@fd55f4c5af5b953cc57a2be44cb082c8f6635e8e
Expand Down
4 changes: 4 additions & 0 deletions pkgs/cupertino_http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.4.0-wip

* Switch to `package:objective_c` `8.1.0` and `package:ffigen` `19.1.0`.

## 2.3.0

* Add the ability to abort requests.
Expand Down

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

141 changes: 95 additions & 46 deletions pkgs/cupertino_http/example/integration_test/client_profile_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ void main() {
});
successServerUri = Uri.http('localhost:${successServer.port}');
final client = CupertinoClientWithProfile.defaultSessionConfiguration();
await client.post(successServerUri,
headers: {'Content-Type': 'text/plain'}, body: 'Hi');
await client.post(
successServerUri,
headers: {'Content-Type': 'text/plain'},
body: 'Hi',
);
profile = client.profile!;
});
tearDownAll(() {
Expand All @@ -53,8 +56,10 @@ void main() {
expect(profile.events, isEmpty);
expect(profile.requestMethod, 'POST');
expect(profile.requestUri, successServerUri.toString());
expect(profile.connectionInfo,
containsPair('package', 'package:cupertino_http'));
expect(
profile.connectionInfo,
containsPair('package', 'package:cupertino_http'),
);
});

test('request attributes', () {
Expand All @@ -63,9 +68,13 @@ void main() {
expect(profile.requestData.endTime, isNotNull);
expect(profile.requestData.error, isNull);
expect(
profile.requestData.headers, containsPair('Content-Length', ['2']));
expect(profile.requestData.headers,
containsPair('Content-Type', ['text/plain; charset=utf-8']));
profile.requestData.headers,
containsPair('Content-Length', ['2']),
);
expect(
profile.requestData.headers,
containsPair('Content-Type', ['text/plain; charset=utf-8']),
);
expect(profile.requestData.persistentConnection, isNull);
expect(profile.requestData.proxyDetails, isNull);
expect(profile.requestData.startTime, isNotNull);
Expand All @@ -77,10 +86,14 @@ void main() {
expect(profile.responseData.contentLength, 11);
expect(profile.responseData.endTime, isNotNull);
expect(profile.responseData.error, isNull);
expect(profile.responseData.headers,
containsPair('content-type', ['text/plain']));
expect(profile.responseData.headers,
containsPair('content-length', ['11']));
expect(
profile.responseData.headers,
containsPair('content-type', ['text/plain']),
);
expect(
profile.responseData.headers,
containsPair('content-length', ['11']),
);
expect(profile.responseData.isRedirect, false);
expect(profile.responseData.persistentConnection, isNull);
expect(profile.responseData.reasonPhrase, 'OK');
Expand Down Expand Up @@ -119,7 +132,8 @@ void main() {
}
}();
unawaited(
request.sink.addStream(stream).then((_) => request.sink.close()));
request.sink.addStream(stream).then((_) => request.sink.close()),
);

await client.send(request);
profile = client.profile!;
Expand All @@ -143,8 +157,11 @@ void main() {
setUpAll(() async {
final client = CupertinoClientWithProfile.defaultSessionConfiguration();
try {
await client.post(Uri.http('thisisnotahost'),
headers: {'Content-Type': 'text/plain'}, body: 'Hi');
await client.post(
Uri.http('thisisnotahost'),
headers: {'Content-Type': 'text/plain'},
body: 'Hi',
);
fail('expected exception');
} on ClientException {
// Expected exception.
Expand All @@ -156,20 +173,28 @@ void main() {
expect(profile.events, isEmpty);
expect(profile.requestMethod, 'POST');
expect(profile.requestUri, 'http://thisisnotahost');
expect(profile.connectionInfo,
containsPair('package', 'package:cupertino_http'));
expect(
profile.connectionInfo,
containsPair('package', 'package:cupertino_http'),
);
});

test('request attributes', () {
expect(profile.requestData.bodyBytes, 'Hi'.codeUnits);
expect(profile.requestData.contentLength, 2);
expect(profile.requestData.endTime, isNotNull);
expect(
profile.requestData.error, startsWith('NSErrorClientException:'));
profile.requestData.error,
startsWith('NSErrorClientException:'),
);
expect(
profile.requestData.headers,
containsPair('Content-Length', ['2']),
);
expect(
profile.requestData.headers, containsPair('Content-Length', ['2']));
expect(profile.requestData.headers,
containsPair('Content-Type', ['text/plain; charset=utf-8']));
profile.requestData.headers,
containsPair('Content-Type', ['text/plain; charset=utf-8']),
);
expect(profile.requestData.persistentConnection, isNull);
expect(profile.requestData.proxyDetails, isNull);
expect(profile.requestData.startTime, isNotNull);
Expand Down Expand Up @@ -209,8 +234,11 @@ void main() {
final client = CupertinoClientWithProfile.defaultSessionConfiguration();

try {
await client.post(successServerUri,
headers: {'Content-Type': 'text/plain'}, body: 'Hi');
await client.post(
successServerUri,
headers: {'Content-Type': 'text/plain'},
body: 'Hi',
);
fail('expected exception');
} on ClientException {
// Expected exception.
Expand All @@ -225,8 +253,10 @@ void main() {
expect(profile.events, isEmpty);
expect(profile.requestMethod, 'POST');
expect(profile.requestUri, successServerUri.toString());
expect(profile.connectionInfo,
containsPair('package', 'package:cupertino_http'));
expect(
profile.connectionInfo,
containsPair('package', 'package:cupertino_http'),
);
});

test('request attributes', () {
Expand All @@ -235,9 +265,13 @@ void main() {
expect(profile.requestData.endTime, isNotNull);
expect(profile.requestData.error, isNull);
expect(
profile.requestData.headers, containsPair('Content-Length', ['2']));
expect(profile.requestData.headers,
containsPair('Content-Type', ['text/plain; charset=utf-8']));
profile.requestData.headers,
containsPair('Content-Length', ['2']),
);
expect(
profile.requestData.headers,
containsPair('Content-Type', ['text/plain; charset=utf-8']),
);
expect(profile.requestData.persistentConnection, isNull);
expect(profile.requestData.proxyDetails, isNull);
expect(profile.requestData.startTime, isNotNull);
Expand All @@ -249,11 +283,17 @@ void main() {
expect(profile.responseData.contentLength, 11);
expect(profile.responseData.endTime, isNotNull);
expect(
profile.responseData.error, startsWith('NSErrorClientException:'));
expect(profile.responseData.headers,
containsPair('content-type', ['text/plain']));
expect(profile.responseData.headers,
containsPair('content-length', ['11']));
profile.responseData.error,
startsWith('NSErrorClientException:'),
);
expect(
profile.responseData.headers,
containsPair('content-type', ['text/plain']),
);
expect(
profile.responseData.headers,
containsPair('content-length', ['11']),
);
expect(profile.responseData.isRedirect, false);
expect(profile.responseData.persistentConnection, isNull);
expect(profile.responseData.reasonPhrase, 'OK');
Expand Down Expand Up @@ -325,8 +365,11 @@ void main() {
} else {
final n = int.parse(request.requestedUri.pathSegments.last);
final nextPath = n - 1 == 0 ? '' : '${n - 1}';
unawaited(request.response
.redirect(successServerUri.replace(path: '/$nextPath')));
unawaited(
request.response.redirect(
successServerUri.replace(path: '/$nextPath'),
),
);
}
});
successServerUri = Uri.http('localhost:${successServer.port}');
Expand All @@ -345,9 +388,11 @@ void main() {

test('follow redirects', () async {
final client = CupertinoClientWithProfile.defaultSessionConfiguration();
await client.send(Request('GET', successServerUri.replace(path: '/3'))
..followRedirects = true
..maxRedirects = 4);
await client.send(
Request('GET', successServerUri.replace(path: '/3'))
..followRedirects = true
..maxRedirects = 4,
);
profile = client.profile!;

expect(profile.requestData.followRedirects, true);
Expand All @@ -356,25 +401,29 @@ void main() {

expect(profile.responseData.redirects, [
HttpProfileRedirectData(
statusCode: 302,
method: 'GET',
location: successServerUri.replace(path: '/2').toString()),
statusCode: 302,
method: 'GET',
location: successServerUri.replace(path: '/2').toString(),
),
HttpProfileRedirectData(
statusCode: 302,
method: 'GET',
location: successServerUri.replace(path: '/1').toString()),
statusCode: 302,
method: 'GET',
location: successServerUri.replace(path: '/1').toString(),
),
HttpProfileRedirectData(
statusCode: 302,
method: 'GET',
location: successServerUri.replace(path: '/').toString(),
)
),
]);
});

test('no follow redirects', () async {
final client = CupertinoClientWithProfile.defaultSessionConfiguration();
await client.send(Request('GET', successServerUri.replace(path: '/3'))
..followRedirects = false);
await client.send(
Request('GET', successServerUri.replace(path: '/3'))
..followRedirects = false,
);
profile = client.profile!;

expect(profile.requestData.followRedirects, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ void main() {
});
final session = URLSession.sharedSession();
final task = session.dataTaskWithRequest(
URLRequest.fromUrl(Uri.parse('http://localhost:${server.port}')))
..resume();
while (
task.state != NSURLSessionTaskState.NSURLSessionTaskStateCompleted) {
URLRequest.fromUrl(Uri.parse('http://localhost:${server.port}')),
)..resume();
while (task.state !=
NSURLSessionTaskState.NSURLSessionTaskStateCompleted) {
// Let the event loop run.
await Future<void>(() {});
}
Expand Down
2 changes: 0 additions & 2 deletions pkgs/cupertino_http/example/integration_test/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import 'url_session_configuration_test.dart' as url_session_configuration_test;
import 'url_session_delegate_test.dart' as url_session_delegate_test;
import 'url_session_task_test.dart' as url_session_task_test;
import 'url_session_test.dart' as url_session_test;
import 'utils_test.dart' as utils_test;
import 'web_socket_conformance_test.dart' as web_socket_conformance_test;

/// Execute all the tests in this directory.
Expand All @@ -39,6 +38,5 @@ void main() {
url_session_delegate_test.main();
url_session_task_test.main();
url_session_test.main();
utils_test.main();
web_socket_conformance_test.main();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ void main() {
test('set', () {
request.cachePolicy =
NSURLRequestCachePolicy.NSURLRequestReturnCacheDataDontLoad;
expect(request.cachePolicy,
NSURLRequestCachePolicy.NSURLRequestReturnCacheDataDontLoad);
expect(
request.cachePolicy,
NSURLRequestCachePolicy.NSURLRequestReturnCacheDataDontLoad,
);
request.toString(); // Just verify that there is no crash.
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,25 @@ void main() {

test('thrown', () async {
expect(
() => client.get(Uri.http('doesnotexist', '/')),
throwsA(isA<NSErrorClientException>()
.having((e) => e.error.domain.toDartString(), 'error.domain',
'NSURLErrorDomain')
() => client.get(Uri.http('doesnotexist', '/')),
throwsA(
isA<NSErrorClientException>()
.having(
(e) => e.error.domain.toDartString(),
'error.domain',
'NSURLErrorDomain',
)
.having((e) => e.error.code, 'error.code', -1003)
.having(
(e) => e.toString(),
'toString()',
'NSErrorClientException: A server with the specified '
'hostname could not be found. '
'[domain=NSURLErrorDomain, code=-1003], '
'uri=http://doesnotexist/')));
(e) => e.toString(),
'toString()',
'NSErrorClientException: A server with the specified '
'hostname could not be found. '
'[domain=NSURLErrorDomain, code=-1003], '
'uri=http://doesnotexist/',
),
),
);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ void main() {
});

Future<void> doRequest(URLSession session) {
final request =
URLRequest.fromUrl(Uri.parse('http://localhost:${server.port}'));
final request = URLRequest.fromUrl(
Uri.parse('http://localhost:${server.port}'),
);
final c = Completer<void>();
session.dataTaskWithCompletionHandler(request, (d, r, e) {
c.complete();
Expand Down
Loading
Loading