This package binds to Cronet's native API to expose them in Dart.

Overview

Experimental Cronet Dart bindings

This package binds to Cronet's native API to expose them in Dart.

This is an HTTP Client Package with almost the same API as dart:io. By comparison, package:cronet is capable of serving about 4 to 5 times more parallel network requests than dart:io and on par in making sequential network requests.

This is a GSoC 2021 project.

Supported Platforms

Currently, 64 bit Desktop Platforms (Linux, Windows and MacOS) are supported.

Requirements

  1. Dart SDK 2.12.0 or above.
  2. CMake 3.15 or above. (If on windows, Visual Studio 2019 with C++ tools)
  3. C++ compiler. (g++/clang/msvc)

Usage

  1. Add package as a dependency in your pubspec.yaml.

  2. Run this from the root of your project.

    Dart CLI

    dart pub get
    dart run cronet:setup # Downloads the cronet binaries.
  3. Import

    import 'package:cronet/cronet.dart';

Note: Internet connection is required to download cronet binaries.

Example

  final client = HttpClient();
  client
      .getUrl(Uri.parse('http://info.cern.ch/'))
      .then((HttpClientRequest request) {
    return request.close();
  }).then((HttpClientResponse response) {
    response.transform(utf8.decoder).listen((contents) {
      print(contents);
    },
      onDone: () => print(
        'Done!'));
  });

See the API comparison with dart:io.

Run Example

cd example
dart run cronet:setup # Downloads the cronet binaries.
dart run

Run Tests

dart pub get
dart run cronet:setup # Downloads the cronet binaries.
dart test --platform vm

You can also verify your cronet binaries using dart run cronet:setup verify. Make sure to have cmake 3.15.

Benchmarking

See benchmark summary and extensive reports for comparison with dart:io.

dart pub get
dart run cronet:setup # Downloads the cronet binaries.
dart run benchmark/latency.dart # For sequential requests benchmark.
dart run benchmark/throughput.dart # For parallel requests benchmark.
dart run benchmark/run_all.dart # To run all the benchmarks and get reports.

Use -h to see available cli arguments and usage informations.

To know how to setup local test servers, read benchmarking guide.

Note: Test results may get affected by: https://github.com/google/cronet.dart/issues/11.

Building Your Own

  1. Make sure you've downloaded your custom version of cronet shared library and filename follows the pattern cronet.86.0.4240.198.<extension> with a prefix lib if on linux. Else, you can build cronet from source using the provided instuctions. Then copy the library to the designated folder. For linux, the files are under .dart_tool/cronet/linux64.

  2. Run dart run cronet:setup build from the root of your project.

Note for Windows: Run step 2 from x64 Native Tools Command Prompt for VS 2019 shell.

Comments
  • Flutter support

    Flutter support

    Add Flutter Support, covering all of the native platforms.

    Platforms -

    • [x] Android
    • [x] Linux
    • [x] Windows

    MacOS & iOS will be done separately.

    This PR only takes care of 64bit systems. For 32 bit systems, issue #20 should be tracked.

    Reference #5

    opened by unsuitable001 11
  • benchmark: cronet benchmarks and comparison with dart:io

    benchmark: cronet benchmarks and comparison with dart:io

    Benchmarks

    Package Version: 0.0.1+1 Cronet Version: 86.0.4240.198 Cronet Build Type: Debug Wrapper Version: 1 Dart SDK Version: 2.12.0

    • [x] Latency
      • [x] Writing Benchmarking Code
      • [x] Gathering observations in different environments and writing reports
      • [x] Comparing with dart:io
    • [x] Throughput
      • [x] Writing Benchmarking Code
      • [x] Gathering observations in different environments and writing reports
      • [x] Comparing with dart:io

    May get affected by #11

    Closes #3

    opened by unsuitable001 10
  • Benchmarks

    Benchmarks

    We should get an understanding of how package:cronet stacks up against dart:io. Cronet is not integrated into the Dart VM which might create some overhead. On the other hand Cronet provides HTTP 2 and QUIC.

    We should add a benchmarks/ folder. Some inspiration from setting up benchmarks can be done from https://github.com/dart-lang/sdk/blob/master/benchmarks/MapLookup/dart/MapLookup.dart.

    We are interested in multiple dimensions:

    • JIT (dart ...) and AOT (dart compile exe ...).
    • Latency (how fast can a single request be) and throughput (how many concurrent requests per second can we do) - tested by doing only sequential requests and parallel requests respectively.
    opened by dcharkes 8
  • Migrate Essentials v0.0.1: Implement Client with openUrl method

    Migrate Essentials v0.0.1: Implement Client with openUrl method

    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

    opened by unsuitable001 8
  • benchmark: maintain no. of parallel requests in throughput benchmark

    benchmark: maintain no. of parallel requests in throughput benchmark

    Spawn a new request when any request is returned within stipulated time duration in case of throughput benchmark to maintain the number of parallel requests performed.

    Closes #16

    opened by unsuitable001 7
  • move to package:args for cli arg parsing

    move to package:args for cli arg parsing

    Continuation #8

    • Bumped up the version of every dependency package as much as possible.
    • Use package:args for CLI argument parsing.
        • [x] bin/setup.dart
        • [x] tool/ files. (Tools don't take any CLI arg)
        • [x] benchmark/ files.
    • Fixes wrong location issue in run_all.dart due to the migration from benchmarks/ to benchmark/ (#14 )
    • Fixed wrong cli suggestion in case of un-locateable dylib.
    • Fixes RangeError (index) in benchmark/throughput.dart in case of 0 result.
    • Added README.md to example folder to fetch more pub points.

    Closes #12

    opened by unsuitable001 5
  • fix: returning values instead of pointers from cronet

    fix: returning values instead of pointers from cronet

    We shouldn't return pointers that we received as a callback parameter from cronet. In a slower system or while doing bunch of requests togather (e.g. benchmarking), we can accidentally dereference those cronet created pointers after cronet frees them.

    UTF8 decoding the newLocation URL string which is received as a callback of onRedirect event causes the following error:

    Unhandled exception:
    FormatException: Unexpected extension byte (at offset .....
    

    This PR fixes this issue by dereferencing and getting the raw data from cronet created pointers in the wrapper then sending copied data to the dart side via nativeport.

    Also patched crash on parallel request if 404 is received.

    NOTE: Update Binaries.

    opened by unsuitable001 2
  • add 32 bit architecture support

    add 32 bit architecture support

    Use an array of uint64 to store the memory addresses of arguments (of cronet callbacks). On 32 bit systems, we must store the memory address on the lower 32 bits of uint64 and upper 32 bits should be padded by 0.

    Closes #20

    opened by unsuitable001 1
  • Adding user specified headers in http request

    Adding user specified headers in http request

    Adding support for user added headers while performing a request. Most common use case for this feature is setting content-type header while sending some data through POST request.

    opened by unsuitable001 0
  • add HttpClient force close feature

    add HttpClient force close feature

    Add force close (optional) parameter to HttpClient.close() method along with tests for it.

    Original API reference: https://api.dart.dev/stable/2.13.1/dart-io/HttpClient/close.html

    opened by unsuitable001 0
  • 32 Bit system support

    32 Bit system support

    Currently only 64bit systems (Android and Desktops) are compatible with this package. Support for 32 bit systems are required for older devices and Android Emulators.

    opened by unsuitable001 0
  • flutter pub run cronet:setup failed with error

    flutter pub run cronet:setup failed with error

    flutter pub run cronet:setup failed with error

    Unhandled exception: Invalid argument(s): Failed to lookup symbol 'VersionString': error code 127 #0 DynamicLibrary.lookup (dart:ffi-patch/ffi_dynamic_library_patch.dart:34:70) #1 Wrapper._VersionString_ptr (package:cronet/src/wrapper/generated_bindings.dart:34:52) #2 Wrapper._VersionString_ptr (package:cronet/src/wrapper/generated_bindings.dart) #3 Wrapper._VersionString (package:cronet/src/wrapper/generated_bindings.dart:36:7) #4 Wrapper._VersionString (package:cronet/src/wrapper/generated_bindings.dart) #5 Wrapper.VersionString (package:cronet/src/wrapper/generated_bindings.dart:30:12) #6 downloadCronetBinaries (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/cronet-0.0.7/bin/setup.dart:99:32) #7 main (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/cronet-0.0.7/bin/setup.dart:280:13) #8 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:295:32) #9 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12) pub finished with exit code 255

    [√] Flutter (Channel stable, 3.3.9, on Microsoft Windows [Version 10.0.22621.900], locale ja-JP) • Flutter version 3.3.9 on channel stable at C:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision b8f7f1f986 (3 weeks ago), 2022-11-23 06:43:51 +0900 • Engine revision 8f2221fbef • Dart version 2.18.5 • DevTools version 2.15.0

    opened by glanium 0
  • Security Policy violation Binary Artifacts

    Security Policy violation Binary Artifacts

    This issue was automatically created by Allstar.

    Security Policy Violation Project is out of compliance with Binary Artifacts policy: binaries present in source code

    Rule Description Binary Artifacts are an increased security risk in your repository. Binary artifacts cannot be reviewed, allowing the introduction of possibly obsolete or maliciously subverted executables. For more information see the Security Scorecards Documentation for Binary Artifacts.

    Remediation Steps To remediate, remove the generated executable artifacts from the repository.

    Artifacts Found

    • ios/lib/libwrapper.a

    Additional Information This policy is drawn from Security Scorecards, which is a tool that scores a project's adherence to security best practices. You may wish to run a Scorecards scan directly on this repository for more details.


    Allstar has been installed on all Google managed GitHub orgs. Policies are gradually being rolled out and enforced by the GOSST and OSPO teams. Learn more at http://go/allstar

    This issue will auto resolve when the policy is in compliance.

    Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.

    allstar 
    opened by allstar-app[bot] 78
  • Webtransport support

    Webtransport support

    Hi, thank you for this library!

    I was wondering if support for the Webtransport protocol is planned. It seems Webtransport is supported by Cronet (as its js APIs are available in Chromium/Chrome since version 97).

    Support for the Webtransport protocol would be huge in enabling Flutter developers to develop faster real-time apps and games.

    opened by nicoroy2561 0
  • Upgrade ffi to 2.0.1 and ffigen to 6.0.1

    Upgrade ffi to 2.0.1 and ffigen to 6.0.1

    Upgrade with ffi 2.0.1 and ffigen 6.0.1.

    But need upgrade:

    • cronet to actual version
    • upload new release files (libs: libcronet and libwrapper)
    • edit ./lib/src/constants.dart to new tag, cronetVersion, wrapperVersion
    opened by aospiridonov 1
  • Force Close Release APK

    Force Close Release APK

    i have clone this repo and following instruction on readme,

    and when I running the example app I have some issue like this Screen Shot 2022-02-16 at 11 42 04

    so I try to comment that line, it is worked, and I have not issue if I running on debug mode, but if I run flutter run --release or flutter build apk application always force close on emulator or real device

    Screen Shot 2022-02-16 at 17 52 28 Screen Shot 2022-02-16 at 11 46 24

    if i miss something, can you tell me please?

    opened by muhammadsaddamnur 0
Releases(binaries-v0.0.1)
Owner
Google
Google ❤️ Open Source
Google
A few handy Flutter tools, dead simple `UriRouter` for `Uri`-based navigator or `BuildTracker` to track widget rebuilds and what caused them to rebuild.

noob A few handy tools for Flutter apps. UriRouter Hooks Providers PointerIndicator BuildTracker PeriodicListenable UriRouter Dead simple Uri-based pa

null 6 Jan 18, 2022
Extension functions on ValueListenable that allows you to work with them almost as if it was a synchronous stream.

functional_listener Extension functions on ValueListenable that allows you to work with them almost as if it was a synchronous stream. Each extension

null 54 Oct 9, 2022
Dart's native integers in custom bitwidth integer format

Dart's native integers in custom bit-width formats like i2, i4, i8, i16, i32, ix and u1, u2, u4, u8, u16, u32, ux...

Aldrin's Art Factory 2 Oct 30, 2022
A simple flexible API wrapper for coinbase commerce API. Totally unofficial.

coinbase_commerce A dart library that connects to interact with the Coinbase Commerce API. Enables projects to connect seamlessly to coinbase and rece

Onuoha Obinna 3 Oct 17, 2021
A Dart package which supports checking if a current package is up-to-date.

pub_updater A Dart package which enables checking whether packages are up to date and supports updating them. Intended for use in CLIs for prompting u

Very Good Open Source 47 Oct 27, 2022
null 2 Apr 17, 2022
WhatsApp API package for flutter, to send message and product information.

WhatsApp API package for flutter, to send message and product information. Platform Support Android iOS MacOS Web Linux Windows ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ What

Rohit Chouhan 7 Nov 11, 2022
A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

Julien Scholz 10 Oct 26, 2022
Provides API to generate Dart source code

DartWriter DartWriter provides API to generate Dart source code. It can make your job easier while developing flutter/dart tools. You can also generat

Ahmet ÇELİK 11 Oct 24, 2022
Call OpenGL ES Api By Dart

Flutter GL Flutter GL can call OpenGL ES API with Dart Support iOS,Android,Web OpenGL ES API Now the api is similar to WebGL How to use Now this is on

zhaolei 163 Jan 5, 2023
A CLI tool to help generate dart classes from json returned from API

Json 2 Dart Command line utility Important note There is already a package called json2dart so this package will be called json2dartc ! This project w

Adib Mohsin 38 Oct 5, 2022
Volt is a wrapper over the Revolt API for easily writing bots using the Dart language.

Volt is a wrapper over the Revolt API for easily writing bots using the Dart language. It is currently in active development so not all of the functionality has yet been implemented.

null 8 Dec 13, 2022
An encapsulation made around openrouteservice API for Dart and Flutter projects.

An encapsulation made around openrouteservice API for Dart and Flutter projects. Made for easy generation of Routes and Directions on Maps, Isochrones, Time-Distance Matrix, Pelias Geocoding, POIs, Elevation and routing Optimizations using their amazing API.

Dhiman Seal 20 Oct 10, 2022
This is a dart library covering nearly 100% of the latest Planning Center public API.

Planning Center API for Dart Planning Center is an online platform for church management. It provides multiple apps for things like check-ins, service

null 1 Oct 6, 2022
Cache json map to local file with Dart:io. Read file with sync api.

local_cache_sync 一个非常简单易用的Flutter本地储存库,适用于在本地储存一列轻量数据(例如用户保存在本地的设备信息,或者缓存一系列用户信息)。 local_cache_sync的所有方法都是同步,而不是异步的。这意味着你不需要使用await就可以获取数据。在flutter中,这

null 16 Jun 24, 2022
Minimal Dart wrapper to interact with Some Random Api. Easy to use, simplified and lightweight.

SRA - Some Random Api Minimal Dart wrapper to interact with Some Random Api. Easy to use, simplified and lightweight. Getting started Add the package

Yakiyo 3 Jan 4, 2023
A package that lets you include a cool, nice looking and validated Password TextFormField in your app to enhance user experience. The package is fully & easily modifiable.

A package that lets you include a cool, nice looking and validated Password TextFormField in your app to enhance user experience. The package is fully

Muhammad Hamza 20 Jun 7, 2022
A Dart package to web scraping data from websites easily and faster using less code lines.

Chaleno A flutter package to webscraping data from websites This package contains a set of high-level functions that make it easy to webscrap websites

António Nicolau 30 Dec 29, 2022
A pure dart package to apply useful rate limiting strategies on regular functions.

Rate limiting is a strategy for limiting an action. It puts a cap on how often someone can repeat an action within a certain timeframe. Using rate_limiter we made it easier than ever to apply these strategies on regular dart functions.

Stream 24 Dec 14, 2022