Skip to content

Commit 7315deb

Browse files
authored
feat: enable gzip support for grpc gateway (#225)
- if a header with "Accept-Encoding: gzip" is set, the response will be gziped Signed-off-by: Kush Sharma <thekushsharma@gmail.com>
1 parent dea4e8a commit 7315deb

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/golang-module/carbon/v2 v2.1.8
1818
github.com/google/go-cmp v0.5.8
1919
github.com/google/uuid v1.3.0
20+
github.com/gorilla/handlers v1.4.2
2021
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
2122
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3
2223
github.com/jackc/pgconn v1.8.0

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORR
708708
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
709709
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
710710
github.com/gorilla/handlers v0.0.0-20150720190736-60c7bfde3e33/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
711+
github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg=
711712
github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
712713
github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
713714
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=

internal/server/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"time"
1111

12+
"github.com/gorilla/handlers"
1213
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
1314
grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
1415
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
@@ -26,6 +27,7 @@ import (
2627
"github.com/raystack/salt/mux"
2728
"google.golang.org/grpc"
2829
"google.golang.org/grpc/credentials/insecure"
30+
_ "google.golang.org/grpc/encoding/gzip" // Install the gzip compressor
2931
"google.golang.org/grpc/health/grpc_health_v1"
3032
"google.golang.org/grpc/reflection"
3133
"google.golang.org/protobuf/encoding/protojson"
@@ -161,7 +163,7 @@ func Serve(
161163
if err := mux.Serve(
162164
ctx,
163165
mux.WithHTTPTarget(config.addr(), &http.Server{
164-
Handler: gwmux,
166+
Handler: handlers.CompressHandler(gwmux),
165167
ReadTimeout: 60 * time.Second,
166168
WriteTimeout: 60 * time.Second,
167169
IdleTimeout: 120 * time.Second,

0 commit comments

Comments
 (0)