From e9510d06c5f7773b1cf8fbe10688f5b469f9aa79 Mon Sep 17 00:00:00 2001 From: "artem.abramov" Date: Wed, 4 Oct 2023 18:45:02 +0400 Subject: [PATCH] Removed http package due to conflicts with old packages --- CHANGELOG.md | 3 + README.md | 3 +- lib/alice.dart | 18 ++---- lib/core/alice_http_adapter.dart | 88 ----------------------------- lib/core/alice_http_extensions.dart | 12 ---- pubspec.lock | 8 --- pubspec.yaml | 3 +- 7 files changed, 12 insertions(+), 123 deletions(-) delete mode 100644 lib/core/alice_http_adapter.dart delete mode 100644 lib/core/alice_http_extensions.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 68b4aedd..e34b16ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [3.5.1] +- Removed `http` package due to conflicts with old packages + ## [3.5.0] - Bump dependencies diff --git a/README.md b/README.md index 6d081196..70bf5aa9 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,5 @@ Removed the following dependencies: - shake - chopper: ^3.0.2 - chewie: ^0.9.10 -- video_player: ^0.10.8+1 \ No newline at end of file +- video_player: ^0.10.8+1 +- http: ^1.1.0 \ No newline at end of file diff --git a/lib/alice.dart b/lib/alice.dart index b4f0b284..ebfdfc7a 100644 --- a/lib/alice.dart +++ b/lib/alice.dart @@ -1,8 +1,6 @@ import 'dart:io'; -import 'package:alice_lightweight/core/alice_http_adapter.dart'; import 'package:alice_lightweight/model/alice_http_call.dart'; -import 'package:http/http.dart' as http; import 'package:alice_lightweight/core/alice_core.dart'; import 'package:alice_lightweight/core/alice_dio_interceptor.dart'; import 'package:alice_lightweight/core/alice_http_client_adapter.dart'; @@ -16,10 +14,13 @@ class Alice { GlobalKey _navigatorKey; AliceCore _aliceCore; AliceHttpClientAdapter _httpClientAdapter; - AliceHttpAdapter _httpAdapter; - Alice._(this.darkTheme, this._navigatorKey, this._aliceCore, - this._httpClientAdapter, this._httpAdapter); + Alice._( + this.darkTheme, + this._navigatorKey, + this._aliceCore, + this._httpClientAdapter, + ); /// Creates alice instance. factory Alice({ @@ -29,14 +30,12 @@ class Alice { }) { final aliceCore = AliceCore(navigatorKey, darkTheme); final httpClientAdapter = AliceHttpClientAdapter(aliceCore); - final httpAdapter = AliceHttpAdapter(aliceCore); return Alice._( darkTheme, navigatorKey, aliceCore, httpClientAdapter, - httpAdapter, ); } @@ -67,11 +66,6 @@ class Alice { _httpClientAdapter.onResponse(response, request, body: body); } - /// Handle both request and response from http package - void onHttpResponse(http.Response response, {dynamic body}) { - _httpAdapter.onResponse(response, body: body); - } - /// Opens Http calls inspector. This will navigate user to the new fullscreen /// page where all listened http calls can be viewed. void showInspector() { diff --git a/lib/core/alice_http_adapter.dart b/lib/core/alice_http_adapter.dart deleted file mode 100644 index 2cfde996..00000000 --- a/lib/core/alice_http_adapter.dart +++ /dev/null @@ -1,88 +0,0 @@ -import 'dart:convert'; - -import 'package:alice_lightweight/core/alice_core.dart'; -import 'package:alice_lightweight/model/alice_http_call.dart'; -import 'package:alice_lightweight/model/alice_http_request.dart'; -import 'package:alice_lightweight/model/alice_http_response.dart'; -import 'package:http/http.dart' as http; - -class AliceHttpAdapter { - /// AliceCore instance - final AliceCore aliceCore; - - /// Creates alice http adapter - AliceHttpAdapter(this.aliceCore); - - /// Handles http response. It creates both request and response from http call - void onResponse(http.Response response, {dynamic body}) { - if (response.request == null) { - return; - } - var request = response.request; - - if (request == null) { - return; - } - - AliceHttpCall call = AliceHttpCall(response.request.hashCode); - call.loading = true; - call.client = "HttpClient (http package)"; - call.uri = request.url.toString(); - call.method = request.method; - var path = request.url.path; - if (path.length == 0) { - path = "/"; - } - call.endpoint = path; - - call.server = request.url.host; - if (request.url.scheme == "https") { - call.secure = true; - } - - AliceHttpRequest httpRequest = AliceHttpRequest(); - - if (response.request is http.Request) { - // we are guranteed the existence of body and headers - httpRequest.body = body ?? (response.request as http.Request).body ?? ""; - httpRequest.size = utf8.encode(httpRequest.body.toString()).length; - httpRequest.headers = Map.from(response.request?.headers ?? {}); - } else if (body == null) { - httpRequest.size = 0; - httpRequest.body = ""; - } else { - httpRequest.size = utf8.encode(body.toString()).length; - httpRequest.body = body; - } - - httpRequest.time = DateTime.now(); - - String contentType = "unknown"; - if (httpRequest.headers.containsKey("Content-Type")) { - contentType = httpRequest.headers["Content-Type"]; - } - - httpRequest.contentType = contentType; - - httpRequest.queryParameters = response.request?.url.queryParameters ?? {}; - - AliceHttpResponse httpResponse = AliceHttpResponse(); - httpResponse.status = response.statusCode; - httpResponse.body = response.body; - - httpResponse.size = utf8.encode(response.body.toString()).length; - httpResponse.time = DateTime.now(); - Map responseHeaders = Map(); - response.headers.forEach((header, values) { - responseHeaders[header] = values.toString(); - }); - httpResponse.headers = responseHeaders; - - call.request = httpRequest; - call.response = httpResponse; - - call.loading = false; - call.duration = 0; - aliceCore.addCall(call); - } -} diff --git a/lib/core/alice_http_extensions.dart b/lib/core/alice_http_extensions.dart deleted file mode 100644 index bb3404c1..00000000 --- a/lib/core/alice_http_extensions.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:alice_lightweight/alice.dart'; -import 'package:http/http.dart'; - -extension AliceHttpExtensions on Future { - /// Intercept http request with alice. This extension method provides additional - /// helpful method to intercept https' response. - Future interceptWithAlice(Alice alice, {dynamic body}) async { - Response response = await this; - alice.onHttpResponse(response, body: body); - return response; - } -} diff --git a/pubspec.lock b/pubspec.lock index e41fef3f..81b25ef9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -75,14 +75,6 @@ packages: description: flutter source: sdk version: "0.0.0" - http: - dependency: "direct main" - description: - name: http - sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525" - url: "https://pub.dev" - source: hosted - version: "1.1.0" http_parser: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6bd94120..24de2713 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: alice_lightweight description: Lightweight Alice version. Removed additional dependencies except dio. -version: 3.5.0 +version: 3.5.1 homepage: https://github.com/jhomlala/alice environment: @@ -9,7 +9,6 @@ environment: dependencies: flutter: sdk: flutter - http: ^1.1.0 dio: ^5.3.3 rxdart: ^0.27.7 share_plus: ^7.1.0