Skip to content

Commit 795c92a

Browse files
committed
fix: use gzip only
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
1 parent d604ac0 commit 795c92a

File tree

7 files changed

+31
-5
lines changed

7 files changed

+31
-5
lines changed

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ linters:
5757
for-loops: true
5858
wsl:
5959
allow-assign-and-anything: true
60+
revive:
61+
enable-default-rules: true
62+
rules:
63+
- name: var-naming
64+
disabled: true
6065
exclusions:
6166
generated: lax
6267
presets:

doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package gzip provides the RoadRunner Gzip plugin.
2+
package gzip

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/roadrunner-server/gzip/v5
22

3-
go 1.25
4-
5-
toolchain go1.25.7
3+
go 1.26
64

75
require (
86
github.com/klauspost/compress v1.18.4

go.work

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
go 1.25
1+
go 1.26
22

33
use (
44
.

plugin.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gzip
22

33
import (
44
"net/http"
5+
"sync"
56

67
"github.com/klauspost/compress/gzhttp"
78
rrcontext "github.com/roadrunner-server/context"
@@ -20,14 +21,30 @@ type Plugin struct {
2021
prop propagation.TextMapPropagator
2122
}
2223

24+
var onceDefault sync.Once //nolint:gochecknoglobals
25+
var defaultWrapper func(http.Handler) http.HandlerFunc //nolint:gochecknoglobals
26+
27+
// GzipHandler allows to easily wrap an http handler with default settings.
28+
func gzipHandler(h http.Handler) http.HandlerFunc {
29+
onceDefault.Do(func() {
30+
var err error
31+
defaultWrapper, err = gzhttp.NewWrapper(gzhttp.PreferZstd(false), gzhttp.EnableZstd(false), gzhttp.EnableGzip(true))
32+
if err != nil {
33+
panic(err)
34+
}
35+
})
36+
37+
return defaultWrapper(h)
38+
}
39+
2340
func (g *Plugin) Init() error {
2441
g.prop = propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}, jprop.Jaeger{})
2542

2643
return nil
2744
}
2845

2946
func (g *Plugin) Middleware(next http.Handler) http.Handler {
30-
return gzhttp.GzipHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
47+
return gzipHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
3148
if val, ok := r.Context().Value(rrcontext.OtelTracerNameKey).(string); ok {
3249
tp := trace.SpanFromContext(r.Context()).TracerProvider()
3350
ctx, span := tp.Tracer(val, trace.WithSchemaURL(semconv.SchemaURL),

tests/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package gzip contains integration tests for the RoadRunner Gzip plugin.
2+
package gzip

tests/mock/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package mocklogger provides test logger mocks and observed log utilities.
2+
package mocklogger

0 commit comments

Comments
 (0)