This code is a self-contained example from a large code base to try to replicate a bug. When this program is run, the address of both &request.URL.Host
and &request1.URL.Host
is same. Why? From my understanding, these are 2 different structures so URL.Host
should not have the same address.
package main
import (
"crypto/tls"
"fmt"
"net/http"
"net/url"
)
func main() {
hostname := "www.google.com"
uri, err := url.Parse("http://www.google.com/")
if err != nil {
panic(err)
}
var tlsConfig *tls.Config
tlsConfig = &tls.Config{
ServerName: hostname,
InsecureSkipVerify: true,
}
client := &http.Client{
Transport: &http.Transport{
DisableKeepAlives: true,
TLSClientConfig: tlsConfig,
},
}
request1 := &http.Request{
Header: http.Header{"User-Agent": {"Foo"}},
Host: hostname,
Method: "GET",
URL: uri,
}
request2 := &http.Request{
Header: http.Header{"User-Agent": {"Foo"}},
Host: hostname,
Method: "GET",
URL: uri,
}
fmt.Printf("Address1: %s, Address2: %s
", &request1.URL.Host, &request2.URL.Host)
resp, err := client.Do(request1)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Printf("
Response: %s", resp)
}