Skip to content

Commit

Permalink
♻️ Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Oct 25, 2023
1 parent 154c20e commit eaf9aae
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion dio/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ See the [Migration Guide][] for the complete breaking changes list.**

- Raise warning for `Map`s other than `Map<String, dynamic>` when encoding request data.
- Improve exception messages.
- Allow case-sensitive header keys with the `caseSensitiveHeaders` flag through options.
- Allow case-sensitive header keys with the `preserveHeaderCase` flag through options.

## 5.3.3

Expand Down
2 changes: 1 addition & 1 deletion dio/lib/src/adapters/io_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class IOHttpClientAdapter implements HttpClientAdapter {
request.headers.set(
key,
value,
preserveHeaderCase: options.caseSensitiveHeaders,
preserveHeaderCase: options.preserveHeaderCase,
);
}
});
Expand Down
4 changes: 2 additions & 2 deletions dio/lib/src/dio_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ abstract class DioMixin implements Dio {
);
final headers = Headers.fromMap(
responseBody.headers,
caseSensitive: reqOpt.caseSensitiveHeaders,
preserveHeaderCase: reqOpt.preserveHeaderCase,
);
// Make sure headers and [ResponseBody.headers] are the same instance.
responseBody.headers = headers.map;
Expand Down Expand Up @@ -712,7 +712,7 @@ abstract class DioMixin implements Dio {
if (data is ResponseBody) {
headers = Headers.fromMap(
data.headers,
caseSensitive: requestOptions.caseSensitiveHeaders,
preserveHeaderCase: requestOptions.preserveHeaderCase,
);
} else {
headers = response.headers;
Expand Down
6 changes: 3 additions & 3 deletions dio/lib/src/headers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ typedef HeaderForEachCallback = void Function(String name, List<String> values);
/// The headers class for requests and responses.
class Headers {
Headers({
this.caseSensitive = false,
this.preserveHeaderCase = false,
}) : _map = caseInsensitiveKeyMap<List<String>>();

/// Create the [Headers] from a [Map] instance.
Headers.fromMap(
Map<String, List<String>> map, {
this.caseSensitive = false,
this.preserveHeaderCase = false,
}) : _map = caseInsensitiveKeyMap<List<String>>(
map.map((k, v) => MapEntry(k.trim(), v)),
);
Expand All @@ -35,7 +35,7 @@ class Headers {
/// Whether the header key should be case-sensitive.
///
/// Defaults to false.
final bool caseSensitive;
final bool preserveHeaderCase;

final Map<String, List<String>> _map;

Expand Down
36 changes: 18 additions & 18 deletions dio/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class BaseOptions extends _RequestConfig with OptionsMixin {
Map<String, dynamic>? queryParameters,
Map<String, dynamic>? extra,
Map<String, dynamic>? headers,
bool caseSensitiveHeaders = false,
bool preserveHeaderCase = false,
ResponseType? responseType = ResponseType.json,
String? contentType,
ValidateStatus? validateStatus,
Expand All @@ -147,7 +147,7 @@ class BaseOptions extends _RequestConfig with OptionsMixin {
sendTimeout: sendTimeout,
extra: extra,
headers: headers,
caseSensitiveHeaders: caseSensitiveHeaders,
preserveHeaderCase: preserveHeaderCase,
responseType: responseType,
contentType: contentType,
validateStatus: validateStatus,
Expand Down Expand Up @@ -175,7 +175,7 @@ class BaseOptions extends _RequestConfig with OptionsMixin {
Duration? sendTimeout,
Map<String, Object?>? extra,
Map<String, Object?>? headers,
bool? caseSensitiveHeaders,
bool? preserveHeaderCase,
ResponseType? responseType,
String? contentType,
ValidateStatus? validateStatus,
Expand All @@ -196,7 +196,7 @@ class BaseOptions extends _RequestConfig with OptionsMixin {
sendTimeout: sendTimeout ?? this.sendTimeout,
extra: extra ?? Map.from(this.extra),
headers: headers ?? Map.from(this.headers),
caseSensitiveHeaders: caseSensitiveHeaders ?? this.caseSensitiveHeaders,
preserveHeaderCase: preserveHeaderCase ?? this.preserveHeaderCase,
responseType: responseType ?? this.responseType,
contentType: contentType ?? this.contentType,
validateStatus: validateStatus ?? this.validateStatus,
Expand All @@ -220,7 +220,7 @@ class Options {
Duration? receiveTimeout,
this.extra,
this.headers,
this.caseSensitiveHeaders,
this.preserveHeaderCase,
this.responseType,
this.contentType,
this.validateStatus,
Expand All @@ -243,7 +243,7 @@ class Options {
Duration? receiveTimeout,
Map<String, Object?>? extra,
Map<String, Object?>? headers,
bool? caseSensitiveHeaders,
bool? preserveHeaderCase,
ResponseType? responseType,
String? contentType,
ValidateStatus? validateStatus,
Expand Down Expand Up @@ -280,7 +280,7 @@ class Options {
receiveTimeout: receiveTimeout ?? this.receiveTimeout,
extra: extra ?? effectiveExtra,
headers: headers ?? effectiveHeaders,
caseSensitiveHeaders: caseSensitiveHeaders ?? this.caseSensitiveHeaders,
preserveHeaderCase: preserveHeaderCase ?? this.preserveHeaderCase,
responseType: responseType ?? this.responseType,
contentType: contentType ?? this.contentType,
validateStatus: validateStatus ?? this.validateStatus,
Expand Down Expand Up @@ -329,8 +329,8 @@ class Options {
baseUrl: baseOpt.baseUrl,
path: path,
data: data,
caseSensitiveHeaders:
caseSensitiveHeaders ?? baseOpt.caseSensitiveHeaders,
preserveHeaderCase:
preserveHeaderCase ?? baseOpt.preserveHeaderCase,
sourceStackTrace: sourceStackTrace ?? StackTrace.current,
connectTimeout: baseOpt.connectTimeout,
sendTimeout: sendTimeout ?? baseOpt.sendTimeout,
Expand Down Expand Up @@ -365,14 +365,14 @@ class Options {
/// e.g.: `content-type` and `Content-Type` will be treated as the same key.
Map<String, dynamic>? headers;

/// Whether the header keys should be case-sensitive.
/// Whether the case of header keys should be preserved.
///
/// Defaults to false.
///
/// This option WILL NOT take effect on these circumstances:
/// - XHR ([HttpRequest]) does not support handling this explicitly.
/// - The HTTP/2 standard only supports lowercase header keys.
bool? caseSensitiveHeaders;
bool? preserveHeaderCase;

/// Timeout when sending data.
///
Expand Down Expand Up @@ -490,7 +490,7 @@ class RequestOptions extends _RequestConfig with OptionsMixin {
String? baseUrl,
Map<String, dynamic>? extra,
Map<String, dynamic>? headers,
bool? caseSensitiveHeaders,
bool? preserveHeaderCase,
ResponseType? responseType,
String? contentType,
ValidateStatus? validateStatus,
Expand All @@ -510,7 +510,7 @@ class RequestOptions extends _RequestConfig with OptionsMixin {
receiveTimeout: receiveTimeout,
extra: extra,
headers: headers,
caseSensitiveHeaders: caseSensitiveHeaders,
preserveHeaderCase: preserveHeaderCase,
responseType: responseType,
contentType: contentType,
validateStatus: validateStatus,
Expand Down Expand Up @@ -543,7 +543,7 @@ class RequestOptions extends _RequestConfig with OptionsMixin {
CancelToken? cancelToken,
Map<String, dynamic>? extra,
Map<String, dynamic>? headers,
bool? caseSensitiveHeaders,
bool? preserveHeaderCase,
ResponseType? responseType,
String? contentType,
ValidateStatus? validateStatus,
Expand Down Expand Up @@ -580,7 +580,7 @@ class RequestOptions extends _RequestConfig with OptionsMixin {
cancelToken: cancelToken ?? this.cancelToken,
extra: extra ?? Map.from(this.extra),
headers: headers ?? Map.from(this.headers),
caseSensitiveHeaders: caseSensitiveHeaders ?? this.caseSensitiveHeaders,
preserveHeaderCase: preserveHeaderCase ?? this.preserveHeaderCase,
responseType: responseType ?? this.responseType,
validateStatus: validateStatus ?? this.validateStatus,
receiveDataWhenStatusError:
Expand Down Expand Up @@ -658,7 +658,7 @@ class _RequestConfig {
String? method,
Map<String, dynamic>? extra,
Map<String, dynamic>? headers,
bool? caseSensitiveHeaders,
bool? preserveHeaderCase,
String? contentType,
ListFormat? listFormat,
bool? followRedirects,
Expand All @@ -674,7 +674,7 @@ class _RequestConfig {
assert(sendTimeout == null || !sendTimeout.isNegative),
_sendTimeout = sendTimeout,
method = method ?? 'GET',
caseSensitiveHeaders = caseSensitiveHeaders ?? false,
preserveHeaderCase = preserveHeaderCase ?? false,
listFormat = listFormat ?? ListFormat.multi,
extra = extra ?? {},
followRedirects = followRedirects ?? true,
Expand Down Expand Up @@ -714,7 +714,7 @@ class _RequestConfig {
}
}

late bool caseSensitiveHeaders;
late bool preserveHeaderCase;

Duration? get sendTimeout => _sendTimeout;
Duration? _sendTimeout;
Expand Down
2 changes: 1 addition & 1 deletion dio/lib/src/response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Response<T> {
Map<String, dynamic>? extra,
Headers? headers,
}) : headers = headers ??
Headers(caseSensitive: requestOptions.caseSensitiveHeaders),
Headers(preserveHeaderCase: requestOptions.preserveHeaderCase),
extra = extra ?? <String, dynamic>{};

/// The response payload in specific type.
Expand Down
2 changes: 1 addition & 1 deletion dio/test/headers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void main() {
'content-length': ['200'],
'Test': ['1', '2'],
},
caseSensitive: true,
preserveHeaderCase: true,
);
expect(headers['SET-COOKIE']?.length, 2);
// Although it's case-sensitive, we still use case-insensitive map.
Expand Down
2 changes: 1 addition & 1 deletion dio/test/options_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ void main() {
final sensitiveResponse = await dio.get<Map<String, dynamic>>(
'/headers',
options: Options(
caseSensitiveHeaders: true,
preserveHeaderCase: true,
headers: {
'Sensitive': 'test',
'insensitive': 'test',
Expand Down
2 changes: 1 addition & 1 deletion plugins/native_dio_adapter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- Bump `cronet_http` version.
- Minimal required Dart version is now 3.1.
- Minimal required Flutter version is now 3.13.0.
- Allow case-sensitive header keys with the `caseSensitiveHeaders` flag through options.
- Allow case-sensitive header keys with the `preserveHeaderCase` flag through options.

## 1.0.0+2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ConversionLayerAdapter implements HttpClientAdapter {
Map.fromEntries(
options.headers.entries.map(
(e) => MapEntry(
options.caseSensitiveHeaders ? e.key : e.key.toLowerCase(),
options.preserveHeaderCase ? e.key : e.key.toLowerCase(),
e.value.toString(),
),
),
Expand Down Expand Up @@ -75,7 +75,7 @@ extension on StreamedResponse {
ResponseBody toDioResponseBody(RequestOptions options) {
final dioHeaders = headers.entries.map(
(e) => MapEntry(
options.caseSensitiveHeaders ? e.key : e.key.toLowerCase(),
options.preserveHeaderCase ? e.key : e.key.toLowerCase(),
[e.value],
),
);
Expand Down

0 comments on commit eaf9aae

Please sign in to comment.