-
Notifications
You must be signed in to change notification settings - Fork 1
fix: use gzip only #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use gzip only #212
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Package gzip provides the RoadRunner Gzip plugin. | ||
| package gzip |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| go 1.25 | ||||||
| go 1.26 | ||||||
|
||||||
| go 1.26 | |
| go 1.22 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package gzip | |
|
|
||
| import ( | ||
| "net/http" | ||
| "sync" | ||
|
|
||
| "github.com/klauspost/compress/gzhttp" | ||
| rrcontext "github.com/roadrunner-server/context" | ||
|
|
@@ -20,14 +21,30 @@ type Plugin struct { | |
| prop propagation.TextMapPropagator | ||
| } | ||
|
|
||
| var onceDefault sync.Once //nolint:gochecknoglobals | ||
| var defaultWrapper func(http.Handler) http.HandlerFunc //nolint:gochecknoglobals | ||
|
|
||
| // GzipHandler allows to easily wrap an http handler with default settings. | ||
| func gzipHandler(h http.Handler) http.HandlerFunc { | ||
| onceDefault.Do(func() { | ||
| var err error | ||
| defaultWrapper, err = gzhttp.NewWrapper(gzhttp.PreferZstd(false), gzhttp.EnableZstd(false), gzhttp.EnableGzip(true)) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| }) | ||
|
Comment on lines
+24
to
+35
|
||
|
|
||
| return defaultWrapper(h) | ||
| } | ||
|
|
||
| func (g *Plugin) Init() error { | ||
| g.prop = propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}, jprop.Jaeger{}) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (g *Plugin) Middleware(next http.Handler) http.Handler { | ||
| return gzhttp.GzipHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| return gzipHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if val, ok := r.Context().Value(rrcontext.OtelTracerNameKey).(string); ok { | ||
| tp := trace.SpanFromContext(r.Context()).TracerProvider() | ||
| ctx, span := tp.Tracer(val, trace.WithSchemaURL(semconv.SchemaURL), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Package gzip contains integration tests for the RoadRunner Gzip plugin. | ||
| package gzip |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Package mocklogger provides test logger mocks and observed log utilities. | ||
| package mocklogger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enabling Revive’s default rules can introduce new lint failures and effectively changes the repo’s lint policy. Since the PR description is about gzip-only compression, consider calling this out explicitly (or splitting lint-policy changes into a separate PR) to keep scope clear.