I'm trying to measure successive load times of a URL, but have been unable to drop an http connection and start fresh with each measurement. With this code...
func getloadtime (url string) float64 {
// setup client
tr := &http.Transport{
DisableKeepAlives: true}
client := &http.Client{Transport:tr}
// page load and measure
start := time.Now()
_, _ = client.Get(url)
return(time.Since(start).Seconds())
}
func main () {
for i := 0; i < 5; i++ {
fmt.Println(getloadtime("http://www.google.com"))
}
}
I get measurements like this:
2.75
0.13
0.09
0.12
0.115
So it appears the http connection is being maintained from the initial load since the subsequent loads are much faster. I have also tried setting "Connection" to "Close" in the header, but get the same results:
req, err := http.NewRequest("GET", url, nil)
req.Header.Set("Connection", "close")
_, _ := client.Do(req)
What am I doing wrong?