mirror of
https://github.com/foss42/apidash.git
synced 2025-05-28 12:18:06 +08:00
refactor
This commit is contained in:
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user