url_tincture v0.0.3 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

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

Validate whether a string is an HTTP(S) url

Detects if URLs are HTTP or HTTPS

Normalizes http scheme/port combinations

Removes the first www. from URLs

Functions

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

force_http(url)

Prepend http:// to urls as needed.

Parameters

  • url - The URL to process

Returns

  • String containing the processed URL
http_url?(url)

Validate whether a string is an HTTP(S) url.

Adapted from github/jonotander/is_url which in turn was adapted from Stack Overflow.

Parameters

  • url: The URL to validate

Returns

  • boolean
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