Skip to content

Commit

Permalink
🐛 Add host header to ping response for improved diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
mkjsix committed Nov 18, 2024
1 parent ebde351 commit 477e5e8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/org/restheart/services/PingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public void handle(final ByteArrayRequest request, final ByteArrayResponse respo
.append(msg)
.append("\", \"client_ip\": \"")
.append(getClientIp(request.getExchange()))
.append("\", \"host\": \"")
.append(getHostHeader(request.getExchange()))
.append("\"}");
final String pingMessage = pingMessageBuilder.toString();
response.setContentType("application/json");
Expand All @@ -67,6 +69,10 @@ public void handle(final ByteArrayRequest request, final ByteArrayResponse respo
}
}

private String getHostHeader(final HttpServerExchange exchange) {
return exchange.getRequestHeaders().getFirst("Host");
}

private String getClientIp(final HttpServerExchange exchange) {
// Get the X-Forwarded-For header from the request
final String forwardedFor = exchange.getRequestHeaders().getFirst("X-Forwarded-For");
Expand Down

0 comments on commit 477e5e8

Please sign in to comment.