pass ClientInfo to Transport.ConnContext, allow rejection of handshake (#5122)

* pass *ClientInfo to ConnContext

This allows users to set some state related to the client's remote
address in `ConnContext`.

This also refuses connection early if the returned context is cancelled.

* review comments

* better error assertion

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
This commit is contained in:
sukun
2025-05-16 15:33:05 +05:30
committed by GitHub
parent 77c401dcbb
commit eb8547ca73
5 changed files with 83 additions and 23 deletions

View File

@@ -614,8 +614,8 @@ func TestHTTPContextFromQUIC(t *testing.T) {
conn := newUDPConnLocalhost(t)
tr := &quic.Transport{
Conn: conn,
ConnContext: func(ctx context.Context) context.Context {
return context.WithValue(ctx, "foo", "bar") //nolint:staticcheck
ConnContext: func(ctx context.Context, _ *quic.ClientInfo) (context.Context, error) {
return context.WithValue(ctx, "foo", "bar"), nil
},
}
defer tr.Close()