Skip to content
This repository was archived by the owner on May 13, 2023. It is now read-only.

Commit 311f548

Browse files
committed
make headers editable
1 parent 4b16f2e commit 311f548

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/src/functions_client.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ class FunctionsClient {
1313
final YAJsonIsolate _isolate;
1414
final bool _hasCustomIsolate;
1515

16+
/// Getter for the headers
17+
Map<String, String> get headers {
18+
return _headers;
19+
}
20+
21+
/// Sets the headers to be sent with requests.
22+
/// If an 'Authorization' header is already present,
23+
/// it will be kept unless removeAuth is called first.
24+
/// @param value a Map containing the new headers to set.
25+
set headers(Map<String, String> value) {
26+
final authHeader =
27+
_headers['Authorization']; // Get the existing Authorization header
28+
29+
_headers
30+
..clear()
31+
..addAll(Constants.defaultHeaders)
32+
..addAll(authHeader == null ? {} : {'Authorization': authHeader})
33+
..addAll(value);
34+
}
35+
1636
/// In case you don't provide your own isolate, call [dispose] when you're done
1737
FunctionsClient(
1838
String url,
@@ -32,6 +52,14 @@ class FunctionsClient {
3252
_headers['Authorization'] = 'Bearer $token';
3353
}
3454

55+
/// Removes the Authorization header from the headers map, if it exists.
56+
///
57+
/// Returns the token value that was removed from the header,
58+
/// without the 'Bearer ' prefix, or null if the header was not present.
59+
String? removeAuth() {
60+
return _headers.remove('Authorization')?.replaceFirst('Bearer ', '');
61+
}
62+
3563
/// Invokes a function
3664
///
3765
/// [functionName] - the name of the function to invoke

0 commit comments

Comments
 (0)