diff --git a/coprocess/grpc/coprocess_grpc_test.go b/coprocess/grpc/coprocess_grpc_test.go index 9a670dae777..a97fb7c41b8 100644 --- a/coprocess/grpc/coprocess_grpc_test.go +++ b/coprocess/grpc/coprocess_grpc_test.go @@ -11,10 +11,13 @@ import ( "net" "net/http" "os" + "strconv" "strings" "testing" "time" + "github.com/TykTechnologies/tyk/header" + "github.com/stretchr/testify/assert" "google.golang.org/grpc" @@ -567,6 +570,9 @@ func TestGRPCDispatch(t *testing.T) { Code: http.StatusOK, Headers: headers, BodyMatch: "newbody", + HeadersMatch: map[string]string{ + header.ContentLength: strconv.Itoa(len("newbody")), + }, }) }) diff --git a/gateway/coprocess.go b/gateway/coprocess.go index 362b1cdc8ab..36663ed8f45 100644 --- a/gateway/coprocess.go +++ b/gateway/coprocess.go @@ -598,6 +598,12 @@ func (h *CustomMiddlewareResponseHook) HandleResponse(rw http.ResponseWriter, re bodyBuf := bytes.NewBuffer(retObject.Response.RawBody) res.Body = ioutil.NopCloser(bodyBuf) + //set response body length with the size of response body returned from the hook + //so that it is updated accordingly in the response object + responseBodyLen := len(retObject.Response.RawBody) + res.ContentLength = int64(responseBodyLen) + res.Header.Set("Content-Length", fmt.Sprintf("%d", responseBodyLen)) + res.StatusCode = int(retObject.Response.StatusCode) return nil }