Prevent 404 for /api-browser route. (#25213)

* Prevent 404 for `/api-browser` route.

* Adding test case.
This commit is contained in:
Dennis Oelkers
2026-03-05 11:11:18 +01:00
committed by GitHub
parent b381af8dbc
commit b643c2024c
2 changed files with 12 additions and 1 deletions

View File

@@ -59,5 +59,14 @@ public abstract class WebInterfaceAssetsResourceBase {
.statusCode(HttpStatus.SC_OK)
.contentType(ContentType.JSON);
});
// Testing that the special `/api-browser` route is not returning a 404
backend()
.get(prefix + "api-browser")
.then()
.log().ifError()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.contentType(ContentType.HTML);
}
}

View File

@@ -163,7 +163,9 @@ public class WebInterfaceAssetsResource {
public Response getIndex(@Context ContainerRequest request,
@Context HttpHeaders headers) {
// If we end up here, the request should go to the API, but no resource class matched it, so we return a 404.
if (request.getAbsolutePath().getPath().startsWith("/" + HttpConfiguration.API_PREFIX)) {
final var path = request.getAbsolutePath().getPath();
final var apiPrefix = "/" + HttpConfiguration.API_PREFIX;
if (path.equals(apiPrefix) || path.startsWith(apiPrefix + "/")) {
return Response.status(Response.Status.NOT_FOUND).build();
}
final URI originalLocation = request.getRequestUri();