Skip to content

Commit 9cbcac1

Browse files
committed
api [nfc]: Factor out helper for making auth HTTP header
1 parent 895bca0 commit 9cbcac1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/api/core.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,20 @@ abstract class ApiConnection {
3737
Future<String> post(String route, Map<String, dynamic>? params);
3838
}
3939

40+
MapEntry<String, String> authHeader(Auth auth) {
41+
// TODO memoize
42+
final authBytes = utf8.encode("${auth.email}:${auth.apiKey}");
43+
return MapEntry('Authorization', 'Basic ${base64.encode(authBytes)}');
44+
}
45+
4046
/// An [ApiConnection] that makes real network requests to a real server.
4147
class LiveApiConnection extends ApiConnection {
4248
LiveApiConnection({required super.auth});
4349

4450
Map<String, String> _headers() {
45-
// TODO memoize
46-
final authBytes = utf8.encode("${auth.email}:${auth.apiKey}");
47-
return {
48-
'Authorization': 'Basic ${base64.encode(authBytes)}',
49-
};
51+
final Map<String, String> result = {};
52+
result.addEntries([authHeader(auth)]);
53+
return result;
5054
}
5155

5256
@override

0 commit comments

Comments
 (0)