Closed cgarciae closed 9 years ago
The router library is responsible for handling http requests, and it contains the implementation of the Chain interface. Take a look at the forward method here
It seems that this method is handling urls completely wrong:
var newUrl = req.requestedUri.resolve(url);
It should do something like this:
var newUrl = url.startsWith('/') ? Uri.parse(url) : _joinUrl(req.requestedUri.toString(), url);
Apart from small modifications, this code produces the same behavior: even if the new URL is the correct one, it triggers the old route.
Future<shelf.Response> forward(String url,
{Map<String, String> headers}) async {
var req = currentContext.request;
var newUrl = url.startsWith('/') ? req.requestedUri.resolve(url) : Router._joinUrl(req.requestedUri.toString(), url);
var shelfReqCtx = new Map.from(req.attributes);
var newReq = new shelf.Request("GET", newUrl
,headers: headers, context: shelfReqCtx);
return _forwardShelfHandler(newReq);
}
My intuition is that _forwardShelfHandler
but the inner workings of shelf are a mystery to me.
I've created the branch #123
with my changes if you want to look at them.
_forwardShelfHandler is just a shelf handler that creates a new chain object, and executes it with the new request.
The problem is that the chain implementation is always looking to the original HttpRequest object when searching for handlers that match the request, instead of looking to the current shelf request.
I've made some changes that fix this behaviour, and it seems to work fine now, although it needs more proper tests.
@luizmineo thanks a lot. I am using the redstone MVC plugin but had to implement some client scripts for redirecting, hopefully with this I won't need to.
I am doing a test for some other feature/bug concerning redirection, I found some other bug,
chain.forward
is not forwarding. Here are my routeswhen the test calls
/test_wrapper/redirect
I getA
printed on the screen forever, as if its "forwarding" to itself, it is very weird.