canonical_url 1.1.0 copy "canonical_url: ^1.1.0" to clipboard
canonical_url: ^1.1.0 copied to clipboard

The UrlCanonicalizer is used for the process of converting an URL into a canonical (normalized) form.

canonical_url #

The UrlCanonicalizer is used for the process of converting an URL into a canonical (normalized) form. It will:

  • make scheme and host lowercase
  • remove port if it matches the default (80, 443)
  • canonicalize path (e.g. /a/../, /a/./)
  • sort query parameters (default)
  • use query parameter ordering (optional)
  • whitelist / blacklist parameters (optional)
  • remove fragment (optional)

It can also calculate the url relative to a context (e.g. base url + relative link).

Usage #

A simple usage example:

import 'package:canonical_url/canonical_url.dart';

main() {
  final urlc = new UrlCanonicalizer(removeFragment: true);

  // prints http://example.com/b.txt
  print(urlc.canonicalize('http://example.com:80/a/../b.txt'));

  // prints https://example.com/abc
  print(urlc.canonicalize('https://example.com/abc#xyz'));

  // prints http://example.com/api?a=2&b=3&c=1
  print(urlc.canonicalize('http://example.com/api?c=1&a=2&b=3'));
}
2
likes
130
pub points
47%
popularity

Publisher

verified publisheragilord.com

The UrlCanonicalizer is used for the process of converting an URL into a canonical (normalized) form.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

path

More

Packages that depend on canonical_url