Skip to content

feat: add h2c (HTTP/2 cleartext) support#182

Merged
PhilipSchmid merged 1 commit intomainfrom
feat/h2c-support
Apr 8, 2026
Merged

feat: add h2c (HTTP/2 cleartext) support#182
PhilipSchmid merged 1 commit intomainfrom
feat/h2c-support

Conversation

@PhilipSchmid
Copy link
Copy Markdown
Owner

Summary

Adds HTTP/2 cleartext (h2c) support to the plain HTTP listener via a new --h2c flag / ECHO_APP_H2C environment variable.

When enabled, the HTTP listener is wrapped with h2c.NewHandler() from golang.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/h2c for upstream HTTP/2 (e.g. Cilium Gateway API with gatewayAPI.enableAppProtocol).

Changes

  • internal/config/config.go: add H2C bool field, default, and viper binding
  • cmd/echo-app/main.go: add --h2c pflag
  • internal/server/http_server.go: wrap handler with h2c.NewHandler() when cfg.H2C is true
  • go.mod: promote golang.org/x/net from indirect to direct dependency
  • internal/server/http_server_test.go: add TestH2CServer_HTTP2Negotiation — starts an h2c server and verifies resp.ProtoMajor == 2 using an http2.Transport with AllowHTTP: true
  • README.md: document ECHO_APP_H2C env var and --h2c flag

Closes #181

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>
@PhilipSchmid PhilipSchmid merged commit 0de3673 into main Apr 8, 2026
11 checks passed
@PhilipSchmid PhilipSchmid deleted the feat/h2c-support branch April 8, 2026 10:25
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.

feat: add h2c (HTTP/2 cleartext) support to HTTP listener

1 participant