@@ -13,6 +13,26 @@ class FunctionsClient {
13
13
final YAJsonIsolate _isolate;
14
14
final bool _hasCustomIsolate;
15
15
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
+
16
36
/// In case you don't provide your own isolate, call [dispose] when you're done
17
37
FunctionsClient (
18
38
String url,
@@ -32,6 +52,14 @@ class FunctionsClient {
32
52
_headers['Authorization' ] = 'Bearer $token ' ;
33
53
}
34
54
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
+
35
63
/// Invokes a function
36
64
///
37
65
/// [functionName] - the name of the function to invoke
0 commit comments