diff --git a/src/main/java/com/hsbc/cranker/mucranker/CrankerMuHandler.java b/src/main/java/com/hsbc/cranker/mucranker/CrankerMuHandler.java index 48ae8f3..fd9cb5a 100644 --- a/src/main/java/com/hsbc/cranker/mucranker/CrankerMuHandler.java +++ b/src/main/java/com/hsbc/cranker/mucranker/CrankerMuHandler.java @@ -210,6 +210,12 @@ private void sendRequestOverWebSocket(MuRequest clientRequest, MuResponse client public void onDataReceived(ByteBuffer buffer, DoneCallback callback) { try { final int position = buffer.position(); + + for (ProxyListener proxyListener : proxyListeners) { + proxyListener.onBeforeRequestBodyChunkSentToTarget(crankedSocket, buffer.position(position)); + } + buffer.position(position); + final DoneCallback doneWrapper = error -> { if (error == null && !proxyListeners.isEmpty()) { for (ProxyListener proxyListener : proxyListeners) { diff --git a/src/main/java/com/hsbc/cranker/mucranker/ProxyListener.java b/src/main/java/com/hsbc/cranker/mucranker/ProxyListener.java index 98cafd7..3450de8 100644 --- a/src/main/java/com/hsbc/cranker/mucranker/ProxyListener.java +++ b/src/main/java/com/hsbc/cranker/mucranker/ProxyListener.java @@ -91,6 +91,17 @@ public interface ProxyListener { default void onAfterTargetToProxyHeadersReceived(ProxyInfo info, int status, Headers headers) throws WebApplicationException {}; + /** + * Called before a chunk of request body data is sent to the target + * This will be called many times if the body has been fragmented + * + * @param info Info about the request and response. + * @param chunk Request body data which is going to be sent to target. + * + */ + default void onBeforeRequestBodyChunkSentToTarget(ProxyInfo info, ByteBuffer chunk) {}; + + /** * Called when a chunk of request body data is sent to the target * This will be called many times if the body has been fragmented diff --git a/src/main/java/com/hsbc/cranker/mucranker/RouterSocketV3.java b/src/main/java/com/hsbc/cranker/mucranker/RouterSocketV3.java index c3be838..ecd1ae3 100644 --- a/src/main/java/com/hsbc/cranker/mucranker/RouterSocketV3.java +++ b/src/main/java/com/hsbc/cranker/mucranker/RouterSocketV3.java @@ -134,6 +134,13 @@ public void onDataReceived(ByteBuffer buffer, DoneCallback callback) { final int remaining = buffer.remaining(); final int position = buffer.position(); + if (!proxyListeners.isEmpty()) { + for (ProxyListener proxyListener : proxyListeners) { + proxyListener.onBeforeRequestBodyChunkSentToTarget(context, buffer.position(position)); + } + } + buffer.position(position); + DoneCallback wrapper = error -> { context.fromClientBytes.addAndGet(remaining);