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.
This commit is contained in:
Catherine
2025-09-21 03:36:14 +00:00
parent 403821a150
commit a10e28210a
2 changed files with 9 additions and 4 deletions

View File

@@ -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
}

View File

@@ -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))
}
}