setUriSchemeToHttp static method
Changes originalURL
to use the http protocol if none specified.
This is used to ensure that URLs that do not include the scheme are treated as absolute paths (not relative to the document URL).
Implementation
static String? setUriSchemeToHttp(String originalURL) {
String? finalUrl;
Uri parsedUri;
log.info(
'Function : setUriSchemeToHttp, Parameters : {[originalURL,$originalURL ]}');
try {
parsedUri = Uri.parse(originalURL);
if (parsedUri.scheme == '') {
finalUrl = parsedUri
.replace(scheme: 'http', path: r'//' + parsedUri.path)
.toString();
//the following line to to work around a bug in Darts URI library
finalUrl = finalUrl.replaceFirst(r'http:////', r'http://');
}
} catch (e) {
//invalid URLs to be passed back unmodified
}
finalUrl = ifNull(finalUrl, originalURL);
log.fine('Function : setUriSchemeToHttp, Return : $finalUrl');
return finalUrl;
}