Skip to content

Commit

Permalink
change signature of dialer in newProxyDialer
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Mar 14, 2017
1 parent f4e4cc3 commit 68f5e21
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
14 changes: 2 additions & 12 deletions transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,11 @@ func dial(ctx context.Context, fn func(context.Context, string) (net.Conn, error
return fn(ctx, addr)
}
dialer := newProxyDialer(
func(addr string, d time.Duration) (net.Conn, error) {
ctx := context.Background()
var cancel context.CancelFunc
if d > 0 {
ctx, cancel = context.WithTimeout(context.Background(), d)
defer cancel()
}
func(ctx context.Context, addr string) (net.Conn, error) {
return dialContext(ctx, "tcp", addr)
},
)

if deadline, ok := ctx.Deadline(); ok {
return dialer(addr, deadline.Sub(time.Now()))
}
return dialer(addr, 0)
return dialer(ctx, addr)
}

func isTemporary(err error) bool {
Expand Down
18 changes: 3 additions & 15 deletions transport/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"net"
"net/http"
"net/url"
"time"

"golang.org/x/net/context"
)
Expand Down Expand Up @@ -113,16 +112,9 @@ func doHTTPConnectHandshake(ctx context.Context, conn net.Conn, addr string) (_
// newProxyDialer returns a dialer that connects to proxy first if necessary.
// The returned dialer checks if a proxy is necessary, dial to the proxy with the
// provided dialer, does HTTP CONNECT handshake and returns the connection.
func newProxyDialer(dialer func(string, time.Duration) (net.Conn, error)) func(string, time.Duration) (net.Conn, error) {
return func(addr string, d time.Duration) (conn net.Conn, err error) {
ctx := context.Background()
var cancel context.CancelFunc
if d > 0 {
ctx, cancel = context.WithTimeout(context.Background(), d)
defer cancel()
}
func newProxyDialer(dialer func(context.Context, string) (net.Conn, error)) func(context.Context, string) (net.Conn, error) {
return func(ctx context.Context, addr string) (conn net.Conn, err error) {
var skipHandshake bool

newAddr, err := mapAddress(ctx, addr)
if err != nil {
if err != errDisabled {
Expand All @@ -132,11 +124,7 @@ func newProxyDialer(dialer func(string, time.Duration) (net.Conn, error)) func(s
newAddr = addr
}

if deadline, ok := ctx.Deadline(); ok {
conn, err = dialer(newAddr, deadline.Sub(time.Now()))
} else {
conn, err = dialer(newAddr, 0)
}
conn, err = dialer(ctx, newAddr)
if err != nil {
return
}
Expand Down

0 comments on commit 68f5e21

Please sign in to comment.