From 7f61dd34c007b14f160d01b47cea7c9c3baf3f86 Mon Sep 17 00:00:00 2001 From: marioevz Date: Fri, 17 Jun 2022 18:04:03 +0000 Subject: [PATCH] proxy: add request bytes to response callback --- proxy/proxy.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index 8560b16..05a8452 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -32,8 +32,11 @@ type SpoofingConfig struct { } type SpoofingCallbacks struct { - RequestCallbacks map[string]func([]byte) *Spoof - ResponseCallbacks map[string]func([]byte) *Spoof + // Map of method names to callbacks, where the callback will receive the request bytes as only parameter + RequestCallbacks map[string]func([]byte) *Spoof + // Map of method names to callbacks, where the callback will receive the response bytes as 1st parameter, + // and original request bytes as 2nd parameter + ResponseCallbacks map[string]func([]byte, []byte) *Spoof } type Spoof struct { @@ -304,7 +307,7 @@ func spoofResponse(config *SpoofingConfig, callbacks *SpoofingCallbacks, request desiredMethodsToSpoof := make(map[string]*Spoof) for method, spoofCallback := range callbacks.ResponseCallbacks { if method == jsonRequest.Method { - spoofReq := spoofCallback(responseBytes) + spoofReq := spoofCallback(responseBytes, requestBytes) if spoofReq != nil { desiredMethodsToSpoof[jsonRequest.Method] = spoofReq }