Skip to content

Commit

Permalink
RHINENG-11685: gzip middleware with logging
Browse files Browse the repository at this point in the history
  • Loading branch information
psegedy committed Aug 26, 2024
1 parent 722bf91 commit 9884272
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"app/manager/middlewares"
"app/manager/routes"

"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)

Expand Down Expand Up @@ -48,7 +47,7 @@ func RunManager() {
app.Use(middlewares.MaxConnections(utils.CoreCfg.MaxGinConnections))
app.Use(middlewares.Ratelimit(utils.CoreCfg.Ratelimit))
app.Use(middlewares.RequestResponseLogger())
app.Use(gzip.Gzip(gzip.DefaultCompression))
app.Use(middlewares.Gzip())
endpointsConfig := getEndpointsConfig()
middlewares.SetSwagger(app, endpointsConfig)
app.Use(middlewares.WithTimeout(utils.CoreCfg.ResponseTimeout))
Expand Down
15 changes: 15 additions & 0 deletions manager/middlewares/gzip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package middlewares

import (
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)

func Gzip(options ...gzip.Option) gin.HandlerFunc {
gzipFn := gzip.Gzip(gzip.DefaultCompression, options...)
return func(c *gin.Context) {
tempLogDebugGinContextRequestHeader(c, "Gzip before")
defer tempLogDebugGinContextRequestHeader(c, "Gzip after")
gzipFn(c)
}
}

0 comments on commit 9884272

Please sign in to comment.