Skip to content

Commit 9e57d05

Browse files
committed
h2 cl conn pool prep fn
1 parent 85fd463 commit 9e57d05

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

dialer/h2.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ func H2ProxyDialerFromURL(u *url.URL, next xproxy.Dialer) (xproxy.Dialer, error)
6161
AllowHTTP: h2c,
6262
TLSClientConfig: tlsConfig,
6363
}
64+
t.ConnPool = &clientConnPool{
65+
t: t,
66+
prepare: func(ctx context.Context, c *http2.ClientConn) (*http2.ClientConn, error) {
67+
return c, nil
68+
},
69+
}
6470
nextDialer := MaybeWrapWithContextDialer(next)
6571
if h2c {
6672
t.DialTLSContext = func(ctx context.Context, network, _ string, _ *tls.Config) (net.Conn, error) {

dialer/h2_client_conn_pool.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type clientConnPool struct {
2929
dialing map[string]*dialCall // currently in-flight dials
3030
keys map[*http2.ClientConn][]string
3131
addConnCalls map[string]*addConnCall // in-flight addConnIfNeeded calls
32+
prepare func(context.Context, *http2.ClientConn) (*http2.ClientConn, error)
3233
}
3334

3435
func (p *clientConnPool) GetClientConn(req *http.Request, addr string) (*http2.ClientConn, error) {
@@ -78,7 +79,14 @@ func (p *clientConnPool) dialClientConn(ctx context.Context, addr string) (*http
7879
if err != nil {
7980
return nil, err
8081
}
81-
return p.t.NewClientConn(tconn)
82+
cc, err := p.t.NewClientConn(tconn)
83+
if err != nil {
84+
return nil, err
85+
}
86+
if p.prepare != nil {
87+
return p.prepare(ctx, cc)
88+
}
89+
return cc, nil
8290
}
8391

8492
func (p *clientConnPool) dialTLS(ctx context.Context, network, addr string, tlsCfg *tls.Config) (net.Conn, error) {

0 commit comments

Comments
 (0)