I have a client which makes a request to download a file, the web server forwards this request on to the resource server that actually holds the file. The *http.Response back from the resource server has the Body io.ReaderCloser streaming the file contents from the resource server. But I'm then at the point where I want to start writing that into the original http.ResponseWriter that came from the client. Looking at the http.ResponseWriter interface it only contains a Write method which takes a slice of bytes, which makes me think that the only way to get the file contents back to the client is to read the Body io.ReaderCloser into a buffer and then put that into the http.ResponseWriter's Write method. which I dont want to do since that is hugely inefficient and it would be much better to stream it through my web server. Is this possible?
here is some code to illustrate:
getFile() *http.Response {
//make a request to resource server and return the response object
}
// handle request from client
http.HandleFunc("/getFile", func(w http.ResponseWriter, r *http.Request){
res := getFile()
//how can I stream res.Body into w without buffering ?
})