buildRequestOptions static method
Options
buildRequestOptions({})
Builds the Options used for a request by merging the default auth
headers (Authorization, x-session-token, content-type, etc.) with any
caller-supplied customOptions. Default auth headers are always applied
first; custom headers from customOptions are overlaid on top so callers
can intentionally override specific values (e.g. token refresh flows).
Exposed publicly so the merge behaviour can be verified in isolation without having to construct a full LittleFishHttpClient.
Implementation
@visibleForTesting
static Options buildRequestOptions({
Options? customOptions,
String? token,
String? sessionToken,
Map<String, dynamic> additionalHeaders = const {},
Map<String, dynamic> sharedHeaders = const {},
}) {
final defaultHeaders = _buildDefaultHeaders(
token: token,
sessionToken: sessionToken,
additionalHeaders: additionalHeaders,
sharedHeaders: sharedHeaders,
);
if (customOptions != null) {
// Merge: start with default auth headers, then overlay custom headers
// on top. This ensures auth tokens are always present unless the
// caller explicitly overrides them.
final mergedHeaders = <String, dynamic>{
...defaultHeaders,
...?customOptions.headers,
};
return customOptions.copyWith(headers: mergedHeaders);
}
return Options(
responseType: ResponseType.json,
contentType: 'application/json',
headers: defaultHeaders,
);
}