From eebd6b1d10cd0c8ec6daf6d41244525f029a0894 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 8 Oct 2025 11:40:02 +0300 Subject: [PATCH] Ability to disable HTTP/2 --- cmd/godlighty/main.go | 10 ++++++++++ godlighty.go | 2 +- tls.go | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/godlighty/main.go b/cmd/godlighty/main.go index 5ca0380..6cbba08 100644 --- a/cmd/godlighty/main.go +++ b/cmd/godlighty/main.go @@ -46,6 +46,7 @@ var ( func main() { bind := flag.String("bind", "[::]:80", "Address to bind and listen on") doTLS := flag.Bool("tls", false, "Enable TLS") + noH2 := flag.Bool("no-h2", false, "Disable HTTP/2") doSetUID := flag.Int("setuid", 0, "Set that UID after binding the socket") doSetGID := flag.Int("setgid", 0, "Set that GID after binding the socket") doSetGIDs := flag.String("setgids", "", "Comma-separated GIDs to set") @@ -108,6 +109,15 @@ func main() { Handler: godlighty.MainHandler, ReadHeaderTimeout: RWTimeout, IdleTimeout: time.Minute, + Protocols: &http.Protocols{}, + } + srv.Protocols.SetHTTP1(true) + if *noH2 { + godlighty.NextProtos = []string{"http/1.1"} + } else { + godlighty.NextProtos = []string{"h2", "http/1.1"} + srv.Protocols.SetHTTP2(true) + srv.Protocols.SetUnencryptedHTTP2(true) } go func() { <-shutdown diff --git a/godlighty.go b/godlighty.go index 895b10c..834266e 100644 --- a/godlighty.go +++ b/godlighty.go @@ -1,6 +1,6 @@ // Highly-customizable HTTP, HTTP/2, HTTPS server package godlighty -const Version = "godlighty/0.9.0" +const Version = "godlighty/0.10.0" var BindAddr string diff --git a/tls.go b/tls.go index 7ccc8f7..e42b06f 100644 --- a/tls.go +++ b/tls.go @@ -27,7 +27,7 @@ import ( ) var ( - NextProtos = []string{"h2", "http/1.1"} + NextProtos []string HostToECDSACertificate map[string]*tls.Certificate HostECDSAClientAuth map[string]*x509.CertPool -- 2.51.0