@@ -8,9 +8,11 @@ import (
88 "io"
99 "net"
1010 "net/http"
11+ "net/http/httptrace"
1112 "strings"
1213 "sync"
1314 "sync/atomic"
15+ "time"
1416
1517 "golang.org/x/net/http/httpguts"
1618
@@ -114,6 +116,30 @@ var (
114116// ErrNoCachedConn is returned when RoundTripper.OnlyCachedConn is set
115117var ErrNoCachedConn = errors .New ("http3: no cached connection was available" )
116118
119+ // fakeConn is a wrapper for quic.EarlyConnection
120+ // because the quic connection does not implement net.Conn.
121+ type fakeConn struct {
122+ conn quic.EarlyConnection
123+ }
124+
125+ func (c * fakeConn ) Close () error { panic ("connection operation prohibited" ) }
126+ func (c * fakeConn ) Read (p []byte ) (int , error ) { panic ("connection operation prohibited" ) }
127+ func (c * fakeConn ) Write (p []byte ) (int , error ) { panic ("connection operation prohibited" ) }
128+ func (c * fakeConn ) SetDeadline (t time.Time ) error { panic ("connection operation prohibited" ) }
129+ func (c * fakeConn ) SetReadDeadline (t time.Time ) error { panic ("connection operation prohibited" ) }
130+ func (c * fakeConn ) SetWriteDeadline (t time.Time ) error { panic ("connection operation prohibited" ) }
131+ func (c * fakeConn ) RemoteAddr () net.Addr { return c .conn .RemoteAddr () }
132+ func (c * fakeConn ) LocalAddr () net.Addr { return c .conn .LocalAddr () }
133+
134+ func traceGotConn (trace * httptrace.ClientTrace , conn quic.EarlyConnection , reused bool ) {
135+ if trace != nil && trace .GotConn != nil {
136+ trace .GotConn (httptrace.GotConnInfo {
137+ Conn : & fakeConn {conn : conn },
138+ Reused : reused ,
139+ })
140+ }
141+ }
142+
117143// RoundTripOpt is like RoundTrip, but takes options.
118144func (r * RoundTripper ) RoundTripOpt (req * http.Request , opt RoundTripOpt ) (* http.Response , error ) {
119145 r .initOnce .Do (func () { r .initErr = r .init () })
@@ -169,6 +195,7 @@ func (r *RoundTripper) RoundTripOpt(req *http.Request, opt RoundTripOpt) (*http.
169195 r .removeClient (hostname )
170196 return nil , cl .dialErr
171197 }
198+ traceGotConn (httptrace .ContextClientTrace (req .Context ()), cl .conn , isReused )
172199 defer cl .useCount .Add (- 1 )
173200 rsp , err := cl .rt .RoundTrip (req )
174201 if err != nil {
0 commit comments