mirror of
https://github.com/foss42/apidash.git
synced 2025-06-09 06:15:50 +08:00
Remove getContentTypeFromHeaders()
This commit is contained in:
packages/apidash_core
lib
test
@ -5,6 +5,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
|
|||||||
import 'package:collection/collection.dart' show mergeMaps;
|
import 'package:collection/collection.dart' show mergeMaps;
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
import 'package:http_parser/http_parser.dart';
|
import 'package:http_parser/http_parser.dart';
|
||||||
|
import '../extensions/extensions.dart';
|
||||||
import '../utils/utils.dart';
|
import '../utils/utils.dart';
|
||||||
import '../consts.dart';
|
import '../consts.dart';
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ class HttpResponseModel with _$HttpResponseModel {
|
|||||||
factory HttpResponseModel.fromJson(Map<String, Object?> json) =>
|
factory HttpResponseModel.fromJson(Map<String, Object?> json) =>
|
||||||
_$HttpResponseModelFromJson(json);
|
_$HttpResponseModelFromJson(json);
|
||||||
|
|
||||||
String? get contentType => getContentTypeFromHeaders(headers);
|
String? get contentType => headers?.getValueContentType();
|
||||||
MediaType? get mediaType => getMediaTypeFromHeaders(headers);
|
MediaType? get mediaType => getMediaTypeFromHeaders(headers);
|
||||||
|
|
||||||
HttpResponseModel fromResponse({
|
HttpResponseModel fromResponse({
|
||||||
|
@ -1,33 +1,10 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:http_parser/http_parser.dart';
|
import 'package:http_parser/http_parser.dart';
|
||||||
import 'package:xml/xml.dart';
|
import 'package:xml/xml.dart';
|
||||||
import '../consts.dart';
|
import '../consts.dart';
|
||||||
|
|
||||||
String? getContentTypeFromHeaders(Map? headers) {
|
|
||||||
return headers?[HttpHeaders.contentTypeHeader];
|
|
||||||
}
|
|
||||||
|
|
||||||
MediaType? getMediaTypeFromHeaders(Map? headers) {
|
|
||||||
var contentType = getContentTypeFromHeaders(headers);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
String? formatBody(String? body, MediaType? mediaType) {
|
String? formatBody(String? body, MediaType? mediaType) {
|
||||||
if (mediaType != null && body != null) {
|
if (mediaType != null && body != null) {
|
||||||
var subtype = mediaType.subtype;
|
var subtype = mediaType.subtype;
|
||||||
|
@ -109,4 +109,21 @@ void main() {
|
|||||||
expect(mapEx.getValueContentType(), "y");
|
expect(mapEx.getValueContentType(), "y");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
group("Testing ?.getValueContentType() function", () {
|
||||||
|
test('Testing ?.getValueContentType() for header1', () {
|
||||||
|
Map<String, String> header1 = {
|
||||||
|
"content-type": "application/json",
|
||||||
|
};
|
||||||
|
String contentType1Expected = "application/json";
|
||||||
|
expect(header1.getValueContentType(), contentType1Expected);
|
||||||
|
});
|
||||||
|
test('Testing ?.getValueContentType() when header keys are in header case',
|
||||||
|
() {
|
||||||
|
Map<String, String> header2 = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
};
|
||||||
|
expect(header2.getValueContentType(), "application/json");
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,8 @@
|
|||||||
import 'package:apidash_core/utils/http_response_utils.dart';
|
import 'package:apidash_core/utils/utils.dart';
|
||||||
import 'package:apidash_core/utils/string_utils.dart';
|
|
||||||
import 'package:http_parser/http_parser.dart';
|
import 'package:http_parser/http_parser.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group("Testing getContentTypeFromHeaders function", () {
|
|
||||||
test('Testing getContentTypeFromHeaders for header1', () {
|
|
||||||
Map<String, String> header1 = {
|
|
||||||
"content-type": "application/json",
|
|
||||||
};
|
|
||||||
String contentType1Expected = "application/json";
|
|
||||||
expect(getContentTypeFromHeaders(header1), contentType1Expected);
|
|
||||||
});
|
|
||||||
test('Testing getContentTypeFromHeaders for null headers', () {
|
|
||||||
expect(getContentTypeFromHeaders(null), null);
|
|
||||||
});
|
|
||||||
test(
|
|
||||||
'Testing getContentTypeFromHeaders when header keys are in header case',
|
|
||||||
() {
|
|
||||||
Map<String, String> header2 = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
};
|
|
||||||
expect(getContentTypeFromHeaders(header2), null);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group('Testing getMediaTypeFromContentType function', () {
|
group('Testing getMediaTypeFromContentType function', () {
|
||||||
test('Testing getMediaTypeFromContentType for json type', () {
|
test('Testing getMediaTypeFromContentType for json type', () {
|
||||||
String contentType1 = "application/json";
|
String contentType1 = "application/json";
|
||||||
|
Reference in New Issue
Block a user