mirror of
https://github.com/Graylog2/graylog2-server.git
synced 2026-03-13 09:32:21 +08:00
Prevent 404 for /api-browser route. (#25213)
* Prevent 404 for `/api-browser` route. * Adding test case.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user