Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions conformance/utils/echo/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (m *MeshPod) MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T,
t.Helper()

http.AwaitConvergence(t, timeoutConfig.RequiredConsecutiveSuccesses, timeoutConfig.MaxTimeToConsistency, func(elapsed time.Duration) bool {
req := makeRequest(exp.Request)
req := makeRequest(t, exp.Request)

resp, err := m.request(req)
if err != nil {
Expand All @@ -76,12 +76,12 @@ func (m *MeshPod) MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T,
t.Logf("Request passed")
}

func makeRequest(r http.Request) []string {
func makeRequest(t *testing.T, r http.Request) []string {
protocol := strings.ToLower(r.Protocol)
if protocol == "" {
protocol = "http"
}
host := calculateHost(r.Host, protocol)
host := calculateHost(t, r.Host, protocol)
args := []string{"client", fmt.Sprintf("%s://%s%s", protocol, host, r.Path)}
if r.Method != "" {
args = append(args, "--method="+r.Method)
Expand Down Expand Up @@ -113,10 +113,16 @@ func compareRequest(exp http.ExpectedResponse, resp Response) error {
return nil
}

// copied from conformance/http to get the ipv6 matching
func calculateHost(reqHost, scheme string) string {
host, port, err := net.SplitHostPort(reqHost)
func calculateHost(t *testing.T, reqHost, scheme string) string {
host, port, err := net.SplitHostPort(reqHost) // note: this will strip brackets of an IPv6 address
if err != nil && strings.Contains(err.Error(), "too many colons in address") {
// This is an IPv6 address; assume it's valid ipv6
// Assume caller won't add a port without brackets
reqHost = "[" + reqHost + "]"
host, port, err = net.SplitHostPort(reqHost)
}
if err != nil {
t.Logf("Failed to parse host %q: %v", reqHost, err)
return reqHost
}
if strings.ToLower(scheme) == "http" && port == "80" {
Expand Down
13 changes: 10 additions & 3 deletions conformance/utils/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func MakeRequest(t *testing.T, expected *ExpectedResponse, gwAddr, protocol, sch
}

path, query, _ := strings.Cut(expected.Request.Path, "?")
reqURL := url.URL{Scheme: scheme, Host: calculateHost(gwAddr, scheme), Path: path, RawQuery: query}
reqURL := url.URL{Scheme: scheme, Host: calculateHost(t, gwAddr, scheme), Path: path, RawQuery: query}

t.Logf("Making %s request to %s", expected.Request.Method, reqURL.String())

Expand Down Expand Up @@ -145,9 +145,16 @@ func MakeRequest(t *testing.T, expected *ExpectedResponse, gwAddr, protocol, sch
// case of any error, the input gwAddr will be returned as the default.
//
// [HTTP spec]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23
func calculateHost(gwAddr, scheme string) string {
host, port, err := net.SplitHostPort(gwAddr)
func calculateHost(t *testing.T, gwAddr, scheme string) string {
host, port, err := net.SplitHostPort(gwAddr) // note: this will strip brackets of an IPv6 address
if err != nil && strings.Contains(err.Error(), "too many colons in address") {
// This is an IPv6 address; assume it's valid ipv6
// Assume caller won't add a port without brackets
gwAddr = "[" + gwAddr + "]"
host, port, err = net.SplitHostPort(gwAddr)
}
if err != nil {
t.Logf("Failed to parse host %q: %v", gwAddr, err)
return gwAddr
}
if strings.ToLower(scheme) == "http" && port == "80" {
Expand Down