I want to program a HTTP-Proxy in golang. I use this module for the proxy: https://github.com/elazarl/goproxy. When someone uses my proxy, it calls a function with an http.Response as an Input. Let's call it "resp". resp.Body is an io.ReadCloser. I can read from it into a []byte array by using it's Read Method. But then the contents of it are gone from the resp.Body. But I have to return an http.Response with the Body that I read into a []byte array. How can I do that?
Greetings,
Max
My Code:
proxy.OnResponse().DoFunc(func(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
body := resp.Body
var readBody []byte
nread, readerr := body.Read(readBody)
//the body is now empty
//and i have to return a body
//with the contents i read.
//how can i do that?
//doing return resp gives a Response with an empty body
}