mirror of
https://github.com/foss42/apidash.git
synced 2025-06-07 03:48:11 +08:00
Create http_utils.dart
This commit is contained in:
@ -2,8 +2,10 @@ import 'package:collection/collection.dart';
|
|||||||
import '../consts.dart';
|
import '../consts.dart';
|
||||||
import '../models/models.dart';
|
import '../models/models.dart';
|
||||||
|
|
||||||
Map<String, String>? rowsToMap(List<NameValueModel>? kvRows,
|
Map<String, String>? rowsToMap(
|
||||||
{bool isHeader = false}) {
|
List<NameValueModel>? kvRows, {
|
||||||
|
bool isHeader = false,
|
||||||
|
}) {
|
||||||
if (kvRows == null) {
|
if (kvRows == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -20,7 +22,9 @@ Map<String, String>? rowsToMap(List<NameValueModel>? kvRows,
|
|||||||
return finalMap;
|
return finalMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<NameValueModel>? mapToRows(Map<String, String>? kvMap) {
|
List<NameValueModel>? mapToRows(
|
||||||
|
Map<String, String>? kvMap,
|
||||||
|
) {
|
||||||
if (kvMap == null) {
|
if (kvMap == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -51,7 +55,9 @@ List<Map<String, String>>? rowsToFormDataMapList(
|
|||||||
return finalMap;
|
return finalMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<FormDataModel>? mapListToFormDataModelRows(List<Map>? kvMap) {
|
List<FormDataModel>? mapListToFormDataModelRows(
|
||||||
|
List<Map>? kvMap,
|
||||||
|
) {
|
||||||
if (kvMap == null) {
|
if (kvMap == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -73,7 +79,9 @@ FormDataType getFormDataType(String? type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<NameValueModel>? getEnabledRows(
|
List<NameValueModel>? getEnabledRows(
|
||||||
List<NameValueModel>? rows, List<bool>? isRowEnabledList) {
|
List<NameValueModel>? rows,
|
||||||
|
List<bool>? isRowEnabledList,
|
||||||
|
) {
|
||||||
if (rows == null || isRowEnabledList == null) {
|
if (rows == null || isRowEnabledList == null) {
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
33
packages/apidash_core/lib/utils/http_utils.dart
Normal file
33
packages/apidash_core/lib/utils/http_utils.dart
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import 'package:http_parser/http_parser.dart';
|
||||||
|
import '../consts.dart';
|
||||||
|
import '../extensions/extensions.dart';
|
||||||
|
|
||||||
|
ContentType? getContentTypeFromHeadersMap(
|
||||||
|
Map<String, String>? kvMap,
|
||||||
|
) {
|
||||||
|
if (kvMap != null && kvMap.hasKeyContentType()) {
|
||||||
|
var val = kvMap.getValueContentType();
|
||||||
|
if (val != null) {
|
||||||
|
return ContentType.text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
MediaType? getMediaTypeFromHeaders(Map? headers) {
|
||||||
|
var contentType = headers?.getValueContentType();
|
||||||
|
MediaType? mediaType = getMediaTypeFromContentType(contentType);
|
||||||
|
return mediaType;
|
||||||
|
}
|
||||||
|
|
||||||
|
MediaType? getMediaTypeFromContentType(String? contentType) {
|
||||||
|
if (contentType != null) {
|
||||||
|
try {
|
||||||
|
MediaType mediaType = MediaType.parse(contentType);
|
||||||
|
return mediaType;
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
export 'http_utils.dart';
|
||||||
export 'http_request_utils.dart';
|
export 'http_request_utils.dart';
|
||||||
export 'http_response_utils.dart';
|
export 'http_response_utils.dart';
|
||||||
export 'string_utils.dart';
|
export 'string_utils.dart';
|
||||||
|
Reference in New Issue
Block a user