diff --git a/go.mod b/go.mod index 37462cd54..aada2ab1f 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/cometbft/cometbft v0.38.12 github.com/dgraph-io/badger/v3 v3.2103.5 github.com/ethereum/go-ethereum v1.14.8 + github.com/go-chi/chi/v5 v5.1.0 github.com/jackc/pglogrepl v0.0.0-20240307033717-828fbfe908e9 github.com/jackc/pgx/v5 v5.6.0 github.com/jpillora/backoff v1.0.0 diff --git a/go.sum b/go.sum index 6129d97dc..9af86cccf 100644 --- a/go.sum +++ b/go.sum @@ -145,6 +145,8 @@ github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqG github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps= github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= +github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= +github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-kit/kit v0.12.0 h1:e4o3o3IsBfAKQh5Qbbiqyfu97Ku7jrO/JbohvztANh4= diff --git a/internal/services/jsonrpc/server.go b/internal/services/jsonrpc/server.go index c203c8947..56d4a8c39 100644 --- a/internal/services/jsonrpc/server.go +++ b/internal/services/jsonrpc/server.go @@ -23,6 +23,7 @@ import ( "syscall" "time" + "github.com/go-chi/chi/v5/middleware" "github.com/prometheus/client_golang/prometheus" "github.com/kwilteam/kwil-db/core/log" @@ -286,6 +287,9 @@ func NewServer(addr string, log log.Logger, opts ...Opt) (*Server, error) { if cfg.enableCORS { h = corsHandler(h) } + + compMW := middleware.Compress(5) + h = compMW(h) h = reqCounter(h, metrics[reqCounterName]) h = realIPHandler(h, cfg.proxyCount) // for effective rate limiting h = recoverer(h, log) // first, wrap with defer and call next ^ @@ -305,6 +309,7 @@ func NewServer(addr string, log log.Logger, opts ...Opt) (*Server, error) { w.Header().Set("content-type", "application/json; charset=utf-8") http.ServeContent(w, r, "openrpc.json", time.Time{}, bytes.NewReader(s.spec)) }) + specHandler = compMW(specHandler) if cfg.enableCORS { specHandler = corsHandler(specHandler) } @@ -317,6 +322,7 @@ func NewServer(addr string, log log.Logger, opts ...Opt) (*Server, error) { if cfg.enableCORS { healthHandler = corsHandler(healthHandler) } + healthHandler = compMW(healthHandler) healthHandler = recoverer(healthHandler, log) mux.Handle(pathHealthV1, healthHandler) @@ -326,6 +332,7 @@ func NewServer(addr string, log log.Logger, opts ...Opt) (*Server, error) { if cfg.enableCORS { userHealthHandler = corsHandler(userHealthHandler) } + userHealthHandler = compMW(userHealthHandler) userHealthHandler = recoverer(userHealthHandler, log) mux.Handle(pathSvcHealthV1, userHealthHandler) diff --git a/test/go.mod b/test/go.mod index eec602689..85819e181 100644 --- a/test/go.mod +++ b/test/go.mod @@ -107,6 +107,7 @@ require ( github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fvbommel/sortorder v1.0.2 // indirect github.com/getsentry/sentry-go v0.27.0 // indirect + github.com/go-chi/chi/v5 v5.1.0 // indirect github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect diff --git a/test/go.sum b/test/go.sum index 4070b0b11..2dccaf397 100644 --- a/test/go.sum +++ b/test/go.sum @@ -274,6 +274,8 @@ github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqG github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps= github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= +github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= +github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=