Remove localDialAddr
This commit is contained in:
parent
2a9402b786
commit
1e6dbb151c
3 changed files with 9 additions and 20 deletions
|
|
@ -476,11 +476,11 @@ var testTransport = &http.Transport{
|
||||||
ResponseHeaderTimeout: 2 * time.Second,
|
ResponseHeaderTimeout: 2 * time.Second,
|
||||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
// always dial localhost for testing purposes
|
// always dial localhost for testing purposes
|
||||||
return new(net.Dialer).DialContext(ctx, network, localDialAddr(addr))
|
return new(net.Dialer).DialContext(ctx, network, addr)
|
||||||
},
|
},
|
||||||
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
// always dial localhost for testing purposes
|
// always dial localhost for testing purposes
|
||||||
conn, err := new(net.Dialer).DialContext(ctx, network, localDialAddr(addr))
|
conn, err := new(net.Dialer).DialContext(ctx, network, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,26 +30,15 @@ import (
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// localDialAddr changes the host portion of addr to be loopback,
|
|
||||||
// which is useful since we're just testing.
|
|
||||||
func localDialAddr(addr string) string {
|
|
||||||
_, port, err := net.SplitHostPort(addr)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return net.JoinHostPort("127.0.0.1", port)
|
|
||||||
}
|
|
||||||
|
|
||||||
func dial(proxyAddr, httpProxyVer string, useTLS bool) (net.Conn, error) {
|
func dial(proxyAddr, httpProxyVer string, useTLS bool) (net.Conn, error) {
|
||||||
// always dial localhost for testing purposes
|
// always dial localhost for testing purposes
|
||||||
dialAddr := localDialAddr(proxyAddr)
|
|
||||||
if useTLS {
|
if useTLS {
|
||||||
return tls.Dial("tcp", dialAddr, &tls.Config{
|
return tls.Dial("tcp", proxyAddr, &tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
NextProtos: []string{httpVersionToALPN[httpProxyVer]},
|
NextProtos: []string{httpVersionToALPN[httpProxyVer]},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return net.Dial("tcp", dialAddr)
|
return net.Dial("tcp", proxyAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getViaProxy(targetHost, resource, proxyAddr, httpProxyVer, proxyCredentials string, useTLS bool) (*http.Response, error) {
|
func getViaProxy(targetHost, resource, proxyAddr, httpProxyVer, proxyCredentials string, useTLS bool) (*http.Response, error) {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ func TestHttpClient(t *testing.T) {
|
||||||
for _, httpTargetVer := range testHTTPTargetVersions {
|
for _, httpTargetVer := range testHTTPTargetVersions {
|
||||||
for _, resource := range testResources {
|
for _, resource := range testResources {
|
||||||
// always dial localhost for testing purposes
|
// always dial localhost for testing purposes
|
||||||
proxyURL := fmt.Sprintf("%s@%s", urlSchemeAndCreds, localDialAddr(urlAddress))
|
proxyURL := fmt.Sprintf("%s@%s", urlSchemeAndCreds, urlAddress)
|
||||||
|
|
||||||
dialer, err := httpclient.NewHTTPConnectDialer(proxyURL)
|
dialer, err := httpclient.NewHTTPConnectDialer(proxyURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -26,7 +26,7 @@ func TestHttpClient(t *testing.T) {
|
||||||
}
|
}
|
||||||
dialer.DialTLS = func(network string, address string) (net.Conn, string, error) {
|
dialer.DialTLS = func(network string, address string) (net.Conn, string, error) {
|
||||||
// always dial localhost for testing purposes
|
// always dial localhost for testing purposes
|
||||||
conn, err := tls.Dial(network, localDialAddr(address), &tls.Config{
|
conn, err := tls.Dial(network, address, &tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
NextProtos: []string{httpVersionToALPN[httpProxyVer]},
|
NextProtos: []string{httpVersionToALPN[httpProxyVer]},
|
||||||
})
|
})
|
||||||
|
|
@ -37,7 +37,7 @@ func TestHttpClient(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// always dial localhost for testing purposes
|
// always dial localhost for testing purposes
|
||||||
conn, err := dialer.Dial("tcp", localDialAddr(caddyTestTarget.addr))
|
conn, err := dialer.Dial("tcp", caddyTestTarget.addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +68,7 @@ func TestHttpClientH2Multiplexing(t *testing.T) {
|
||||||
}
|
}
|
||||||
dialer.DialTLS = func(network string, address string) (net.Conn, string, error) {
|
dialer.DialTLS = func(network string, address string) (net.Conn, string, error) {
|
||||||
// always dial localhost for testing purposes
|
// always dial localhost for testing purposes
|
||||||
conn, err := tls.Dial(network, localDialAddr(address), &tls.Config{
|
conn, err := tls.Dial(network, address, &tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
NextProtos: []string{httpVersionToALPN[httpProxyVer]},
|
NextProtos: []string{httpVersionToALPN[httpProxyVer]},
|
||||||
})
|
})
|
||||||
|
|
@ -87,7 +87,7 @@ func TestHttpClientH2Multiplexing(t *testing.T) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for _, resource := range testResources {
|
for _, resource := range testResources {
|
||||||
// always dial localhost for testing purposes
|
// always dial localhost for testing purposes
|
||||||
conn, err := dialer.Dial("tcp", localDialAddr(caddyTestTarget.addr))
|
conn, err := dialer.Dial("tcp", caddyTestTarget.addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue