add support for plain h2c

This commit is contained in:
Dmitry Rubtsov 2022-09-19 17:06:32 +06:00
parent 42bd0615c2
commit 95771c7aba
No known key found for this signature in database
GPG Key ID: 4B1E43D13E6D4311

View File

@ -15,6 +15,8 @@ import (
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/netutil"
"github.com/NYTimes/gziphandler"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
)
// HTTP scheme constants.
@ -167,12 +169,15 @@ func (web *Web) Start() {
printHTTPAddresses(schemeHTTP)
errs := make(chan error, 2)
// h2s adds support for plain h2c
h2s := &http2.Server{}
hostStr := web.conf.BindHost.String()
// we need to have new instance, because after Shutdown() the Server is not usable
web.httpServer = &http.Server{
ErrorLog: log.StdLog("web: plain", log.DEBUG),
Addr: netutil.JoinHostPort(hostStr, web.conf.BindPort),
Handler: withMiddlewares(Context.mux, limitRequestBody),
Handler: h2c.NewHandler(withMiddlewares(Context.mux, limitRequestBody), h2s),
ReadTimeout: web.conf.ReadTimeout,
ReadHeaderTimeout: web.conf.ReadHeaderTimeout,
WriteTimeout: web.conf.WriteTimeout,
@ -202,10 +207,13 @@ func (web *Web) startBetaServer(hostStr string) {
return
}
// h2s adds support for plain h2c
h2s := &http2.Server{}
web.httpServerBeta = &http.Server{
ErrorLog: log.StdLog("web: plain: beta", log.DEBUG),
Addr: netutil.JoinHostPort(hostStr, web.conf.BetaBindPort),
Handler: withMiddlewares(Context.mux, limitRequestBody, web.wrapIndexBeta),
Handler: h2c.NewHandler(withMiddlewares(Context.mux, limitRequestBody, web.wrapIndexBeta), h2s),
ReadTimeout: web.conf.ReadTimeout,
ReadHeaderTimeout: web.conf.ReadHeaderTimeout,
WriteTimeout: web.conf.WriteTimeout,