Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Migrate Essentials v0.0.1: Implement Client with openUrl method #2

Merged
merged 42 commits into from Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d96f235
adding dependencies, generated_bindings and android support
unsuitable001 Jun 11, 2021
4d3bb12
refactor: third_party APIs (cronet) seperated from wrapper.h
unsuitable001 Jun 12, 2021
e3ca8a8
initial implementation: essential APIs of http client, request & resp…
unsuitable001 Jun 12, 2021
b2253a3
refactor: comments & readme
unsuitable001 Jun 13, 2021
30cfbe6
refactor: docs, analysis, license, tests
unsuitable001 Jun 13, 2021
1ba712d
api change: registerCallback's future resolves `bool` and readDataCal…
unsuitable001 Jun 14, 2021
a218ac4
tests & bug fix: http response callback api
unsuitable001 Jun 15, 2021
d99c7c3
tests: automatic port selection
unsuitable001 Jun 15, 2021
c3da375
tests: add license and enforce 80char
unsuitable001 Jun 16, 2021
ea156b1
remove: flutter support boilerplate
unsuitable001 Jun 17, 2021
382be13
hint user to get binaries and relocate prepare_cronet
unsuitable001 Jun 17, 2021
82b296a
refactor: native code lib/src/native -> src and 3rd_party -> third_party
unsuitable001 Jun 18, 2021
a667deb
rewrite build.sh in dart
unsuitable001 Jun 18, 2021
7df5522
add build_cronet executable for user customization
unsuitable001 Jun 18, 2021
9e7836a
tar -> package:archive and cronet binary detection improvements
unsuitable001 Jun 19, 2021
5b921cf
info: display command to get cronet library when wrapper can't load it
unsuitable001 Jun 19, 2021
0303b71
test: remove unused imports
unsuitable001 Jun 19, 2021
5d4c698
refactor: wrapper.cc & improve: destroying unused requests
unsuitable001 Jun 20, 2021
088b9fb
include: cronet c++ sample
unsuitable001 Jun 21, 2021
c88867e
refactoring, added new tests and api comparisons
unsuitable001 Jun 23, 2021
f6ae319
move find_resource.dart -> third_party and fix readme
unsuitable001 Jun 24, 2021
5eba348
remove: alternate callback based API
unsuitable001 Jun 24, 2021
dd2490f
refactor: remove part directives
unsuitable001 Jun 24, 2021
f4cbd24
merge quic & http2 options into protocol using enum HttpProtocol
unsuitable001 Jun 25, 2021
12499c3
initial splitting of cronet and wrapper bindings
unsuitable001 Jun 25, 2021
783a6ce
spliting wrapper and cronet bindings
unsuitable001 Jun 27, 2021
96636e8
locate binaries to .dart_tool
unsuitable001 Jun 27, 2021
d3e4d84
formatting and sanity checks
unsuitable001 Jun 28, 2021
5958aad
add licence & minor refactors
unsuitable001 Jun 29, 2021
7533e4b
void* -> real type def for cronet fn & test: add regex
unsuitable001 Jun 29, 2021
f9a1e1e
setup script, cmake based build & set dylibs as global
unsuitable001 Jun 30, 2021
1d51146
analyzer: removed unused show from tool/build_wrapper.dart
unsuitable001 Jun 30, 2021
2f93cd3
ci: change ci setup command
unsuitable001 Jun 30, 2021
31de14b
CronetNativeException -> Error and enum to string mapping
unsuitable001 Jun 30, 2021
2ce6957
add verify option to cronet:setup, fix setup halting
unsuitable001 Jun 30, 2021
0beef32
C API for SampleExecutor
unsuitable001 Jul 1, 2021
4452dbe
tool: update tarballs. setup verify: delete verifier after done.
unsuitable001 Jul 1, 2021
1dcb370
readme: setup command, add: ffigen issue reference
unsuitable001 Jul 2, 2021
c50d7b3
readme: typo fix
unsuitable001 Jul 2, 2021
f222aa4
readme: supported platforms
unsuitable001 Jul 2, 2021
3de3374
readme
unsuitable001 Jul 2, 2021
ec2efb0
update: binary download url
unsuitable001 Jul 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Expand Up @@ -88,7 +88,4 @@ dart run cronet <platform> # Downloads the cronet binaries.
dart test --platform vm
unsuitable001 marked this conversation as resolved.
Show resolved Hide resolved
```

**Note:** Make sure that `52XX` ports are not reserved by any other process.
As some of the tests use ports in this range.

**Wrapper & Cronet binaries build guide**: [BUILD.md](lib/src/native/wrapper/BUILD.md)
10 changes: 6 additions & 4 deletions test/http_client_close_test.dart
Expand Up @@ -7,13 +7,15 @@ import 'dart:io';

import 'package:cronet/cronet.dart';
import 'package:test/test.dart';
import 'test_utils.dart';

void main() {
group('client_close_test', () {
late HttpServer server;
final sentData = 'Hello, world!';
late int port;
setUp(() async {
server = await HttpServer.bind(InternetAddress.anyIPv6, 5253);
server = await HttpServer.bind(InternetAddress.anyIPv6, 0);
port = server.port;
server.listen((HttpRequest request) {
request.response.write(sentData);
request.response.close();
Expand All @@ -25,14 +27,14 @@ void main() {
client.close();
expect(
() async =>
await client.openUrl('GET', Uri.parse('http://localhost:5253')),
await client.openUrl('GET', Uri.parse('http://$host:$port')),
throwsException);
});

test('Keeps the previous connection alive, if closed afterwards', () async {
final client = HttpClient();
final request =
await client.openUrl('GET', Uri.parse('http://localhost:5253'));
await client.openUrl('GET', Uri.parse('http://$host:$port'));
final resp = await request.close();
client.close();
final dataStream = resp.transform(utf8.decoder);
Expand Down
11 changes: 8 additions & 3 deletions test/http_request_exceptions_test.dart
Expand Up @@ -6,33 +6,38 @@ import 'dart:io';

import 'package:cronet/cronet.dart';
import 'package:test/test.dart';
import 'test_utils.dart';

void main() {
group('request_HttpException_test', () {
late HttpClient client;
late int port;
setUp(() async {
client = HttpClient();
final server = await HttpServer.bind(InternetAddress.anyIPv6, 0);
port = server.port;
server.close();
});

test('URL do not exist', () async {
final request = await client.openUrl('GET',
Uri.parse('http://localghost:9999')); // localghost shouln't exist :p
Uri.parse('http://localghost:$port')); // localghost shouln't exist :p
unsuitable001 marked this conversation as resolved.
Show resolved Hide resolved
final resp = await request.close();
expect(resp,
emitsInOrder(<Matcher>[emitsError(isA<HttpException>()), emitsDone]));
});

test('The port is wrong', () async {
final request = await client.openUrl('GET',
Uri.parse('http://localhost:9999')); // port 9999 should be close
Uri.parse('http://$host:$port')); // port 9999 should be close
final resp = await request.close();
expect(resp,
emitsInOrder(<Matcher>[emitsError(isA<HttpException>()), emitsDone]));
});

test('The scheme is wrong', () async {
final request =
await client.openUrl('GET', Uri.parse('random://localhost:5253'));
await client.openUrl('GET', Uri.parse('random://$host:$port'));
unsuitable001 marked this conversation as resolved.
Show resolved Hide resolved
final resp = await request.close();
expect(resp,
emitsInOrder(<Matcher>[emitsError(isA<HttpException>()), emitsDone]));
Expand Down
13 changes: 8 additions & 5 deletions test/http_responses_exceptions_test.dart
Expand Up @@ -6,14 +6,17 @@ import 'dart:io';

import 'package:cronet/cronet.dart';
import 'package:test/test.dart';
import 'test_utils.dart';

void main() {
group('response_HttpException_test', () {
late HttpClient client;
late HttpServer server;
late int port;
setUp(() async {
client = HttpClient();
server = await HttpServer.bind(InternetAddress.anyIPv6, 5255);
server = await HttpServer.bind(InternetAddress.anyIPv6, 0);
port = server.port;
server.listen((HttpRequest request) {
final paths = request.uri.pathSegments;
request.response.statusCode = int.parse(paths[0]);
unsuitable001 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -23,7 +26,7 @@ void main() {

test('404, Not Found', () async {
final request =
await client.getUrl(Uri.parse('http://localhost:5255/404'));
await client.getUrl(Uri.parse('http://$host:$port/404'));
final resp = await request.close();
expect(
resp,
Expand All @@ -36,7 +39,7 @@ void main() {

test('401, Unauthorized', () async {
final request =
await client.getUrl(Uri.parse('http://localhost:5255/401'));
await client.getUrl(Uri.parse('http://$host:$port/401'));
final resp = await request.close();
expect(
resp,
Expand All @@ -49,7 +52,7 @@ void main() {

test('503, Service Unavailable', () async {
final request =
await client.getUrl(Uri.parse('http://localhost:5255/503'));
await client.getUrl(Uri.parse('http://$host:$port/503'));
final resp = await request.close();
expect(
resp,
Expand All @@ -64,7 +67,7 @@ void main() {

test('New API: 503, Service Unavailable', () async {
final request =
await client.getUrl(Uri.parse('http://localhost:5255/503'));
await client.getUrl(Uri.parse('http://$host:$port/503'));
final success = await request.registerCallbacks(
(data, bytesRead, responseCode) {}, onFailed: (reason) {
expect(
Expand Down
16 changes: 9 additions & 7 deletions test/http_responses_new_api_test.dart
Expand Up @@ -7,15 +7,17 @@ import 'dart:io';

import 'package:cronet/cronet.dart';
import 'package:test/test.dart';
import 'test_utils.dart';

void main() {
group('callback_api_response_test New API', () {
late HttpClient client;
late HttpServer server;
final sentData = 'Hello, world!';
late int port;
setUp(() async {
client = HttpClient();
server = await HttpServer.bind(InternetAddress.anyIPv6, 5256);
server = await HttpServer.bind(InternetAddress.anyIPv6, 0);
port = server.port;
server.listen((HttpRequest request) {
if (request.uri.pathSegments.isNotEmpty &&
request.uri.pathSegments[0] == '301') {
Expand All @@ -30,7 +32,7 @@ void main() {

test('Gets Hello, world response from server using getUrl', () async {
String resp = '';
final request = await client.getUrl(Uri.parse('http://localhost:5256'));
final request = await client.getUrl(Uri.parse('http://$host:$port'));
final success =
await request.registerCallbacks((data, bytesRead, responseCode) {
resp += utf8.decoder.convert(data);
Expand All @@ -44,7 +46,7 @@ void main() {
test('Invalid URLs calls onFailed and returns false', () async {
String resp = '';
final request = await client.getUrl(
Uri.parse('http://localghost:5256')); // localghost shouldn't exist
Uri.parse('http://localghost:$port')); // localghost shouldn't exist
final success =
await request.registerCallbacks((data, bytesRead, responseCode) {
resp += utf8.decoder.convert(data);
Expand All @@ -58,21 +60,21 @@ void main() {
test('URL redirect on 301 and fetch data', () async {
String resp = '';
final request =
await client.getUrl(Uri.parse('http://localhost:5256/301'));
await client.getUrl(Uri.parse('http://$host:$port'));
final success =
await request.registerCallbacks((data, bytesRead, responseCode) {
resp += utf8.decoder.convert(data);
}, onRedirectReceived: (location, responseCode) {
expect(responseCode, equals(301));
expect(location, equals('http://localhost:5256/'));
expect(location, equals('http://$host:$port'));
});
expect(resp, equals(sentData));
expect(success, equals(true));
});

test('registering callbacks after response.close will throw error',
() async {
final request = await client.getUrl(Uri.parse('http://localhost:5256'));
final request = await client.getUrl(Uri.parse('http://$host:$port'));
await request.close();
expect(request.registerCallbacks((data, bytesRead, responseCode) {}),
throwsA(isA<ResponseListenerException>()));
unsuitable001 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
18 changes: 10 additions & 8 deletions test/http_responses_test.dart
Expand Up @@ -7,15 +7,17 @@ import 'dart:io';

import 'package:cronet/cronet.dart';
import 'package:test/test.dart';
import 'test_utils.dart';

void main() {
group('http_responses_test', () {
late HttpClient client;
late HttpServer server;
final sentData = 'Hello, world!';
late int port;
setUp(() async {
client = HttpClient();
server = await HttpServer.bind(InternetAddress.anyIPv6, 5252);
server = await HttpServer.bind(InternetAddress.anyIPv6, 0);
unsuitable001 marked this conversation as resolved.
Show resolved Hide resolved
port = server.port;
server.listen((HttpRequest request) {
if (request.method == 'CUSTOM') {
request.response.write(request.method);
Expand All @@ -27,14 +29,14 @@ void main() {
});

test('Gets Hello, world response from server using getUrl', () async {
final request = await client.getUrl(Uri.parse('http://localhost:5252'));
final request = await client.getUrl(Uri.parse('http://$host:$port'));
final resp = await request.close();
final dataStream = resp.transform(utf8.decoder);
expect(dataStream, emitsInOrder(<Matcher>[equals(sentData), emitsDone]));
});

test('Gets Hello, world response from server using get method', () async {
final request = await client.get('localhost', 5252, '/');
final request = await client.get(host, port, '/');
final resp = await request.close();
final dataStream = resp.transform(utf8.decoder);
expect(dataStream, emitsInOrder(<Matcher>[equals(sentData), emitsDone]));
Expand All @@ -43,7 +45,7 @@ void main() {
test('Gets Hello, world response from server using openUrl method',
() async {
final request =
await client.openUrl('GET', Uri.parse('http://localhost:5252'));
await client.openUrl('GET', Uri.parse('http://$host:$port'));
final resp = await request.close();
final dataStream = resp.transform(utf8.decoder);
expect(dataStream, emitsInOrder(<Matcher>[equals(sentData), emitsDone]));
Expand All @@ -53,23 +55,23 @@ void main() {
'Fetch Hello, world response from server using openUrl, custom method method',
() async {
final request =
await client.openUrl('CUSTOM', Uri.parse('http://localhost:5252'));
await client.openUrl('CUSTOM', Uri.parse('http://$host:$port'));
final resp = await request.close();
final dataStream = resp.transform(utf8.decoder);
expect(dataStream, emitsInOrder(<Matcher>[equals('CUSTOM'), emitsDone]));
});

test('Fetch Hello, world response from server using POST request',
() async {
final request = await client.postUrl(Uri.parse('http://localhost:5252'));
final request = await client.postUrl(Uri.parse('http://$host:$port'));
final resp = await request.close();
final dataStream = resp.transform(utf8.decoder);
expect(dataStream, emitsInOrder(<Matcher>[equals(sentData), emitsDone]));
});

test('response.close after registering callbacks will throw error',
() async {
final request = await client.postUrl(Uri.parse('http://localhost:5252'));
final request = await client.postUrl(Uri.parse('http://$host:$port'));
request.registerCallbacks((data, bytesRead, responseCode) {});
expect(request.close(), throwsA(isA<ResponseListenerException>()));
});
Expand Down
2 changes: 2 additions & 0 deletions test/test_utils.dart
@@ -0,0 +1,2 @@
const host = 'localhost';
unsuitable001 marked this conversation as resolved.
Show resolved Hide resolved
const sentData = 'Hello, world!';