1
0
mirror of https://github.com/go-vikunja/app synced 2024-06-02 18:49:47 +00:00

fix: use platform-specific HTTP client (fixes go-vikunja/app#66)

This commit is contained in:
Denys Vitali 2024-03-26 22:10:58 +01:00
parent facadb5d8f
commit 3025e10861
No known key found for this signature in database
GPG Key ID: 5227C664145098BC
3 changed files with 57 additions and 4 deletions

View File

@ -1,8 +1,11 @@
import 'dart:convert';
import 'dart:core';
import 'dart:io';
import 'package:cronet_http/cronet_http.dart' as cronet_http;
import 'package:cupertino_http/cupertino_http.dart' as cupertino_http;
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart' as io_client;
import 'package:vikunja_app/api/response.dart';
import 'package:vikunja_app/components/string_extension.dart';
import 'package:vikunja_app/global.dart';
@ -33,6 +36,22 @@ class Client {
configure(token: token, base: base, authenticated: authenticated);
}
http.Client get httpClient {
if (Platform.isAndroid) {
final engine = cronet_http.CronetEngine.build(
cacheMode: cronet_http.CacheMode.memory, cacheMaxSize: 1000000);
return cronet_http.CronetClient.fromCronetEngine(engine);
}
if (Platform.isIOS || Platform.isMacOS) {
final config =
cupertino_http.URLSessionConfiguration.ephemeralSessionConfiguration()
..cache =
cupertino_http.URLCache.withCapacity(memoryCapacity: 1000000);
return cupertino_http.CupertinoClient.fromSessionConfiguration(config);
}
return io_client.IOClient();
}
void reloadIgnoreCerts(bool? val) {
ignoreCertificates = val ?? false;
HttpOverrides.global = new IgnoreCertHttpOverrides(ignoreCertificates);
@ -84,14 +103,14 @@ class Client {
queryParameters: queryParameters,
fragment: uri.fragment);
return http
return httpClient
.get(uri, headers: _headers)
.then(_handleResponse)
.onError((error, stackTrace) => _handleError(error, stackTrace));
}
Future<Response?> delete(String url) {
return http
return httpClient
.delete(
'${this.base}$url'.toUri()!,
headers: _headers,
@ -101,7 +120,7 @@ class Client {
}
Future<Response?> post(String url, {dynamic body}) {
return http
return httpClient
.post(
'${this.base}$url'.toUri()!,
headers: _headers,
@ -112,7 +131,7 @@ class Client {
}
Future<Response?> put(String url, {dynamic body}) {
return http
return httpClient
.put(
'${this.base}$url'.toUri()!,
headers: _headers,

View File

@ -169,6 +169,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.7.2"
cronet_http:
dependency: "direct main"
description:
name: cronet_http
sha256: "9b9f00ae48971bc8a8cbdd4528bd35511adce00fb79d1ebf9f9907667056640f"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
crypto:
dependency: transitive
description:
@ -185,6 +193,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.0"
cupertino_http:
dependency: "direct main"
description:
name: cupertino_http
sha256: "20c167fd843c9ff6fc25cc4a0e8efa4180dfe119fb6d18c3c55104113e9cfc6f"
url: "https://pub.dev"
source: hosted
version: "1.4.0"
cupertino_icons:
dependency: "direct main"
description:
@ -592,6 +608,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.4"
jni:
dependency: transitive
description:
name: jni
sha256: "499558e919997adfc45809a66caf0b95b91393e23289dd2826b152f8f04e6611"
url: "https://pub.dev"
source: hosted
version: "0.7.3"
js:
dependency: transitive
description:
@ -1341,6 +1365,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.5.1"
web_socket:
dependency: transitive
description:
name: web_socket
sha256: "3f81fde6fbc799d03c0fb3f2c3ac84368ee267012a4beb876685c029946da4e0"
url: "https://pub.dev"
source: hosted
version: "0.1.0"
web_socket_channel:
dependency: transitive
description:

View File

@ -38,6 +38,8 @@ dependencies:
timezone: ^0.9.2
json_annotation: ^4.8.1
collection: ^1.18.0
cupertino_http: ^1.4.0
cronet_http: ^1.2.0
dev_dependencies:
flutter_test:
sdk: flutter