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 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,

View File

@ -6,8 +6,14 @@ ContentType? getContentTypeFromHeadersMap(
Map<String, String>? 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;
}
}