使用http.ResponseBody时测量上载速度

Is there a way to measure a client's download speed when uploading a large quantity of data using an http.ResponseWriter?

Update for context: I'm writing a streaming download endpoint for blob storage which stores blobs in chunks. The files are very large, so loading and buffering whole blobs is not feasible. Being able to monitor the buffer state, bytes written or similar would allow better scheduling of the chunk downloads.

E.g. when Write()ing to the response, is there a way to check how much data is already queued?

An example of the context, but not using a file object.

func downloadHandler(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
    // Open some file.
    f := os.Open("somefile.txt")

    // Adjust the iteration speed of this loop to the client's download speed.
    for
    { 
        data := make([]byte, 1000)
        count, err := f.Read(data)
        if err != nil {
            log.Fatal(err)
        }
        if count == 0 {
            break
        }
       // Upload data chunk to client.
       w.Write(data[:count])
    }
}

You could implement a custom http.ResponseWriter that measures bytes sent, and calculates throughput.

There are likely packages to do similar things already. Google found this one (which I haven't used).