fix: match against updated url (#962)

This commit is contained in:
Yury Semikhatsky 2022-06-24 15:13:41 -07:00 committed by GitHub
parent 4fee61a655
commit 2fdb89c94e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 6 deletions

View File

@ -177,10 +177,6 @@ public class RequestImpl extends ChannelOwner implements Request {
if (fallbackOverrides != null && fallbackOverrides.url != null) {
return fallbackOverrides.url;
}
return originalUrl();
}
String originalUrl() {
return initializer.get("url").getAsString();
}

View File

@ -42,7 +42,7 @@ class Router {
if (times != null && times <= 0) {
return false;
}
if (!matcher.test(route.request().originalUrl())) {
if (!matcher.test(route.request().url())) {
return false;
}
if (times != null) {

View File

@ -222,7 +222,7 @@ public class TestPageRequestFallback extends TestBase {
void shouldOverrideRequestUrl() throws ExecutionException, InterruptedException {
Future<Server.Request> request = server.futureRequest("/global-var.html");
String[] url = {null};
page.route("**/foo", route -> {
page.route("**/global-var.html", route -> {
url[0] = route.request().url();
route.resume();
});

View File

@ -725,4 +725,25 @@ public class TestPageRoute extends TestBase {
});
assertEquals(server.PREFIX, response.headerValue("Access-Control-Allow-Origin"));
}
@Test
void shouldChainFallbackWDynamicURL() {
List<Integer> intercepted = new ArrayList<>();
page.route("**/bar", route -> {
intercepted.add(1);
route.fallback(new Route.FallbackOptions().setUrl(server.EMPTY_PAGE));
});
page.route("**/foo", route -> {
intercepted.add(2);
route.fallback(new Route.FallbackOptions().setUrl("http://localhost/bar"));
});
page.route("**/empty.html", route -> {
intercepted.add(3);
route.fallback(new Route.FallbackOptions().setUrl("http://localhost/foo"));
});
page.navigate(server.EMPTY_PAGE);
assertEquals(asList(3, 2, 1), intercepted);
}
}