Add SupportedUriSchemes support

This commit is contained in:
Ashita Prasad
2024-12-15 07:37:18 +05:30
parent 676468dc7c
commit 2bb54ec4d6
7 changed files with 25 additions and 14 deletions

View File

@ -13,7 +13,7 @@ enum SupportedUriSchemes { https, http }
final kSupportedUriSchemes =
SupportedUriSchemes.values.map((i) => i.name).toList();
const kDefaultUriScheme = "https";
const kDefaultUriScheme = SupportedUriSchemes.https;
final kLocalhostRegex = RegExp(r'^localhost(:\d+)?(/.*)?$');
const kMethodsWithBody = [

View File

@ -11,7 +11,7 @@ typedef HttpResponse = http.Response;
Future<(HttpResponse?, Duration?, String?)> request(
HttpRequestModel requestModel, {
String defaultUriScheme = kDefaultUriScheme,
SupportedUriSchemes defaultUriScheme = kDefaultUriScheme,
}) async {
(Uri?, String?) uriRec = getValidRequestUri(
requestModel.url,

View File

@ -5,7 +5,7 @@ import 'http_request_utils.dart';
(String?, bool) getUriScheme(Uri uri) {
if (uri.hasScheme) {
if (kSupportedUriSchemes.contains(uri.scheme)) {
if (kSupportedUriSchemes.contains(uri.scheme.toLowerCase())) {
return (uri.scheme, true);
}
return (uri.scheme, false);
@ -24,7 +24,7 @@ String stripUrlParams(String url) {
(Uri?, String?) getValidRequestUri(
String? url, List<NameValueModel>? requestParams,
{String defaultUriScheme = kDefaultUriScheme}) {
{SupportedUriSchemes defaultUriScheme = kDefaultUriScheme}) {
url = url?.trim();
if (url == null || url == "") {
return (null, "URL is missing!");
@ -44,7 +44,7 @@ String stripUrlParams(String url) {
return (null, "Unsupported URL Scheme (${urlScheme.$1})");
}
} else {
url = "$defaultUriScheme://$url";
url = "${defaultUriScheme.name}://$url";
}
uri = Uri.parse(url);