From b93cc2c8718d6690673c3c209bfcfb21e88f744a Mon Sep 17 00:00:00 2001 From: Milinda Dias Date: Wed, 2 Jul 2025 20:44:15 +0530 Subject: [PATCH 1/2] feat: pass in response body --- v2/pkg/engine/resolve/loader.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/v2/pkg/engine/resolve/loader.go b/v2/pkg/engine/resolve/loader.go index 4b1a5e7829..010ca75684 100644 --- a/v2/pkg/engine/resolve/loader.go +++ b/v2/pkg/engine/resolve/loader.go @@ -55,10 +55,16 @@ type ResponseInfo struct { Request *http.Request // ResponseHeaders contains a clone of the headers of the response from the subgraph. ResponseHeaders http.Header + // ResponseBody contains the response body of the subgraph, it is of type string so that it cannot be manipulated. + ResponseBody string } func newResponseInfo(res *result, subgraphError error) *ResponseInfo { - responseInfo := &ResponseInfo{StatusCode: res.statusCode, Err: goerrors.Join(res.err, subgraphError)} + responseInfo := &ResponseInfo{ + StatusCode: res.statusCode, + Err: goerrors.Join(res.err, subgraphError), + ResponseBody: res.out.String(), + } if res.httpResponseContext != nil { // We're using the response.Request here, because the body will be nil (since the response was read) and won't // cause a memory leak. From 251f89e4c2a8e29345f1f93c696480e4d35ca2bd Mon Sep 17 00:00:00 2001 From: Milinda Dias Date: Wed, 9 Jul 2025 14:49:08 +0530 Subject: [PATCH 2/2] fix: update responseinfo body in struct --- v2/pkg/engine/resolve/loader.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/v2/pkg/engine/resolve/loader.go b/v2/pkg/engine/resolve/loader.go index 010ca75684..ff949cabf1 100644 --- a/v2/pkg/engine/resolve/loader.go +++ b/v2/pkg/engine/resolve/loader.go @@ -55,15 +55,19 @@ type ResponseInfo struct { Request *http.Request // ResponseHeaders contains a clone of the headers of the response from the subgraph. ResponseHeaders http.Header - // ResponseBody contains the response body of the subgraph, it is of type string so that it cannot be manipulated. - ResponseBody string + // This should be private as we do not want user's to access the raw responseBody directly + responseBody *bytes.Buffer +} + +func (ri *ResponseInfo) GetResponseBody() string { + return ri.responseBody.String() } func newResponseInfo(res *result, subgraphError error) *ResponseInfo { responseInfo := &ResponseInfo{ StatusCode: res.statusCode, Err: goerrors.Join(res.err, subgraphError), - ResponseBody: res.out.String(), + responseBody: res.out, } if res.httpResponseContext != nil { // We're using the response.Request here, because the body will be nil (since the response was read) and won't