url_tincture v1.0.4 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

can_parse_safely?(url)

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_url(url)

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_url(url, opts)

Canonicalize a url, scheme not prepended when missing by default.

See UrlTincture.canonicalize_url/1 for details.

Parameters

  • url: The URL to canonicalize
  • opts: Options to pass to the canonicalizer (currently only force_http is supported)

TODO

Replace the hardcoded crypto call with an atom

extract_root(url)

Specs

extract_root(String.t) :: String.t
extract_tld(url)

Specs

extract_tld(list) :: String.t
extract_tld(String.t) :: String.t
force_http(url)

Prepend http:// to urls as needed.

Parameters

  • url - The URL to process

Returns

  • String containing the processed URL
httpish?(url)

Detects if URLs are HTTP or HTTPS

Parameters

  • url - The URL to analyze

Returns

  • boolean
normalized_http(other, port)

Normalizes http scheme/port combinations.

Passes through any unrecognized combinations.

Parameters

  • scheme - A string representing the URI parsed scheme
  • port - An integer representing the URI parsed port

Returns {scheme, port}

  • (String) port in the format “:num”
remove_www(url)

Removes the first www. from URLs

Parameters

  • url - The URL to process

Returns

  • String containing the processed URL
safe_parse(url)

Safely parses passed in URLs

Parameters

  • url: The URL to parse

Returns

  • {:ok, %URI} on success
  • `{:error, “invalid url”} on failure