I have a program that periodically does a HTTP GET. The simplified codes
looks like that.
```
package main
import (
"log"
"net/http"
"testing"
"time"
)
func TestPlay(t *testing.T) {
for {
log.Println("starting request")
// If I use this, the test will hang forever!
// rsp, err := http.Get("
http://google.com")
client := http.Client{Timeout: time.Second * 3}
rsp, err := client.Get("
http://google.com")
if err != nil {
t.Fatal(err)
}
if err = rsp.Body.Close(); err != nil {
t.Fatal(err)
}
log.Println("request finished")
log.Println("sleeping...")
time.Sleep(time.Second * 1)
}
}
```
Problem is when a user connects to a VPN network, the request will fails
with following error.
```
main_test.go:17: Get
http://google.com: net/http: request canceled
(Client.Timeout exceeded while awaiting headers)
```
And if I didn't set timeout in http.Client, it will hang forever!
So my questions are:
- is this normal, expected behavior of http.Client?
- what is the best way to handle this? beside just retry the request?