feat: enable H2C for the HTTP server (#8861)
Some checks failed
testing-integration / test-sqlite (push) Has been skipped
testing-integration / test-unit (push) Has been skipped
testing-integration / test-mariadb (v11.8) (push) Has been skipped
testing-integration / test-mariadb (v10.6) (push) Has been skipped
testing / frontend-checks (push) Has been skipped
testing / backend-checks (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / security-check (push) Has been skipped
/ release (push) Has been cancelled

This PR adds HTTP/2 Cleartext (H2C) support for the HTTP server, this allows for reverse proxies to use HTTP/2 instead.

## Test
1. Start Forgejo.
2. Run `curl --http2-prior-knowledge http://localhost:3000`.
3. Observe it doesn't return a error.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8861
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: sim <git@sgougeon.fr>
Co-committed-by: sim <git@sgougeon.fr>
This commit is contained in:
sim 2025-08-16 21:00:20 +02:00 committed by Gusted
commit b9bd821fb2

View file

@ -16,6 +16,11 @@ func newHTTPServer(network, address, name string, handler http.Handler) (*Server
Handler: handler,
BaseContext: func(net.Listener) context.Context { return GetManager().HammerContext() },
}
// Enable H2C for HTTP server
httpServer.Protocols = new(http.Protocols)
httpServer.Protocols.SetHTTP1(true)
httpServer.Protocols.SetHTTP2(true)
httpServer.Protocols.SetUnencryptedHTTP2(true)
server.OnShutdown = func() {
httpServer.SetKeepAlivesEnabled(false)
}