Skip to content

update documentation for Transport.ConnContext #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions content/docs/quic/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Applications can identify which QUIC connection these callbacks are called for b
For example:
```go
tr := quic.Transport{
ConnContext: func(ctx context.Context) context.Context {
ConnContext: func(ctx context.Context, info *quic.ClientInfo) (context.Context, error) {
// In practice, generate an identifier that's unique to this one connection,
// for example by incrementing a counter.
return context.WithValue(ctx, "foo", "bar")
return context.WithValue(ctx, "foo", "bar"), nil
}
}

Expand All @@ -43,6 +43,10 @@ _ = conn.Context()
The context passed to `ConnContext` is closed once the QUIC connection is closed, or if the handshake fails for any reason.
This allows applications to clean up state that might they might have created in the `ConnContext` callback (e.g. by using `context.AfterFunc`).

{{< callout type="info" >}}
By returning an error, `ConnContext` can also be used to reject a connection attempt at a very early stage, before the QUIC handshake is started.
In that case, the connection is closed with a CONNECTION_REFUSED error code.
{{< /callout >}}

## Closing a Connection {#closing}

Expand Down