diff --git a/packages/apidash_core/lib/utils/http_request_utils.dart b/packages/apidash_core/lib/utils/http_request_utils.dart index 1c09842b..666d585a 100644 --- a/packages/apidash_core/lib/utils/http_request_utils.dart +++ b/packages/apidash_core/lib/utils/http_request_utils.dart @@ -2,8 +2,10 @@ import 'package:collection/collection.dart'; import '../consts.dart'; import '../models/models.dart'; -Map? rowsToMap(List? kvRows, - {bool isHeader = false}) { +Map? rowsToMap( + List? kvRows, { + bool isHeader = false, +}) { if (kvRows == null) { return null; } @@ -20,7 +22,9 @@ Map? rowsToMap(List? kvRows, return finalMap; } -List? mapToRows(Map? kvMap) { +List? mapToRows( + Map? kvMap, +) { if (kvMap == null) { return null; } @@ -51,7 +55,9 @@ List>? rowsToFormDataMapList( return finalMap; } -List? mapListToFormDataModelRows(List? kvMap) { +List? mapListToFormDataModelRows( + List? kvMap, +) { if (kvMap == null) { return null; } @@ -73,7 +79,9 @@ FormDataType getFormDataType(String? type) { } List? getEnabledRows( - List? rows, List? isRowEnabledList) { + List? rows, + List? isRowEnabledList, +) { if (rows == null || isRowEnabledList == null) { return rows; } diff --git a/packages/apidash_core/lib/utils/http_utils.dart b/packages/apidash_core/lib/utils/http_utils.dart new file mode 100644 index 00000000..74c52414 --- /dev/null +++ b/packages/apidash_core/lib/utils/http_utils.dart @@ -0,0 +1,33 @@ +import 'package:http_parser/http_parser.dart'; +import '../consts.dart'; +import '../extensions/extensions.dart'; + +ContentType? getContentTypeFromHeadersMap( + Map? kvMap, +) { + if (kvMap != null && kvMap.hasKeyContentType()) { + var val = kvMap.getValueContentType(); + if (val != null) { + return ContentType.text; + } + } + return null; +} + +MediaType? getMediaTypeFromHeaders(Map? headers) { + var contentType = headers?.getValueContentType(); + MediaType? mediaType = getMediaTypeFromContentType(contentType); + return mediaType; +} + +MediaType? getMediaTypeFromContentType(String? contentType) { + if (contentType != null) { + try { + MediaType mediaType = MediaType.parse(contentType); + return mediaType; + } catch (e) { + return null; + } + } + return null; +} diff --git a/packages/apidash_core/lib/utils/utils.dart b/packages/apidash_core/lib/utils/utils.dart index 5e1dbbcb..6ecbf527 100644 --- a/packages/apidash_core/lib/utils/utils.dart +++ b/packages/apidash_core/lib/utils/utils.dart @@ -1,3 +1,4 @@ +export 'http_utils.dart'; export 'http_request_utils.dart'; export 'http_response_utils.dart'; export 'string_utils.dart';