From f16ffc6d1637b62c32a66407c3bfabe93c5b7b05 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 18 Jun 2025 00:29:27 +0800 Subject: [PATCH] http3: add ClientConn.Context, CloseWithError and Conn (#5219) --- http3/client.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/http3/client.go b/http3/client.go index e3155a98b..5e2e2612d 100644 --- a/http3/client.go +++ b/http3/client.go @@ -254,16 +254,27 @@ func (c *ClientConn) roundTrip(req *http.Request) (*http.Response, error) { return rsp, maybeReplaceError(err) } +// ReceivedSettings returns a channel that is closed once the server's HTTP/3 settings were received. +// Settings can be obtained from the Settings method after the channel was closed. func (c *ClientConn) ReceivedSettings() <-chan struct{} { return c.conn.ReceivedSettings() } +// Settings returns the HTTP/3 settings for this connection. +// It is only valid to call this function after the channel returned by ReceivedSettings was closed. func (c *ClientConn) Settings() *Settings { return c.conn.Settings() } -func (c *ClientConn) CloseWithError(code quic.ApplicationErrorCode, msg string) error { - return c.conn.CloseWithError(code, msg) +// CloseWithError closes the connection with the given error code and message. +// It is invalid to call this function after the connection was closed. +func (c *ClientConn) CloseWithError(code ErrCode, msg string) error { + return c.conn.CloseWithError(quic.ApplicationErrorCode(code), msg) +} + +// Context returns a context that is cancelled when the connection is closed. +func (c *ClientConn) Context() context.Context { + return c.conn.Context() } // cancelingReader reads from the io.Reader. @@ -367,3 +378,10 @@ func (c *ClientConn) doRequest(req *http.Request, str *RequestStream) (*http.Res res.Request = req return res, nil } + +// Conn returns the underlying HTTP/3 connection. +// This method is only useful for advanced use cases, such as when the application needs to +// open streams on the HTTP/3 connection (e.g. WebTransport). +func (c *ClientConn) Conn() *Conn { + return c.conn +}