ServerRule constructor

ServerRule(String pathPattern, RequestHandler handler)

Constructor.

The pathPattern determines if a HTTP request matches this rule or not. It is a path made up of segments separated by slashes "/".

There are different types of segments:

  • variable
  • wildcard
  • literal

Examples

"" - no segments "/" - no segments "/foo" - one literal segment "/foo/bar" - two literal segments "/foo/bar/" - three literal segments

"/foo/bar/:abc" "/foo/*" "/foo/bar?/baz"

Implementation

ServerRule(String pathPattern, this.handler) : assert(pathPattern != null) {
  _segments = pathPattern.split(_pathSeparator);

  assert(_segments.isNotEmpty);
  assert(_segments[0] == '~', 'ServerRule path does not start with ~');

  _segments.removeAt(0); // remove the leading "~".

  while (_segments.isNotEmpty && _segments[0].isEmpty) {
    _segments.removeAt(0); // remove leading slashes "/", "//", "/////"
  }

  // Examples:
  //  "" -> empty list
  //  "/" -> empty list
  //  "/foo -> "foo"
  //  "/foo/bar -> "foo", "bar"
  //  "/foo/bar/" -> "foo", "bar", ""
}