From a10e28210ab0ab6de566460da1ea4dea741c5c9f Mon Sep 17 00:00:00 2001 From: Catherine Date: Sun, 21 Sep 2025 03:36:14 +0000 Subject: [PATCH] Enable h2c:// (cleartext HTTP/2) protocol on all http:// sockets. This allows git-pages and Caddy to efficiently use the same connection for many pipelined requests, which I hope will reduce contention when some bot decides to send fifty requests in the same millisecond. This commit also changes built-in Caddy configuration to use HTTP/2 cleartext only when talking to the backend. --- conf/Caddyfile | 6 +++--- src/main.go | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/conf/Caddyfile b/conf/Caddyfile index 48ed556..62e9986 100644 --- a/conf/Caddyfile +++ b/conf/Caddyfile @@ -51,7 +51,7 @@ http:// { redir @get https://{host}{uri} 301 # initial PUT/POST for a new domain has to happen over HTTP - reverse_proxy http://{$GIT_PAGES_ADDRESS:localhost}:3000 + reverse_proxy h2c://{$GIT_PAGES_ADDRESS:localhost}:3000 } https:// { @@ -60,9 +60,9 @@ https:// { } encode - reverse_proxy http://{$GIT_PAGES_ADDRESS:localhost}:3000 + reverse_proxy h2c://{$GIT_PAGES_ADDRESS:localhost}:3000 } http://localhost:2002 { - reverse_proxy http://{$GIT_PAGES_ADDRESS:localhost}:3002 + reverse_proxy h2c://{$GIT_PAGES_ADDRESS:localhost}:3002 } diff --git a/src/main.go b/src/main.go index ccbdff1..1174aaf 100644 --- a/src/main.go +++ b/src/main.go @@ -53,7 +53,12 @@ func serve(listener net.Listener, serve func(http.ResponseWriter, *http.Request) handler = http.HandlerFunc(serve) handler = ObserveHTTPHandler(handler) handler = panicHandler(handler) - log.Fatalln(http.Serve(listener, handler)) + + server := http.Server{Handler: handler} + server.Protocols = new(http.Protocols) + server.Protocols.SetHTTP1(true) + server.Protocols.SetUnencryptedHTTP2(true) + log.Fatalln(server.Serve(listener)) } }