From ce2213ce7b90491c2b3503a80c54749ad7a3fac9 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Fri, 6 Dec 2024 05:00:14 +0530 Subject: [PATCH] refactor --- lib/importer/curl/curl.dart | 10 +--------- packages/apidash_core/lib/utils/http_utils.dart | 8 +++++++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/importer/curl/curl.dart b/lib/importer/curl/curl.dart index 626170f0..1a0f990b 100644 --- a/lib/importer/curl/curl.dart +++ b/lib/importer/curl/curl.dart @@ -12,18 +12,10 @@ class CurlFileImport { final params = mapToRows(curl.uri.queryParameters); final body = curl.data; final formData = curl.formData; - // Determine content type based on form data and headers - final bool hasJsonContentType = headers?.any((header) => - header.name == "Content-Type" && - header.value == "application/json") ?? - false; - final ContentType contentType = curl.form ? ContentType.formdata - : hasJsonContentType - ? ContentType.json - : ContentType.text; + : (getContentTypeFromHeadersMap(curl.headers) ?? ContentType.text); return HttpRequestModel( method: method, diff --git a/packages/apidash_core/lib/utils/http_utils.dart b/packages/apidash_core/lib/utils/http_utils.dart index 74c52414..13fb7226 100644 --- a/packages/apidash_core/lib/utils/http_utils.dart +++ b/packages/apidash_core/lib/utils/http_utils.dart @@ -6,8 +6,14 @@ ContentType? getContentTypeFromHeadersMap( Map? kvMap, ) { if (kvMap != null && kvMap.hasKeyContentType()) { - var val = kvMap.getValueContentType(); + var val = getMediaTypeFromHeaders(kvMap); if (val != null) { + if (val.subtype.contains(kSubTypeJson)) { + return ContentType.json; + } else if (val.type == kTypeMultipart && + val.subtype == kSubTypeFormData) { + return ContentType.formdata; + } return ContentType.text; } }