Skip to content

Commit

Permalink
check the server's SETTINGS before sending the Extended CONNECT reque…
Browse files Browse the repository at this point in the history
…st (#151)
  • Loading branch information
marten-seemann authored Apr 27, 2024
1 parent a74676a commit 375a5dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
15 changes: 8 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,6 @@ func (d *Dialer) Dial(ctx context.Context, urlStr string, reqHdr http.Header) (*
}

conn := rt.Start()
requestStr, err := rt.OpenRequestStream(ctx) // TODO: put this on the Connection (maybe introduce a ClientConnection?)
if err != nil {
return nil, nil, err
}
if err := requestStr.SendRequestHeader(req); err != nil {
return nil, nil, err
}
select {
case <-conn.ReceivedSettings():
case <-d.ctx.Done():
Expand All @@ -157,6 +150,14 @@ func (d *Dialer) Dial(ctx context.Context, urlStr string, reqHdr http.Header) (*
return nil, nil, errNoWebTransport
}

requestStr, err := rt.OpenRequestStream(ctx) // TODO: put this on the Connection (maybe introduce a ClientConnection?)
if err != nil {
return nil, nil, err
}
if err := requestStr.SendRequestHeader(req); err != nil {
return nil, nil, err
}
// TODO(#136): create the session to allow optimistic opening of streams and sending of datagrams
rsp, err := requestStr.ReadResponse()
if err != nil {
return nil, nil, err
Expand Down
20 changes: 17 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,36 @@ func TestClientInvalidSettingsHandling(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
tlsConf := tlsConf.Clone()
tlsConf.NextProtos = []string{http3.NextProtoH3}
s, err := quic.ListenAddr("localhost:0", tlsConf, &quic.Config{EnableDatagrams: true})
ln, err := quic.ListenAddr("localhost:0", tlsConf, &quic.Config{EnableDatagrams: true})
require.NoError(t, err)
defer ln.Close()

done := make(chan struct{})
ctx, cancel := context.WithCancel(context.Background())
go func() {
conn, err := s.Accept(context.Background())
defer close(done)
conn, err := ln.Accept(context.Background())
require.NoError(t, err)
// send the SETTINGS frame
settingsStr, err := conn.OpenUniStream()
require.NoError(t, err)
_, err = settingsStr.Write(appendSettingsFrame([]byte{0} /* stream type */, tc.settings))
require.NoError(t, err)
if _, err := conn.AcceptStream(ctx); err == nil || !errors.Is(err, context.Canceled) {
require.Fail(t, "didn't expect any stream to be accepted")
}
}()

d := webtransport.Dialer{TLSClientConfig: &tls.Config{RootCAs: certPool}}
_, _, err = d.Dial(context.Background(), fmt.Sprintf("https://localhost:%d", s.Addr().(*net.UDPAddr).Port), nil)
_, _, err = d.Dial(context.Background(), fmt.Sprintf("https://localhost:%d", ln.Addr().(*net.UDPAddr).Port), nil)
require.Error(t, err)
require.ErrorContains(t, err, tc.errorStr)
cancel()
select {
case <-done:
case <-time.After(5 * time.Second):
t.Fatal("timeout")
}
})

}
Expand Down

0 comments on commit 375a5dc

Please sign in to comment.