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