feat: add h2c (HTTP/2 cleartext) support#182
Merged
PhilipSchmid merged 1 commit intomainfrom Apr 8, 2026
Merged
Conversation
Add --h2c flag and ECHO_APP_H2C env var that wraps the plain HTTP listener with h2c.NewHandler(), enabling HTTP/2 cleartext on the existing HTTP port without requiring a separate listener. - Add H2C bool field to Config struct with viper wiring - Add --h2c pflag in main.go - Promote golang.org/x/net to a direct dependency - Wrap handler with h2c.NewHandler() when cfg.H2C is true - Add TestH2CServer_HTTP2Negotiation to verify ProtoMajor == 2 - Document ECHO_APP_H2C and --h2c in README.md Closes #181 Signed-off-by: Philip Schmid <phisch@cisco.com>
316a1bd to
c4e1581
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds HTTP/2 cleartext (h2c) support to the plain HTTP listener via a new
--h2cflag /ECHO_APP_H2Cenvironment variable.When enabled, the HTTP listener is wrapped with
h2c.NewHandler()fromgolang.org/x/net/http2/h2c, allowing it to accept both HTTP/1.1 and HTTP/2 cleartext connections on the same port — no separate listener or TLS required.This is needed for backends behind a Gateway API proxy that uses
appProtocol: kubernetes.io/h2cfor upstream HTTP/2 (e.g. Cilium Gateway API withgatewayAPI.enableAppProtocol).Changes
internal/config/config.go: addH2C boolfield, default, and viper bindingcmd/echo-app/main.go: add--h2cpflaginternal/server/http_server.go: wrap handler withh2c.NewHandler()whencfg.H2Cis truego.mod: promotegolang.org/x/netfrom indirect to direct dependencyinternal/server/http_server_test.go: addTestH2CServer_HTTP2Negotiation— starts an h2c server and verifiesresp.ProtoMajor == 2using anhttp2.TransportwithAllowHTTP: trueREADME.md: documentECHO_APP_H2Cenv var and--h2cflagCloses #181