Skip to content

Commit 4b8d31d

Browse files
update documentation for Transport.ConnContext (#92)
* update documentation for Transport.ConnContext * specify error code
1 parent c897252 commit 4b8d31d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

content/docs/quic/connection.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ Applications can identify which QUIC connection these callbacks are called for b
1818
For example:
1919
```go
2020
tr := quic.Transport{
21-
ConnContext: func(ctx context.Context) context.Context {
21+
ConnContext: func(ctx context.Context, info *quic.ClientInfo) (context.Context, error) {
2222
// In practice, generate an identifier that's unique to this one connection,
2323
// for example by incrementing a counter.
24-
return context.WithValue(ctx, "foo", "bar")
24+
return context.WithValue(ctx, "foo", "bar"), nil
2525
}
2626
}
2727

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

46+
{{< callout type="info" >}}
47+
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.
48+
In that case, the connection is closed with a CONNECTION_REFUSED error code.
49+
{{< /callout >}}
4650

4751
## Closing a Connection {#closing}
4852

0 commit comments

Comments
 (0)