diff --git a/pkg/gomuks/config.go b/pkg/gomuks/config.go index 870923f..421f08e 100644 --- a/pkg/gomuks/config.go +++ b/pkg/gomuks/config.go @@ -33,9 +33,14 @@ import ( type Config struct { Web WebConfig `yaml:"web"` + Matrix MatrixConfig `yaml:"matrix"` Logging zeroconfig.Config `yaml:"logging"` } +type MatrixConfig struct { + DisableHTTP2 bool `yaml:"disable_http2"` +} + type WebConfig struct { ListenAddress string `yaml:"listen_address"` Username string `yaml:"username"` @@ -59,6 +64,9 @@ func makeDefaultConfig() Config { Web: WebConfig{ ListenAddress: "localhost:29325", }, + Matrix: MatrixConfig{ + DisableHTTP2: false, + }, Logging: zeroconfig.Config{ MinLevel: ptr.Ptr(zerolog.DebugLevel), Writers: []zeroconfig.WriterConfig{{ diff --git a/pkg/gomuks/gomuks.go b/pkg/gomuks/gomuks.go index 11378c4..4329977 100644 --- a/pkg/gomuks/gomuks.go +++ b/pkg/gomuks/gomuks.go @@ -36,6 +36,7 @@ import ( "go.mau.fi/util/dbutil" "go.mau.fi/util/exerrors" "go.mau.fi/util/exzerolog" + "golang.org/x/net/http2" "go.mau.fi/gomuks/pkg/hicli" ) @@ -176,6 +177,15 @@ func (gmx *Gomuks) StartClient() { []byte("meow"), hicli.JSONEventHandler(gmx.OnEvent).HandleEvent, ) + httpClient := gmx.Client.Client.Client + httpClient.Transport.(*http.Transport).ForceAttemptHTTP2 = false + if !gmx.Config.Matrix.DisableHTTP2 { + _, err = http2.ConfigureTransports(httpClient.Transport.(*http.Transport)) + if err != nil { + gmx.Log.WithLevel(zerolog.FatalLevel).Err(err).Msg("Failed to configure HTTP/2") + os.Exit(13) + } + } userID, err := gmx.Client.DB.Account.GetFirstUserID(ctx) if err != nil { gmx.Log.WithLevel(zerolog.FatalLevel).Err(err).Msg("Failed to get first user ID") diff --git a/pkg/hicli/hicli.go b/pkg/hicli/hicli.go index 9969387..371010c 100644 --- a/pkg/hicli/hicli.go +++ b/pkg/hicli/hicli.go @@ -103,7 +103,7 @@ func New(rawDB, cryptoDB *dbutil.Database, log zerolog.Logger, pickleKey []byte, // Default settings from http.DefaultTransport Proxy: http.ProxyFromEnvironment, ForceAttemptHTTP2: true, - MaxIdleConns: 100, + MaxIdleConns: 5, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second,