Skip to content

Commit

Permalink
chore: removed http and replaced with AWSHttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
khatruong2009 committed Sep 7, 2023
1 parent 88b5be7 commit 2180b93
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This is a generated file; do not edit or check into version control.
path_provider=/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider-2.1.1/
path_provider_android=/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_android-2.2.0/
path_provider_foundation=/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/
path_provider_linux=/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/
path_provider_windows=/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_android-2.2.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2023-09-07 15:25:43.661957","version":"3.10.6"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This is a generated file; do not edit or check into version control.
path_provider=/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider-2.1.1/
path_provider_android=/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_android-2.2.0/
path_provider_foundation=/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/
path_provider_linux=/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/
path_provider_windows=/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_android-2.2.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/ktruon/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2023-09-07 15:25:43.712619","version":"3.10.6"}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'package:aws_logging_cloudwatch/src/file_storage/file_storage.vm.dart'
if (dart.library.html) 'package:aws_logging_cloudwatch/src/file_storage/file_storage.web.dart'
as storage;
import 'package:aws_signature_v4/aws_signature_v4.dart';
import 'package:http/http.dart' as http;

/// {@template aws_logging_cloudwatch.remote_logging_constraint_provider}
/// An Interface to provide custom implementation for
Expand Down Expand Up @@ -51,6 +50,8 @@ class DefaultRemoteLoggingConstraintProvider
/// The signer to sign the request.
static const _signer = AWSSigV4Signer();

final AWSHttpClient _awsHttpClient = AWSHttpClient();

// The timer to refresh the constraint periodically.
Timer? _timer;

Expand Down Expand Up @@ -91,7 +92,13 @@ class DefaultRemoteLoggingConstraintProvider
Future<LoggingConstraint?> _fetchConstraintFromEndpoint() async {
final uri = Uri.parse(_config.endpoint);

final request = AWSHttpRequest.get(uri);
final request = AWSHttpRequest(
method: AWSHttpMethod.get,
uri: uri,
headers: {
AWSHeaders.host: uri.host,
},
);

final scope = AWSCredentialScope(
region: _config.region,
Expand All @@ -103,21 +110,24 @@ class DefaultRemoteLoggingConstraintProvider
credentialScope: scope,
);

final headers = signedRequest.headers.map<String, String>(
MapEntry<String, String>.new,
);

final response = await http.get(
uri,
final newRequest = AWSHttpRequest(
method: signedRequest.method,
uri: signedRequest.uri,
headers: {
...headers,
...signedRequest.headers,
AWSHeaders.accept: 'application/json; charset=utf-8',
},
);

final operation = _awsHttpClient.send(newRequest);

final response = await operation.response;

final body = await response.decodeBody();

if (response.statusCode == 200) {
final fetchedConstraint = LoggingConstraint.fromJson(
jsonDecode(response.body) as Map<String, dynamic>,
jsonDecode(body) as Map<String, dynamic>,
);
return fetchedConstraint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dependencies:
fixnum: ^1.1.0
flutter:
sdk: flutter
http: ^1.0.0
intl: ">=0.18.0 <1.0.0"
json_annotation: ^4.8.1
meta: ^1.9.1
Expand Down

0 comments on commit 2180b93

Please sign in to comment.