url_tincture v1.0.5 UrlTincture
The base module of UrlTincture. This module canonicalizes HTTP(S) urls.
The primary methods provided are canonicalize_url/1
& canonicalize_url/2
Summary
Functions
Test if passed url can be safely parsed
Canonicalize a url, forcing scheme to be prepended when missing
Canonicalize a url, scheme not prepended when missing by default
Prepend http:// to urls as needed
Detects if URLs are HTTP or HTTPS
Normalizes http scheme/port combinations
Removes the first www. from URLs
Safely parses passed in URLs
Functions
Test if passed url can be safely parsed
Parameters
url
: The URL to parse
Returns
{:ok, url}
on success{:error, "invalid url"}
on failure
Canonicalize a url, forcing scheme to be prepended when missing.
URLs are:
- Validated.
- Downcased.
- Stripped of www.
- Stripped of fragments.
- http(s) / 80(443) ports are normalized.
Parameters
url
: The URL to canonicalize
Returns:
%UrlTincture.Info{}
on success{:error, "error message"}
on failure
Canonicalize a url, scheme not prepended when missing by default.
See UrlTincture.canonicalize_url/1
for details.
Parameters
url
: The URL to canonicalizeopts
: Options to pass to the canonicalizer (currently onlyforce_http
is supported)
TODO
Replace the hardcoded crypto call with an atom
Prepend http:// to urls as needed.
Parameters
url
- The URL to process
Returns
String
containing the processed URL
Normalizes http scheme/port combinations.
Passes through any unrecognized combinations.
Parameters
scheme
- A string representing the URI parsed schemeport
- An integer representing the URI parsed port
Returns {scheme, port}
(String) port
in the format “:num”
Removes the first www. from URLs
Parameters
url
- The URL to process
Returns
String
containing the processed URL