scalecube / scalecube-gateway

ScaleCube API Gateway is the single entry point for service consumers. handles incoming requests and proxy/route to the appropriate microservice instance.
Apache License 2.0
18 stars 7 forks source link

Add interceptors on websocket gateway side #101

Closed segabriel closed 4 years ago

segabriel commented 4 years ago

This part only for WebSocket gateway acceptor so far.

I need to add more audit stuff and it should write all incoming and outgoing traffic/content. I guess the context approach (reactor.util.context.Context) can be used for it. And need to add something similar to the following invocation of two interfaces:

public interface WebsocketRequestInterceptor {

  Context handle(String gatewaySessionId, ByteBuf request, Context ctx);
}

public interface WebsocketResponseInterceptor {

  void handle(String gatewaySessionId, ByteBuf response, Context ctx);
}

As you can see WebsocketRequestInterceptor returns a new context instance which should be used with reactor.core.publisher.Mono#subscriberContext(java.util.function.Function<reactor.util.context.Context,reactor.util.context.Context>) and this context will go along with the request.

Also, it can be a replacement for invoking GatewayMetrics, it means it can be pluggable.

WDYT guys?