I'm trying to create a middleware in Shelf that will inspect the request, and if certain values are found the request will be handled, otherwise it should be sent to the inner handler. Eg. I would like to inspect the Request.method.
Handler middleware(Handler innerHandler) {
return (Request req) async {
if(req.method == "GET" && req.headers["xxx"] == yyy) {
// Handle the request
...
}
else {
// This gives exception:
// Bad state: The 'read' method can only be called once on a shelf.Request/shelf.Response object.
return innerHandler(req);
}
}
The problem is that it is not possible to call the inner handler after the Request has been inspected. How do I go about inspecting it but still being able to send it along to the inner handler?