@@ -63,8 +63,6 @@ func (d *Dialer) init() {
6363func (d * Dialer ) Dial (ctx context.Context , urlStr string , reqHdr http.Header ) (* http.Response , * Session , error ) {
6464 d .initOnce .Do (func () { d .init () })
6565
66- // Technically, this is not true. DATAGRAMs could be sent using the Capsule protocol.
67- // However, quic-go currently enforces QUIC datagram support if HTTP/3 datagrams are enabled.
6866 quicConf := d .QUICConfig
6967 if quicConf == nil {
7068 quicConf = & quic.Config {EnableDatagrams : true }
@@ -117,35 +115,65 @@ func (d *Dialer) Dial(ctx context.Context, urlStr string, reqHdr http.Header) (*
117115 if err != nil {
118116 return nil , nil , err
119117 }
120- tr := & http3.Transport {
121- EnableDatagrams : true ,
122- StreamHijacker : func (ft http3.FrameType , connTracingID quic.ConnectionTracingID , str * quic.Stream , e error ) (hijacked bool , err error ) {
123- if isWebTransportError (e ) {
124- return true , nil
125- }
126- if ft != webTransportFrameType {
127- return false , nil
128- }
129- id , err := quicvarint .Read (quicvarint .NewReader (str ))
118+ tr := & http3.Transport {EnableDatagrams : true }
119+
120+ conn := tr .NewRawClientConn (qconn )
121+
122+ go func () {
123+ for {
124+ str , err := qconn .AcceptStream (context .Background ())
130125 if err != nil {
131- if isWebTransportError (err ) {
132- return true , nil
133- }
134- return false , err
126+ return
135127 }
136- d .conns .AddStream (connTracingID , str , sessionID (id ))
137- return true , nil
138- },
139- UniStreamHijacker : func (st http3.StreamType , connTracingID quic.ConnectionTracingID , str * quic.ReceiveStream , err error ) (hijacked bool ) {
140- if st != webTransportUniStreamType && ! isWebTransportError (err ) {
141- return false
128+
129+ go func () {
130+ typ , err := quicvarint .Peek (str )
131+ if err != nil {
132+ return
133+ }
134+ if typ != webTransportFrameType {
135+ conn .HandleBidirectionalStream (str )
136+ return
137+ }
138+ // read the frame type (already peeked above)
139+ if _ , err := quicvarint .Read (quicvarint .NewReader (str )); err != nil {
140+ return
141+ }
142+ // read the session ID
143+ id , err := quicvarint .Read (quicvarint .NewReader (str ))
144+ if err != nil {
145+ return
146+ }
147+ d .conns .AddStream (qconn , str , sessionID (id ))
148+ }()
149+ }
150+ }()
151+
152+ go func () {
153+ for {
154+ str , err := qconn .AcceptUniStream (context .Background ())
155+ if err != nil {
156+ return
142157 }
143- d .conns .AddUniStream (connTracingID , str )
144- return true
145- },
146- }
147158
148- conn := tr .NewClientConn (qconn )
159+ go func () {
160+ typ , err := quicvarint .Peek (str )
161+ if err != nil {
162+ return
163+ }
164+ if typ != webTransportUniStreamType {
165+ conn .HandleUnidirectionalStream (str )
166+ return
167+ }
168+ // read the stream type (already peeked above)
169+ if _ , err := quicvarint .Read (quicvarint .NewReader (str )); err != nil {
170+ return
171+ }
172+ d .conns .AddUniStream (qconn , str )
173+ }()
174+ }
175+ }()
176+
149177 select {
150178 case <- conn .ReceivedSettings ():
151179 case <- ctx .Done ():
@@ -168,7 +196,7 @@ func (d *Dialer) Dial(ctx context.Context, urlStr string, reqHdr http.Header) (*
168196 return nil , nil , errNoWebTransport
169197 }
170198
171- requestStr , err := conn .OpenRequestStream (ctx ) // TODO: put this on the Connection (maybe introduce a ClientConnection?)
199+ requestStr , err := conn .OpenRequestStream (ctx )
172200 if err != nil {
173201 return nil , nil , err
174202 }
@@ -188,7 +216,7 @@ func (d *Dialer) Dial(ctx context.Context, urlStr string, reqHdr http.Header) (*
188216 protocol = d .negotiateProtocol (protocolHeader )
189217 }
190218 sessID := sessionID (requestStr .StreamID ())
191- return rsp , d .conns .AddSession (context .WithoutCancel (ctx ), conn . Conn () , sessID , requestStr , protocol ), nil
219+ return rsp , d .conns .AddSession (context .WithoutCancel (ctx ), qconn , sessID , requestStr , protocol ), nil
192220}
193221
194222func (d * Dialer ) negotiateProtocol (theirs []string ) string {
0 commit comments