From 80c92098aaa7c0da9c68ee3ff311d53f78bdf01c Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Tue, 20 Aug 2024 19:04:32 +0200 Subject: [PATCH] address PR notes --- private/buf/bufcurl/tls.go | 4 +++- private/buf/cmd/buf/command/curl/curl.go | 18 +++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/private/buf/bufcurl/tls.go b/private/buf/bufcurl/tls.go index 0dd1ee7655..7fd987d04b 100644 --- a/private/buf/bufcurl/tls.go +++ b/private/buf/bufcurl/tls.go @@ -38,7 +38,9 @@ type TLSSettings struct { // "h2", and exclude "http/1.1". If the server does not pick a // protocol, "h2" is assumed as the default. HTTP2PriorKnowledge bool - + // If true, the server is known to support HTTP/3. When set, the + // ALPN protocols sent during the TLS handshake will include + // only "h3", and exclude the other versions. HTTP3 bool } diff --git a/private/buf/cmd/buf/command/curl/curl.go b/private/buf/cmd/buf/command/curl/curl.go index de04661577..5833b8d1b5 100644 --- a/private/buf/cmd/buf/command/curl/curl.go +++ b/private/buf/cmd/buf/command/curl/curl.go @@ -955,10 +955,11 @@ func run(ctx context.Context, container appext.Container, f *flags) (err error) // This shouldn't be possible since we check in flags.validate, but just in case return nil, errors.New("URL positional argument is missing") } - if f.HTTP3 { - return makeHTTP3Client(f, bufcurl.GetAuthority(host, requestHeaders), container.VerbosePrinter()) + roundTripper, err := makeHTTPRoundTripper(f, isSecure, bufcurl.GetAuthority(host, requestHeaders), container.VerbosePrinter()) + if err != nil { + return nil, err } - return makeHTTPClient(f, isSecure, bufcurl.GetAuthority(host, requestHeaders), container.VerbosePrinter()) + return bufcurl.NewVerboseHTTPClient(roundTripper, container.VerbosePrinter()), nil }) output := container.Stdout() @@ -1067,7 +1068,10 @@ func run(ctx context.Context, container appext.Container, f *flags) (err error) } } -func makeHTTPClient(f *flags, isSecure bool, authority string, printer verbose.Printer) (connect.HTTPClient, error) { +func makeHTTPRoundTripper(f *flags, isSecure bool, authority string, printer verbose.Printer) (http.RoundTripper, error) { + if f.HTTP3 { + return makeHTTP3RoundTripper(f, authority, printer) + } var dialer net.Dialer if f.ConnectTimeoutSeconds != 0 { dialer.Timeout = secondsToDuration(f.ConnectTimeoutSeconds) @@ -1140,10 +1144,10 @@ func makeHTTPClient(f *flags, isSecure bool, authority string, printer verbose.P MaxIdleConns: 1, } } - return bufcurl.NewVerboseHTTPClient(transport, printer), nil + return transport, nil } -func makeHTTP3Client(f *flags, authority string, printer verbose.Printer) (connect.HTTPClient, error) { +func makeHTTP3RoundTripper(f *flags, authority string, printer verbose.Printer) (http.RoundTripper, error) { quicCfg := &quic.Config{ KeepAlivePeriod: -1, } @@ -1186,7 +1190,7 @@ func makeHTTP3Client(f *flags, authority string, printer verbose.Printer) (conne MaxResponseHeaderBytes: 0, DisableCompression: false, } - return bufcurl.NewVerboseHTTPClient(roundTripper, printer), nil + return roundTripper, nil } func secondsToDuration(secs float64) time.Duration {