I am working on a ReverseProxy based project and I am trying to figure out how to calculate the size of the entire incoming request. i.e. including headers, body & trailers.
Since speed is important, I don't want to calculate it by adding up the various fields of the parsed request, and instead was looking for a way to do it as the Incoming Request is read.
From what I can see, the readRequest function from "request.go" seems to be the most appropriate place to do this, but I am unsure about how to go about modifying this or wrapping this function to also calculate the size.
Found a solution for this here - Count sent and received bytes in Go in an http.Handler ServeHTTP function?
It can be modified to work in a Reverse Proxy scenario & does exactly what I wanted.
Update: This Github code was also very useful in the final solution. https://github.com/j0hnsmith/connspy
Now I can get the raw data received & sent over the wire when using Golang as a reverse proxy
Hope this helps someone in the future