Skip to content

Commit 48d0307

Browse files
committed
refactor: refactor WithDecompressOnly function and update related tests
- Remove the boolean parameter from `WithDecompressOnly` function - Update `WithDecompressOnly` function to always set `DecompressOnly` to true - Update test cases to use the modified `WithDecompressOnly` function - Improve the documentation for `WithDecompressOnly` function Signed-off-by: appleboy <[email protected]>
1 parent 969f96e commit 48d0307

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

gzip_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func TestDecompressOnly(t *testing.T) {
261261
req.Header.Add("Content-Encoding", "gzip")
262262

263263
router := gin.New()
264-
router.Use(Gzip(NoCompression, WithDecompressOnly(true), WithDecompressFn(DefaultDecompressHandle)))
264+
router.Use(Gzip(NoCompression, WithDecompressOnly(), WithDecompressFn(DefaultDecompressHandle)))
265265
router.POST("/", func(c *gin.Context) {
266266
if v := c.Request.Header.Get("Content-Encoding"); v != "" {
267267
t.Errorf("unexpected `Content-Encoding`: %s header", v)
@@ -300,7 +300,7 @@ func TestGzipWithDecompressOnly(t *testing.T) {
300300
req.Header.Add("Accept-Encoding", "gzip")
301301

302302
r := gin.New()
303-
r.Use(Gzip(NoCompression, WithDecompressOnly(true), WithDecompressFn(DefaultDecompressHandle)))
303+
r.Use(Gzip(NoCompression, WithDecompressOnly(), WithDecompressFn(DefaultDecompressHandle)))
304304
r.POST("/", func(c *gin.Context) {
305305
assert.Equal(t, c.Request.Header.Get("Content-Encoding"), "")
306306
assert.Equal(t, c.Request.Header.Get("Content-Length"), "")

options.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ func WithDecompressFn(decompressFn func(c *gin.Context)) Option {
5252
}
5353
}
5454

55-
// disable compression, only decompress incoming request
56-
func WithDecompressOnly(decompressOnly bool) Option {
55+
// WithDecompressOnly is an option that configures the gzip middleware to only
56+
// decompress incoming requests without compressing the responses. When this
57+
// option is enabled, the middleware will set the DecompressOnly field of the
58+
// Options struct to true.
59+
func WithDecompressOnly() Option {
5760
return func(o *Options) {
58-
o.DecompressOnly = decompressOnly
61+
o.DecompressOnly = true
5962
}
6063
}
6164

0 commit comments

Comments
 (0)