Skip to content

Commit e6dc3e6

Browse files
authored
Add a http Client implementation based on Cronet (#747)
1 parent cfa9128 commit e6dc3e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2189
-0
lines changed

.github/workflows/cronet.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: package:cronet_http CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
paths:
9+
- 'pkgs/cronet_http/**'
10+
- 'pkgs/http_client_conformance_tests/**'
11+
pull_request:
12+
paths:
13+
- 'pkgs/cronet_http/**'
14+
- 'pkgs/http_client_conformance_tests/**'
15+
schedule:
16+
- cron: "0 0 * * 0"
17+
18+
env:
19+
PUB_ENVIRONMENT: bot.github
20+
21+
jobs:
22+
analyze:
23+
name: Lint and static analysis
24+
runs-on: ubuntu-latest
25+
defaults:
26+
run:
27+
working-directory: pkgs/cronet_http
28+
steps:
29+
- uses: actions/checkout@v3
30+
- uses: subosito/flutter-action@v2
31+
with:
32+
# TODO: Change to 'stable' when a release version of flutter
33+
# pins version 1.21.1 or later of 'package:test'
34+
channel: 'master'
35+
- id: install
36+
name: Install dependencies
37+
run: flutter pub get
38+
- name: Check formatting
39+
run: flutter format --output=none --set-exit-if-changed .
40+
if: always() && steps.install.outcome == 'success'
41+
- name: Analyze code
42+
run: flutter analyze --fatal-infos
43+
if: always() && steps.install.outcome == 'success'
44+
45+
test:
46+
# Test package:cupertino_http use flutter integration tests.
47+
needs: analyze
48+
name: "Build and test"
49+
runs-on: macos-latest
50+
steps:
51+
- uses: actions/checkout@v3
52+
- uses: actions/setup-java@v3
53+
with:
54+
distribution: 'zulu'
55+
java-version: '17'
56+
- uses: subosito/flutter-action@v2
57+
with:
58+
# TODO: Change to 'stable' when a release version of flutter
59+
# pins version 1.21.1 or later of 'package:test'
60+
channel: 'master'
61+
- name: Run tests
62+
uses: reactivecircus/android-emulator-runner@v2
63+
with:
64+
api-level: 32
65+
target: playstore
66+
arch: x86_64
67+
profile: pixel
68+
script: cd ./pkgs/cronet_http/example && flutter pub get && flutter --version && flutter -v test integration_test/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ and the browser.
1212
|---|---|---|
1313
| [http](pkgs/http/) | A composable, multi-platform, Future-based API for HTTP requests. | [![pub package](https://img.shields.io/pub/v/http.svg)](https://pub.dev/packages/http) |
1414
| [http_client_conformance_tests](pkgs/http_client_conformance_tests/) | A library that tests whether implementations of package:http's `Client` class behave as expected. | |
15+
| [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. | |
1516
| [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) |

pkgs/cronet_http/.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# pigeon generated code
2+
lib/src/messages.dart linguist-generated
3+
android/src/main/java/io/flutter/plugins/cronet_http/Messages.java

pkgs/cronet_http/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
.gradle/

pkgs/cronet_http/.metadata

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled.
5+
6+
version:
7+
revision: 85684f9300908116a78138ea4c6036c35c9a1236
8+
channel: stable
9+
10+
project_type: plugin
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 85684f9300908116a78138ea4c6036c35c9a1236
17+
base_revision: 85684f9300908116a78138ea4c6036c35c9a1236
18+
- platform: android
19+
create_revision: 85684f9300908116a78138ea4c6036c35c9a1236
20+
base_revision: 85684f9300908116a78138ea4c6036c35c9a1236
21+
22+
# User provided section
23+
24+
# List of Local paths (relative to this file) that should be
25+
# ignored by the migrate tool.
26+
#
27+
# Files that are not part of the templates will be ignored by default.
28+
unmanaged_files:
29+
- 'lib/main.dart'
30+
- 'ios/Runner.xcodeproj/project.pbxproj'

pkgs/cronet_http/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2022, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/cronet_http/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
An Android Flutter plugin that provides access to the
2+
[Cronet](https://developer.android.com/guide/topics/connectivity/cronet/reference/org/chromium/net/package-summary)
3+
HTTP client.
4+
5+
Cronet is available as part of
6+
[Google Play Services](https://developers.google.com/android/guides/overview).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include: ../../analysis_options.yaml
2+
3+
analyzer:
4+
exclude:
5+
- lib/src/messages.dart
6+
- pigeons/messages.dart

pkgs/cronet_http/android/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.cxx

pkgs/cronet_http/android/build.gradle

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
group 'io.flutter.plugins.cronet_http'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
ext.kotlin_version = '1.6.10'
6+
repositories {
7+
google()
8+
mavenCentral()
9+
}
10+
11+
dependencies {
12+
classpath 'com.android.tools.build:gradle:7.1.2'
13+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14+
}
15+
}
16+
17+
rootProject.allprojects {
18+
repositories {
19+
google()
20+
mavenCentral()
21+
}
22+
}
23+
24+
apply plugin: 'com.android.library'
25+
apply plugin: 'kotlin-android'
26+
27+
android {
28+
compileSdkVersion 31
29+
30+
compileOptions {
31+
sourceCompatibility JavaVersion.VERSION_1_8
32+
targetCompatibility JavaVersion.VERSION_1_8
33+
}
34+
35+
kotlinOptions {
36+
jvmTarget = '1.8'
37+
}
38+
39+
sourceSets {
40+
main.java.srcDirs += 'src/main/kotlin'
41+
main.java.srcDirs += 'src/main/java'
42+
}
43+
44+
defaultConfig {
45+
minSdkVersion 16
46+
}
47+
}
48+
49+
dependencies {
50+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
51+
implementation "com.google.android.gms:play-services-cronet:18.0.1"
52+
}

0 commit comments

Comments
 (0)