Skip to content

Commit

Permalink
address PR notes
Browse files Browse the repository at this point in the history
  • Loading branch information
sudorandom committed Aug 20, 2024
1 parent 4c42509 commit 80c9209
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion private/buf/bufcurl/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 11 additions & 7 deletions private/buf/cmd/buf/command/curl/curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 80c9209

Please sign in to comment.