Fixed client analysis warnings
This commit is contained in:
parent
e219b91424
commit
3fe1778c27
3 changed files with 23 additions and 28 deletions
|
@ -1,10 +1,6 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:http/src/base_client.dart' as http;
|
import 'package:http/http.dart';
|
||||||
import 'package:http/src/base_request.dart' as http;
|
|
||||||
import 'package:http/src/request.dart' as http;
|
|
||||||
import 'package:http/src/response.dart' as http;
|
|
||||||
import 'package:http/src/streamed_response.dart' as http;
|
|
||||||
import 'package:path/path.dart';
|
import 'package:path/path.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'angel3_client.dart';
|
import 'angel3_client.dart';
|
||||||
|
@ -19,10 +15,10 @@ Map<String, String> _buildQuery(Map<String, dynamic>? params) {
|
||||||
return params?.map((k, v) => MapEntry(k, v.toString())) ?? {};
|
return params?.map((k, v) => MapEntry(k, v.toString())) ?? {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _invalid(http.Response response) =>
|
bool _invalid(Response response) =>
|
||||||
response.statusCode < 200 || response.statusCode >= 300;
|
response.statusCode < 200 || response.statusCode >= 300;
|
||||||
|
|
||||||
AngelHttpException failure(http.Response response,
|
AngelHttpException failure(Response response,
|
||||||
{error, String? message, StackTrace? stack}) {
|
{error, String? message, StackTrace? stack}) {
|
||||||
try {
|
try {
|
||||||
var v = json.decode(response.body);
|
var v = json.decode(response.body);
|
||||||
|
@ -50,7 +46,7 @@ abstract class BaseAngelClient extends Angel {
|
||||||
final StreamController<AngelAuthResult> _onAuthenticated =
|
final StreamController<AngelAuthResult> _onAuthenticated =
|
||||||
StreamController<AngelAuthResult>();
|
StreamController<AngelAuthResult>();
|
||||||
final List<Service> _services = [];
|
final List<Service> _services = [];
|
||||||
final http.BaseClient client;
|
final BaseClient client;
|
||||||
|
|
||||||
final Context _p = Context(style: Style.url);
|
final Context _p = Context(style: Style.url);
|
||||||
|
|
||||||
|
@ -71,7 +67,7 @@ abstract class BaseAngelClient extends Angel {
|
||||||
//var p1 = p.joinAll(segments).replaceAll('\\', '/');
|
//var p1 = p.joinAll(segments).replaceAll('\\', '/');
|
||||||
|
|
||||||
var url = baseUrl.replace(path: _p.joinAll(segments));
|
var url = baseUrl.replace(path: _p.joinAll(segments));
|
||||||
http.Response response;
|
Response response;
|
||||||
|
|
||||||
if (credentials != null) {
|
if (credentials != null) {
|
||||||
response = await post(url,
|
response = await post(url,
|
||||||
|
@ -121,7 +117,7 @@ abstract class BaseAngelClient extends Angel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<http.StreamedResponse> send(http.BaseRequest request) async {
|
Future<StreamedResponse> send(BaseRequest request) async {
|
||||||
if (authToken?.isNotEmpty == true) {
|
if (authToken?.isNotEmpty == true) {
|
||||||
request.headers['authorization'] ??= 'Bearer $authToken';
|
request.headers['authorization'] ??= 'Bearer $authToken';
|
||||||
}
|
}
|
||||||
|
@ -129,11 +125,10 @@ abstract class BaseAngelClient extends Angel {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends a non-streaming [Request] and returns a non-streaming [Response].
|
/// Sends a non-streaming [Request] and returns a non-streaming [Response].
|
||||||
Future<http.Response> sendUnstreamed(
|
Future<Response> sendUnstreamed(
|
||||||
String method, url, Map<String, String>? headers,
|
String method, url, Map<String, String>? headers,
|
||||||
[body, Encoding? encoding]) async {
|
[body, Encoding? encoding]) async {
|
||||||
var request =
|
var request = Request(method, url is Uri ? url : Uri.parse(url.toString()));
|
||||||
http.Request(method, url is Uri ? url : Uri.parse(url.toString()));
|
|
||||||
|
|
||||||
if (headers != null) request.headers.addAll(headers);
|
if (headers != null) request.headers.addAll(headers);
|
||||||
|
|
||||||
|
@ -153,7 +148,7 @@ abstract class BaseAngelClient extends Angel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return http.Response.fromStream(await send(request));
|
return Response.fromStream(await send(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -173,34 +168,34 @@ abstract class BaseAngelClient extends Angel {
|
||||||
}
|
}
|
||||||
|
|
||||||
//@override
|
//@override
|
||||||
//Future<http.Response> delete(url, {Map<String, String> headers}) async {
|
//Future<Response> delete(url, {Map<String, String> headers}) async {
|
||||||
// return sendUnstreamed('DELETE', _join(url), headers);
|
// return sendUnstreamed('DELETE', _join(url), headers);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<http.Response> get(url, {Map<String, String>? headers}) async {
|
Future<Response> get(url, {Map<String, String>? headers}) async {
|
||||||
return sendUnstreamed('GET', _join(url), headers);
|
return sendUnstreamed('GET', _join(url), headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<http.Response> head(url, {Map<String, String>? headers}) async {
|
Future<Response> head(url, {Map<String, String>? headers}) async {
|
||||||
return sendUnstreamed('HEAD', _join(url), headers);
|
return sendUnstreamed('HEAD', _join(url), headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<http.Response> patch(url,
|
Future<Response> patch(url,
|
||||||
{body, Map<String, String>? headers, Encoding? encoding}) async {
|
{body, Map<String, String>? headers, Encoding? encoding}) async {
|
||||||
return sendUnstreamed('PATCH', _join(url), headers, body, encoding);
|
return sendUnstreamed('PATCH', _join(url), headers, body, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<http.Response> post(url,
|
Future<Response> post(url,
|
||||||
{body, Map<String, String>? headers, Encoding? encoding}) async {
|
{body, Map<String, String>? headers, Encoding? encoding}) async {
|
||||||
return sendUnstreamed('POST', _join(url), headers, body, encoding);
|
return sendUnstreamed('POST', _join(url), headers, body, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<http.Response> put(url,
|
Future<Response> put(url,
|
||||||
{body, Map<String, String>? headers, Encoding? encoding}) async {
|
{body, Map<String, String>? headers, Encoding? encoding}) async {
|
||||||
return sendUnstreamed('PUT', _join(url), headers, body, encoding);
|
return sendUnstreamed('PUT', _join(url), headers, body, encoding);
|
||||||
}
|
}
|
||||||
|
@ -210,7 +205,7 @@ class BaseAngelService<Id, Data> extends Service<Id, Data?> {
|
||||||
@override
|
@override
|
||||||
final BaseAngelClient app;
|
final BaseAngelClient app;
|
||||||
final Uri baseUrl;
|
final Uri baseUrl;
|
||||||
final http.BaseClient client;
|
final BaseClient client;
|
||||||
final AngelDeserializer<Data>? deserializer;
|
final AngelDeserializer<Data>? deserializer;
|
||||||
|
|
||||||
final Context _p = Context(style: Style.url);
|
final Context _p = Context(style: Style.url);
|
||||||
|
@ -262,7 +257,7 @@ class BaseAngelService<Id, Data> extends Service<Id, Data?> {
|
||||||
return jsonEncode(x);
|
return jsonEncode(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<http.StreamedResponse> send(http.BaseRequest request) {
|
Future<StreamedResponse> send(BaseRequest request) {
|
||||||
if (app.authToken != null && app.authToken!.isNotEmpty) {
|
if (app.authToken != null && app.authToken!.isNotEmpty) {
|
||||||
request.headers['Authorization'] = 'Bearer ${app.authToken}';
|
request.headers['Authorization'] = 'Bearer ${app.authToken}';
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import 'package:angel3_framework/http.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
const Map<String, String> USER = {'username': 'foo', 'password': 'bar'};
|
const Map<String, String> user = {'username': 'foo', 'password': 'bar'};
|
||||||
var localOpts = AngelAuthOptions<Map<String, String>>(canRespondWithJson: true);
|
var localOpts = AngelAuthOptions<Map<String, String>>(canRespondWithJson: true);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -17,12 +17,12 @@ void main() {
|
||||||
app = Angel();
|
app = Angel();
|
||||||
http = AngelHttp(app, useZone: false);
|
http = AngelHttp(app, useZone: false);
|
||||||
var auth = AngelAuth(
|
var auth = AngelAuth(
|
||||||
serializer: (_) async => 'baz', deserializer: (_) async => USER);
|
serializer: (_) async => 'baz', deserializer: (_) async => user);
|
||||||
|
|
||||||
auth.strategies['local'] = LocalAuthStrategy(
|
auth.strategies['local'] = LocalAuthStrategy(
|
||||||
(username, password) async {
|
(username, password) async {
|
||||||
if (username == 'foo' && password == 'bar') {
|
if (username == 'foo' && password == 'bar') {
|
||||||
return USER;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
@ -50,10 +50,10 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('auth event fires', () async {
|
test('auth event fires', () async {
|
||||||
var localAuth = await client.authenticate(type: 'local', credentials: USER);
|
var localAuth = await client.authenticate(type: 'local', credentials: user);
|
||||||
print('JWT: ${localAuth.token}');
|
print('JWT: ${localAuth.token}');
|
||||||
print('Data: ${localAuth.data}');
|
print('Data: ${localAuth.data}');
|
||||||
|
|
||||||
expect(localAuth.data, USER);
|
expect(localAuth.data, user);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Postcard extends Model {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(other) {
|
bool operator ==(other) {
|
||||||
if (!(other is Postcard)) return false;
|
if (other is! Postcard) return false;
|
||||||
|
|
||||||
return id == other.id &&
|
return id == other.id &&
|
||||||
location == other.location &&
|
location == other.location &&
|
||||||
|
|
Loading…
Reference in a new issue