I am trying to implement a HTTP proxy using vert.x reverse proxy to capture the incoming request and outgoing response. But for the response I am not able to capture it as a plain text whereas for the request I use interceptor that intercepts the request and logs the request as plain text. How can I capture the response as a plain text.
This is my code public Future start(Vertx vertx) { HttpClient proxyClient = vertx.createHttpClient();
HttpProxy proxy = HttpProxy.reverseProxy(proxyClient);
proxy.origin(targetPort, targetHost);
proxy.addInterceptor(new ProxyInterceptor() {
@Override
public Future<ProxyResponse> handleProxyRequest(ProxyContext context) {
ProxyRequest proxyRequest = context.request();
HttpServerRequest originalRequest = proxyRequest.proxiedRequest();
originalRequest.bodyHandler(requestBody -> {
LOG.info("Request Body: {}", requestBody.toString("UTF-8"));
});
// Continue the interception chain
return context.sendRequest();
}
});
proxy.addInterceptor(new ProxyInterceptor() {
@Override
public Future<Void> handleProxyResponse(ProxyContext context) {
ProxyResponse proxyResponse = context.response();
// there is no proxyResponse.proxiedResponse() method and no handlers for ProxyResponse either
return context.response().send();
}
});
HttpServer proxyServer = vertx.createHttpServer();
proxyServer.requestHandler(proxy).listen(listeningPort);
}
Thanks
Tried to use the same logic in request receptor for response but turns out there is no proxyResponse.proxiedResponse() method and no handlers for ProxyResponse either