From 69753a5f26a7ce052764a25a5a865081e3d81d64 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sat, 2 Nov 2024 20:11:45 +0530 Subject: [PATCH] refactor code --- packages/apidash_core/lib/consts.dart | 7 ++++++- packages/apidash_core/lib/utils/uri_utils.dart | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/apidash_core/lib/consts.dart b/packages/apidash_core/lib/consts.dart index 3493c40d..d2544d04 100644 --- a/packages/apidash_core/lib/consts.dart +++ b/packages/apidash_core/lib/consts.dart @@ -4,8 +4,13 @@ enum HTTPVerb { get, head, post, put, patch, delete } enum FormDataType { text, file } -const kSupportedUriSchemes = ["https", "http"]; +enum SupportedUriSchemes { https, http } + +final kSupportedUriSchemes = + SupportedUriSchemes.values.map((i) => i.name).toList(); const kDefaultUriScheme = "https"; +final kLocalhostRegex = RegExp(r'^localhost(:\d+)?(/.*)?$'); + const kMethodsWithBody = [ HTTPVerb.post, HTTPVerb.put, diff --git a/packages/apidash_core/lib/utils/uri_utils.dart b/packages/apidash_core/lib/utils/uri_utils.dart index f2b44f21..09c159ab 100644 --- a/packages/apidash_core/lib/utils/uri_utils.dart +++ b/packages/apidash_core/lib/utils/uri_utils.dart @@ -29,9 +29,9 @@ String stripUrlParams(String url) { if (url == null || url == "") { return (null, "URL is missing!"); } - final localhostRegex = RegExp(r'^localhost(:\d+)?(/.*)?$'); - if (localhostRegex.hasMatch(url)) { - url = 'http://$url'; + + if (kLocalhostRegex.hasMatch(url)) { + url = '${SupportedUriSchemes.http.name}://$url'; } Uri? uri = Uri.tryParse(url); if (uri == null) {