add additional qs and header to http client; add additional queryParams to websocket

This commit is contained in:
Salvatore Giordano
2021-07-23 10:27:31 +02:00
parent 55b826ea7b
commit ad916de425
5 changed files with 42 additions and 6 deletions
@@ -33,11 +33,14 @@ class StreamHttpClient {
..options.baseUrl = _options.baseUrl
..options.receiveTimeout = _options.receiveTimeout.inMilliseconds
..options.connectTimeout = _options.connectTimeout.inMilliseconds
..options.queryParameters = {'api_key': apiKey}
..options.queryParameters = {
'api_key': apiKey,
..._options.queryParams,
}
..options.headers = {
'Content-Type': 'application/json',
'X-Stream-Client': _options.userAgent,
'Content-Encoding': 'application/gzip',
..._options.headers,
}
..interceptors.addAll([
if (tokenManager != null) AuthInterceptor(this, tokenManager),
@@ -10,6 +10,8 @@ class StreamHttpClientOptions {
this.location,
this.connectTimeout = const Duration(seconds: 6),
this.receiveTimeout = const Duration(seconds: 6),
this.queryParams = const {},
this.headers = const {},
}) : _baseUrl = baseUrl ?? _defaultBaseURL;
final String _baseUrl;
@@ -32,8 +34,20 @@ class StreamHttpClientOptions {
/// received timeout, default to 6s
final Duration receiveTimeout;
/// Get the current user agent
String get userAgent => 'stream-chat-dart-client-'
'${CurrentPlatform.name}-'
'${PACKAGE_VERSION.split('+')[0]}';
/// Common query parameters.
///
/// List values use the default [ListFormat.multiCompatible].
///
/// The value can be overridden per parameter by adding a [MultiParam]
/// object wrapping the actual List value and the desired format.
final Map<String, Object?> queryParams;
/// Http request headers.
/// The keys of initial headers will be converted to lowercase,
/// for example 'Content-Type' will be converted to 'content-type'.
///
/// The key of Header Map is case-insensitive
/// eg: content-type and Content-Type are
/// regard as the same key.
final Map<String, Object?> headers;
}