From 4e6025204ef783f4bab676a7a392462a0b7e926b Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 9 Jun 2025 18:38:21 +0800 Subject: [PATCH 1/2] update documentation for Transport.ConnContext --- content/docs/quic/connection.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/content/docs/quic/connection.md b/content/docs/quic/connection.md index 1c266e9..ed5597a 100644 --- a/content/docs/quic/connection.md +++ b/content/docs/quic/connection.md @@ -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 } } @@ -43,6 +43,9 @@ _ = 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. +{{< /callout >}} ## Closing a Connection {#closing} From 98f762229f36645bf2083471aff935322398686f Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 9 Jun 2025 20:40:55 +0800 Subject: [PATCH 2/2] specify error code --- content/docs/quic/connection.md | 1 + 1 file changed, 1 insertion(+) diff --git a/content/docs/quic/connection.md b/content/docs/quic/connection.md index ed5597a..e346511 100644 --- a/content/docs/quic/connection.md +++ b/content/docs/quic/connection.md @@ -45,6 +45,7 @@ This allows applications to clean up state that might they might have created in {{< 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}