From b9bd821fb2a48863f41f09cbc36caf934b1f1a96 Mon Sep 17 00:00:00 2001 From: sim Date: Sat, 16 Aug 2025 21:00:20 +0200 Subject: [PATCH] feat: enable H2C for the HTTP server (#8861) 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 Co-authored-by: sim Co-committed-by: sim --- modules/graceful/server_http.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/graceful/server_http.go b/modules/graceful/server_http.go index 7c855ac64e..0b2984a953 100644 --- a/modules/graceful/server_http.go +++ b/modules/graceful/server_http.go @@ -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) }