Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/unreleased/pr-24590.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type = "f"
message = "Return 404 instead of HTML for non-existent API methods."

pulls = ["24590"]
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class HttpConfiguration {
private static final int GRAYLOG_DEFAULT_PORT = 9000;

public static final String OVERRIDE_HEADER = "X-Graylog-Server-URL";
public static final String PATH_API = "api/";
public static final String API_PREFIX = "api";
public static final String PATH_API = API_PREFIX + "/";

@Documentation("""
## HTTP bind address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ private String removeTrailingSlash(String basePath) {
@Path("{filename:.*}")
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)) {
return Response.status(Response.Status.NOT_FOUND).build();
}
final URI originalLocation = request.getRequestUri();
return get(request, headers, originalLocation.getPath());
}
Expand Down
Loading