Skip to content

Commit

Permalink
* sse: log clientIP on sse:close action
Browse files Browse the repository at this point in the history
Signed-off-by: neo <1100909+neowu@users.noreply.github.com>
  • Loading branch information
neowu committed Mar 3, 2025
1 parent bc1d147 commit e35fad8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 9.1.7 (2/26/2025 - )

* sse: send ErrorResponse to client via "event: error" on exception
* sse: log clientIP on sse:close action

### 9.1.6 (2/10/2025 - 2/25/2025)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ class ServerSentEventCloseHandler<T> implements ExchangeCompletionListener {
final ServerSentEventContextImpl<T> context;
private final LogManager logManager;
private final ChannelImpl<T> channel;
private final String clientIP;

ServerSentEventCloseHandler(LogManager logManager, ChannelImpl<T> channel, ServerSentEventContextImpl<T> context) {
ServerSentEventCloseHandler(LogManager logManager, ChannelImpl<T> channel, ServerSentEventContextImpl<T> context, String clientIP) {
this.logManager = logManager;
this.channel = channel;
this.context = context;
this.clientIP = clientIP;
}

@Override
Expand All @@ -34,6 +36,7 @@ public void exchangeEvent(HttpServerExchange exchange, NextListener next) {
List<String> refIds = List.of(channel.refId);
actionLog.refIds = refIds;
actionLog.correlationIds = refIds;
actionLog.context.put("client_ip", List.of(clientIP));
if (!channel.groups.isEmpty()) actionLog.context("group", channel.groups.toArray());
context.remove(channel);
channel.shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void handle(HttpServerExchange exchange, StreamSinkChannel sink) {
actionLog.context("channel", channel.id);
sink.getWriteSetter().set(channel.writeListener);
support.context.add(channel);
exchange.addExchangeCompleteListener(new ServerSentEventCloseHandler<>(logManager, channel, support.context));
exchange.addExchangeCompleteListener(new ServerSentEventCloseHandler<>(logManager, channel, support.context, request.clientIP()));

channel.sendBytes(Strings.bytes("retry: 5000\n\n")); // set browser retry to 5s

Expand Down

0 comments on commit e35fad8

Please sign in to comment.