This commit is contained in:
Ashita Prasad
2024-12-06 05:00:14 +05:30
parent f63663392c
commit ce2213ce7b
2 changed files with 8 additions and 10 deletions

View File

@ -12,18 +12,10 @@ class CurlFileImport {
final params = mapToRows(curl.uri.queryParameters); final params = mapToRows(curl.uri.queryParameters);
final body = curl.data; final body = curl.data;
final formData = curl.formData; final formData = curl.formData;
// Determine content type based on form data and headers // 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 final ContentType contentType = curl.form
? ContentType.formdata ? ContentType.formdata
: hasJsonContentType : (getContentTypeFromHeadersMap(curl.headers) ?? ContentType.text);
? ContentType.json
: ContentType.text;
return HttpRequestModel( return HttpRequestModel(
method: method, method: method,

View File

@ -6,8 +6,14 @@ ContentType? getContentTypeFromHeadersMap(
Map<String, String>? kvMap, Map<String, String>? kvMap,
) { ) {
if (kvMap != null && kvMap.hasKeyContentType()) { if (kvMap != null && kvMap.hasKeyContentType()) {
var val = kvMap.getValueContentType(); var val = getMediaTypeFromHeaders(kvMap);
if (val != null) { 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; return ContentType.text;
} }
} }