add method
Add handler for verb requests to route.
If verb is GET the handler will also be called for HEAD requests
matching route. This is because handling GET requests without handling
HEAD is always wrong. To explicitely implement a HEAD handler it must
be registered before the GET handler.
Implementation
void add(String verb, String route, Function handler) {
if (!isHttpMethod(verb)) {
throw ArgumentError.value(verb, 'verb', 'expected a valid HTTP method');
}
verb = verb.toUpperCase();
if (verb == 'GET') {
// Handling in a 'GET' request without handling a 'HEAD' request is always
// wrong, thus, we add a default implementation that discards the body.
_routes.add(RouterEntry('HEAD', route, handler, middleware: _removeBody));
}
_routes.add(RouterEntry(verb, route, handler));
}