- @override
The mechanism for delivering a Request
to this controller for processing.
This method is the entry point of a Request
into this RequestController
.
By default, it invokes this controller's processRequest
method and, if that method
determines processing should continue to the nextController
and a
nextController
exists, the request will be delivered to nextController
.
An RequestSink
invokes this method on its initial controller
in its processRequest
method.
Some RequestController
s may override this method if they do not wish to
use simple chaining. For example, the Router
class overrides this method
to deliver the Request
to the appropriate RouteController
. If overriding this
method, it is important that you always invoke subsequent controller's with receive
and not processRequest
. You must also ensure that CORS requests are handled properly,
as this method does the heavy-lifting for handling CORS requests.
Source
@override Future receive(Request req) async { RequestController next; try { var requestURISegmentIterator = req.innerRequest.uri.pathSegments.iterator; if (_basePathSegments.length > 0) { for (var i = 0; i < _basePathSegments.length; i++) { requestURISegmentIterator.moveNext(); if (_basePathSegments[i] != requestURISegmentIterator.current) { await _unhandledRequestController(req); return null; } } } var remainingSegments = <String>[]; while (requestURISegmentIterator.moveNext()) { remainingSegments.add(requestURISegmentIterator.current); } if (remainingSegments.isEmpty) { remainingSegments = [""]; } var node = _rootRouteNode.nodeForPathSegments(remainingSegments); if (node?.specification == null) { await _unhandledRequestController(req); return null; } var requestPath = new HTTPRequestPath(node.specification, remainingSegments); req.path = requestPath; next = node.controller; } catch (any, stack) { return handleError(req, any, stack); } return next?.receive(req); }