Skip to content

Automatically attempt HTTP/2 prior knowledge without flag when required - #4680

Merged
anuraaga merged 4 commits into
bufbuild:mainfrom
anuraaga:autohttp2
Sep 16, 2026
Merged

anuraaga merged 4 commits into
bufbuild:mainfrom
anuraaga:autohttp2

Conversation

@anuraaga

@anuraaga anuraaga commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Currently, --http2-prior-knowledge must always be set with http urls where HTTP/2 is required. The reality is it's generally well known if a request will require HTTP/2 or not, so this change detects those cases and implicitly enables the flag, for gRPC protocol, server reflection enabled, or bidi streaming.

After this change, users should generally not need to set --http2-prior-knowledge anymore.

Fixes #4629

@anuraaga
anuraaga requested a review from doriable September 15, 2026 05:35
in a Buf module in the current directory, using an empty request message:

$ buf curl --schema . --protocol grpc --http2-prior-knowledge \
$ buf curl --schema . --protocol grpc \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearest demonstration of the win

//
// Without this, the CLI's error interceptor would render this without details as:
//
// Failure: the server hosted at that remote is unavailable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this function is a bit hacky, it felt worth it to improve on this error message

!strings.Contains(err.Error(), "frame header looked like an HTTP/1.1 header") {
return err
}
// Format with %v rather than %w on purpose: the CLI's error interceptor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed reasonable to me, the alternative was going to be much more invasive

Comment thread cmd/buf/internal/command/curl/curl.go Outdated
// Without this, the CLI's error interceptor would render this without details as:
//
// Failure: the server hosted at that remote is unavailable.
func wrapPlainTextHTTP2Error(err error, f *flags, host string, isSecure bool) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this function taken in f or a bool with the value of f.HTTP2PriorKnowledge?

@anuraaga anuraaga Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already does doesn't it (read on 898)?

Oops got it makes sense

// The stdlib does not expose a structured way of knowing the error is from a
// HTTP/1.1-like response so do a string match, meaning this function is
// best-effort across Go versions.
!strings.Contains(err.Error(), "frame header looked like an HTTP/1.1 header") {

@jonbodner-buf jonbodner-buf Sep 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if using a structured error for this case would be a good contribution to the go standard library/(or really, golang.org/x/net). There are two places in the standard library that would need to be changed and one new exported error type as a sentinel.

@anuraaga
anuraaga merged commit 2437e41 into bufbuild:main Sep 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid having to pass --http2-prior-knowledge for every http URL

2 participants