Skip to content

Commit

Permalink
UNDERTOW-1581: Fix RoutingHandler allMethodsMatcher validation
Browse files Browse the repository at this point in the history
Updates the allMethodsMatcher to lookup templates using the
match method instead of get in order to normalize the input.

Previously registration would throw an exception when routes
were added for the same path template with different parameter names
despite being equivalent.

From undertow-io/undertow#799
  • Loading branch information
carterkozak authored and gsmet committed Apr 18, 2024
1 parent 6d0a3ca commit 2d6cdd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/io/undertow/server/RoutingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public synchronized RoutingHandler add(String method, String template, HttpHandl
if (res == null) {
matcher.add(template, res = new RoutingMatch());
}
if (allMethodsMatcher.get(template) == null) {
if (allMethodsMatcher.match(template) == null) {
allMethodsMatcher.add(template, res);
}
res.defaultHandler = handler;
Expand Down Expand Up @@ -152,7 +152,7 @@ public synchronized RoutingHandler add(String method, String template, Predicate
if (res == null) {
matcher.add(template, res = new RoutingMatch());
}
if (allMethodsMatcher.get(template) == null) {
if (allMethodsMatcher.match(template) == null) {
allMethodsMatcher.add(template, res);
}
res.predicatedHandlers.add(new HandlerHolder(predicate, handler));
Expand Down Expand Up @@ -186,7 +186,7 @@ public synchronized RoutingHandler addAll(RoutingHandler routingHandler) {
// If we use allMethodsMatcher.addAll() we can have duplicate
// PathTemplates which we want to ignore here so it does not crash.
for (PathTemplate template : entry.getValue().getPathTemplates()) {
if (allMethodsMatcher.get(template.getTemplateString()) == null) {
if (allMethodsMatcher.match(template.getTemplateString()) == null) {
allMethodsMatcher.add(template, new RoutingMatch());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.writeAsync("posted foo");
}
})
.add(HttpMethodNames.POST, "/foo/{baz}", new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.writeAsync("foo-path" + exchange.getQueryParameters().get("bar"));
}
})
.add(HttpMethodNames.GET, "/foo/{bar}", new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
Expand Down

0 comments on commit 2d6cdd9

Please sign in to comment.