转发代理阅读请求和响应正文

I am implementing a forward proxy in Go and I have 2 features that need to do:

  • Limit upload and download with a maximum configurable size.
  • Get md5 and sha256 of download file with a maximum configurable size for DLP purposes

Both of these features require to read request and response body and processing that would affect largely in performance by causing high memory consumption and slow response time for client.

Currently my flow is to ioutil.ReadAll request and response body, get the Body size, md5 and sha256 checksum the response body, finally if we do not blocking anything, put the body back to the origin one for the client

I was wondering if there is any other best practice for handling these kind of things.