Skip to content

Commit 13d2ae8

Browse files
authored
[#212]: fix: use gzip only
2 parents d604ac0 + cd3b3f2 commit 13d2ae8

File tree

8 files changed

+49
-25
lines changed

8 files changed

+49
-25
lines changed

.github/workflows/linux.yml

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: gzip
2-
32
on:
43
push:
54
branches:
@@ -9,86 +8,85 @@ on:
98
branches:
109
- master
1110
- stable
12-
1311
jobs:
1412
gzip_test:
1513
name: GZIP plugin (Go ${{ matrix.go }}, PHP ${{ matrix.php }}, OS ${{matrix.os}})
1614
runs-on: ${{ matrix.os }}
1715
timeout-minutes: 60
1816
strategy:
1917
matrix:
20-
php: [ "8.4" ]
21-
go: [ stable ]
22-
os: [ "ubuntu-latest" ]
18+
php: ["8.5"]
19+
go: [stable]
20+
os: ["ubuntu-latest"]
2321
steps:
2422
- name: Set up Go ${{ matrix.go }}
2523
uses: actions/setup-go@v6 # action page: <https://github.com/actions/setup-go>
2624
with:
2725
go-version: ${{ matrix.go }}
28-
2926
- name: Set up PHP ${{ matrix.php }}
3027
uses: shivammathur/setup-php@v2 # action page: <https://github.com/shivammathur/setup-php>
3128
with:
3229
php-version: ${{ matrix.php }}
3330
extensions: sockets
34-
3531
- name: Check out code
3632
uses: actions/checkout@v6
37-
3833
- name: Get Composer Cache Directory
3934
id: composer-cache
4035
run: |
4136
cd tests/php_test_files
4237
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
43-
4438
- name: Init Composer Cache # Docs: <https://git.io/JfAKn#php---composer>
4539
uses: actions/cache@v5
4640
with:
4741
path: ${{ steps.composer-cache.outputs.dir }}
4842
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.json') }}
4943
restore-keys: ${{ runner.os }}-composer-
50-
5144
- name: Install Composer dependencies
5245
run: cd tests/php_test_files && composer update --prefer-dist --no-progress --ansi
53-
5446
- name: Init Go modules Cache # Docs: <https://git.io/JfAKn#go---modules>
5547
uses: actions/cache@v5
5648
with:
5749
path: ~/go/pkg/mod
5850
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
5951
restore-keys: ${{ runner.os }}-go-
60-
6152
- name: Install Go dependencies
6253
run: go mod download
63-
6454
- name: Run golang tests with coverage
6555
run: |
6656
cd tests
6757
mkdir ./coverage-ci
6858
6959
go test -timeout 20m -v -race -cover -tags=debug -failfast -coverpkg=$(cat pkgs.txt) -coverprofile=./coverage-ci/gzip.out -covermode=atomic plugin_test.go
70-
7160
- name: Archive code coverage results
7261
uses: actions/upload-artifact@v6
7362
with:
7463
name: coverage
75-
path: ./tests/coverage-ci/gzip.out
76-
64+
path: ./tests/coverage-ci
7765
codecov:
7866
name: Upload codecov
7967
runs-on: ubuntu-latest
8068
needs:
8169
- gzip_test
82-
8370
timeout-minutes: 60
8471
steps:
72+
- name: Check out code
73+
uses: actions/checkout@v6
8574
- name: Download code coverage results
8675
uses: actions/download-artifact@v7
76+
with:
77+
name: coverage
78+
path: coverage
8779
- run: |
8880
echo 'mode: atomic' > summary.txt
89-
tail -q -n +2 *.out >> summary.txt
90-
sed -i '2,${/roadrunner/!d}' summary.txt
91-
81+
tail -q -n +2 coverage/*.out >> summary.txt
82+
awk '
83+
NR == 1 { print; next }
84+
/^github\.com\/roadrunner-server\/gzip\/v5\// {
85+
sub(/^github\.com\/roadrunner-server\/gzip\/v5\//, "", $0)
86+
print
87+
}
88+
' summary.txt > summary.filtered.txt
89+
mv summary.filtered.txt summary.txt
9290
- name: upload to codecov
9391
uses: codecov/codecov-action@v5 # Docs: <https://github.com/codecov/codecov-action>
9492
with:

.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)