refactor code

This commit is contained in:
Ashita Prasad
2024-11-02 20:11:45 +05:30
parent 44f9d10c8c
commit 69753a5f26
2 changed files with 9 additions and 4 deletions

View File

@ -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,

View File

@ -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) {