Skip to content

Commit

Permalink
fix: extra overwritten issue (#6)
Browse files Browse the repository at this point in the history
* Fix dio.extra overlay issue

* Add prefix and revert version
  • Loading branch information
simonkimi authored Feb 24, 2023
1 parent ba62a67 commit 4cefce3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/src/dio_http_formatter_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import 'package:logger/logger.dart';

typedef HttpLoggerFilter = bool Function();

const _prefix = 'dio_http_formatter';
const _startTimeKey = '$_prefix@start_time';

class HttpFormatter extends Interceptor {
// Logger object to pretty print the HTTP Request
final Logger _logger;
Expand Down Expand Up @@ -48,9 +51,7 @@ class HttpFormatter extends Interceptor {

@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
options.extra = <String, dynamic>{
'start_time': DateTime.now().millisecondsSinceEpoch
};
options.extra[_startTimeKey] = DateTime.now().millisecondsSinceEpoch;
super.onRequest(options, handler);
}

Expand Down Expand Up @@ -142,7 +143,7 @@ class HttpFormatter extends Interceptor {
if (_includeResponse && response != null) {
responseString =
'⤵ RESPONSE [${response.statusCode}/${response.statusMessage}] '
'${requestOptions?.extra['start_time'] != null ? '[Time elapsed: ${DateTime.now().millisecondsSinceEpoch - requestOptions?.extra['start_time']} ms]' : ''}'
'${requestOptions?.extra[_startTimeKey] != null ? '[Time elapsed: ${DateTime.now().millisecondsSinceEpoch - requestOptions?.extra[_startTimeKey]} ms]' : ''}'
'⤵\n\n';

if (_includeResponseHeaders) {
Expand Down

0 comments on commit 4cefce3

Please sign in to comment.