map extension to help detect content-type

This commit is contained in:
Ashita Prasad
2024-12-06 03:50:13 +05:30
parent f52aa45d86
commit 9aa7224f31
2 changed files with 23 additions and 0 deletions

View File

@ -1 +1,2 @@
export 'string_extensions.dart';
export 'map_extensions.dart';

View File

@ -0,0 +1,22 @@
import 'dart:io';
extension MapExtension on Map {
bool hasKeyContentType() {
return keys.any((k) => (k is String)
? k.toLowerCase() == HttpHeaders.contentTypeHeader
: false);
}
String? getKeyContentType() {
if (isEmpty) {
return null;
}
bool present = hasKeyContentType();
if (present) {
return keys.firstWhere((e) => (e is String)
? e.toLowerCase() == HttpHeaders.contentTypeHeader
: false);
}
return null;
}
}