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

Conversation

unsuitable001
Copy link
Contributor

@unsuitable001 unsuitable001 commented Jun 12, 2021

Summary

  1. HttpClient with QUIC, HTTP2, brotli support
  2. HttpClient with a customizable user agent string
  3. HttpClient close method (without force close)
  4. open, openUrl & other associated methods.
  5. Response is consumable using dart:io style API.
  6. Different types of Exceptions are implemented.

Notes and Breaking Changes from dart:io

  1. Custom SecurityContext is no longer handled by the client. Users have to handle it in other ways. (To be documented later)

  2. userAgent property is now read-only. Custom userAgent should be passed as a constructor argument.

  3. Force close isn't enabled in this PR.

Partial migration from: unsuitable001/dart_cronet_sample

Copy link
Contributor

@mannprerak2 mannprerak2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 1 of review.

.gitignore Outdated Show resolved Hide resolved
.pubignore Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
analysis_options.yaml Outdated Show resolved Hide resolved
analysis_options.yaml Outdated Show resolved Hide resolved
analysis_options.yaml Outdated Show resolved Hide resolved
lib/src/find_resource.dart Outdated Show resolved Hide resolved
lib/src/find_resource.dart Outdated Show resolved Hide resolved
fixed un-nessesary removal of code from .gitignore
refined analysis options
added changelog
@unsuitable001
Copy link
Contributor Author

unsuitable001 commented Jun 13, 2021

Round 1 of review.

Done. Please check the changes :)

Copy link
Contributor

@mannprerak2 mannprerak2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 1.1 of review.

.gitignore Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
lib/src/http_callback_handler.dart Outdated Show resolved Hide resolved
@mannprerak2
Copy link
Contributor

@unsuitable001 You can remove the empty analysis_options.yaml files from your example projects, instead add this in their pubspec.yaml -

dev_dependencies:  
  ...
  lints: ^1.0.1

Copy link
Contributor

@mannprerak2 mannprerak2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 2 of review.

analysis_options.yaml Outdated Show resolved Hide resolved
lib/src/generated_bindings.dart Outdated Show resolved Hide resolved
test/http_client_close_test.dart Outdated Show resolved Hide resolved
test/http_responses_exceptions_test.dart Outdated Show resolved Hide resolved
lib/src/http_client_response.dart Outdated Show resolved Hide resolved
lib/src/http_client_response.dart Outdated Show resolved Hide resolved
behaviour change: If registerCallbacks & close api is used togather, the later called on will resolve with a RequestListenerException.
@unsuitable001
Copy link
Contributor Author

unsuitable001 commented Jun 13, 2021

Round 1.1 of review.
Round 2 of review.

@mannprerak2 Resolved the issues. Please check :) I've also trimmed the flutter example. When you're done reviewing the existing, I'll add the actual one.

…lback's

`next` callback is removed. It is now called directly.

refactor: docs and cleaned api detection
@unsuitable001
Copy link
Contributor Author

@dcharkes @mannprerak2 Some changes and small fix for registerCallback api is pushed and added tests for it.

Copy link
Contributor

@mannprerak2 mannprerak2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 3 of review.

test/http_responses_exceptions_test.dart Outdated Show resolved Hide resolved
test/http_responses_test.dart Outdated Show resolved Hide resolved
@unsuitable001
Copy link
Contributor Author

unsuitable001 commented Jun 15, 2021

@mannprerak2 Changes done :)

oppsie again. :) forgot to put newline between few as they cross that 80char limit. I'll push that with next review's changes.

test/test_utils.dart Outdated Show resolved Hide resolved
Copy link
Member

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far! 👌

Here's my first round of comments.

Maybe we should remove flutter support from this PR and do it in a next one. Then we can focus on getting the dart standalone setup (package-wise, code-layout-wise, CI-wise) right in this PR, and focus on those aspects for Flutter in a follow up CL.

README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
.pubignore Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
lib/src/native/wrapper/wrapper.cc Outdated Show resolved Hide resolved
lib/src/native/wrapper/wrapper.h Outdated Show resolved Hide resolved
lib/src/prepare_cronet.dart Outdated Show resolved Hide resolved
lib/src/prepare_cronet.dart Outdated Show resolved Hide resolved

/// Download [cronet] library
/// from Github Releases
Future<void> downloadCronetBinaries(String platform) async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a buildCronetBinaries as well? (Automating the steps you did locally to build the binary.)

That way we can just run buildCronetBinaries when we want to make the binaries for a new version.

Also, that would enable users to build instead of download if they so prefer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this build utility to build the wrapper for that custom version and print the link to build cronet in the console. Should we also take the responsibility for building actual cronet binaries? I guess that may turn out to be a little bit hard to maintain. What's your view?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you need to build the libcronet.xxxx.so/dll yourself also right? It would be useful to have the steps to do that as a Dart script, so that you don't forget.

We can either have that script in tool/update_cronet.dart so that you can update the shared libraries with a simple step, or we can have it available in bin/setup.dart as dart run cronet:build-cronet (or something similar).

lib/src/native/include/dart/dart_api_dl.h Outdated Show resolved Hide resolved
@unsuitable001
Copy link
Contributor Author

@dcharkes Done with this round of changes. 😃

@unsuitable001
Copy link
Contributor Author

unsuitable001 commented Jun 27, 2021

Review of Dart public API and tests. (Internal Dart code and C/C++ code review pending.)

@dcharkes Done with this round of changes. There are few queries in some of the review threads. Waiting for your thoughts on them.

Other than that, there's a change on what we discussed before.
Discussed: Expose addresses of callbacks from wrapper bindings and pass them to cronet for registration.

Change: Exposed few cronet function pointers and passed them to the wrapper.

Reason: The executor (thread) we're using is written in C/C++ and a part of the wrapper. So, we've to expose few cronet apis to make executor work. And, wrapper also handles few memory management tasks (e.g. finalizers etc.) for us. So, I decided to keep the pattern and expose the function for registering callbacks to the wrapper.

Copy link
Member

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next round of comments

README.md Outdated Show resolved Hide resolved
lib/src/third_party/cronet/ffigen.yaml Outdated Show resolved Hide resolved
lib/src/third_party/cronet/ffigen.yaml Outdated Show resolved Hide resolved
lib/src/third_party/cronet/ffigen.yaml Show resolved Hide resolved
lib/src/third_party/cronet/ffigen.yaml Outdated Show resolved Hide resolved
lib/src/http_callback_handler.dart Outdated Show resolved Hide resolved
lib/src/http_callback_handler.dart Outdated Show resolved Hide resolved
third_party/cronet_impl/sample_executor.h Show resolved Hide resolved
third_party/cronet_impl/sample_executor.cc Outdated Show resolved Hide resolved
lib/src/http_callback_handler.dart Outdated Show resolved Hide resolved
src/wrapper.cc Outdated Show resolved Hide resolved
third_party/cronet_impl/sample_executor.h Show resolved Hide resolved
bin/setup.dart Outdated Show resolved Hide resolved
README.md Outdated

```bash
dart pub get
dart run cronet <platform> # Downloads the cronet binaries.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dart run cronet:setup

@@ -0,0 +1,201 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I like how this is set up!

requestParams, _method.toNativeUtf8().cast<Int8>());
wrapper.InitSampleExecutor(_callbackHandler.executor);

final cronetCallbacks = cronet.Cronet_UrlRequestCallback_CreateWith(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a TODO with a reference to the relevant ffigen issue with regard to the casts.

@unsuitable001
Copy link
Contributor Author

unsuitable001 commented Jul 2, 2021

@dcharkes Typos are fixed and ffigen issue reference added. Tell Google to make a AI typo finder for me :p (Autocorrect for programmers)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants