Skip to content

Commit 40a16bf

Browse files
authored
feat(chore): Prometheus metrics with latest nutsdb (#414)
* feat(chore): Prometheus metrics with latest nutsdb * fix(ci): bump plugins * fix(chore): race condition in the middleware and writer * fix(ci): tests * feat(prepare-release): bump to v1.6.44
1 parent 4bb1371 commit 40a16bf

File tree

556 files changed

+5065
-11139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

556 files changed

+5065
-11139
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ build-caddy: ## Build caddy binary
6262
cd plugins/caddy && \
6363
go mod tidy && \
6464
go mod download && \
65-
xcaddy build --with github.com/darkweak/souin/plugins/caddy=./ --with github.com/darkweak/souin=../..
65+
XCADDY_RACE_DETECTOR=1 XCADDY_DEBUG=1 xcaddy build --with github.com/darkweak/souin/plugins/caddy=./ --with github.com/darkweak/souin=../..
6666

6767
build-dev: env-dev ## Build containers with dev env vars
6868
$(DC_BUILD) souin

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ experimental:
970970
plugins:
971971
souin:
972972
moduleName: github.com/darkweak/souin
973-
version: v1.6.43
973+
version: v1.6.44
974974
```
975975
After that you can declare either the whole configuration at once in the middleware block or by service. See the examples below.
976976
```yaml

go.mod

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ require (
99
github.com/fsnotify/fsnotify v1.6.0
1010
github.com/google/uuid v1.3.0
1111
github.com/imdario/mergo v0.3.13
12-
github.com/nutsdb/nutsdb v0.14.0
12+
github.com/nutsdb/nutsdb v0.14.2
1313
github.com/pquerna/cachecontrol v0.2.0
1414
github.com/prometheus/client_golang v1.16.0
1515
github.com/prometheus/client_model v0.4.0
1616
github.com/redis/go-redis/v9 v9.1.0
1717
go.etcd.io/etcd/client/v3 v3.5.9
1818
go.uber.org/zap v1.26.0
19-
golang.org/x/sync v0.2.0
19+
golang.org/x/exp v0.0.0-20231127185646-65229373498e
20+
golang.org/x/sync v0.5.0
2021
gopkg.in/yaml.v3 v3.0.1
2122
)
2223

@@ -29,7 +30,6 @@ require (
2930
github.com/cespare/xxhash v1.1.0 // indirect
3031
github.com/cespare/xxhash/v2 v2.2.0 // indirect
3132
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
32-
github.com/emirpasic/gods v1.18.1 // indirect
3333
github.com/go-redis/redis/v8 v8.11.5 // indirect
3434
github.com/gofrs/flock v0.8.1 // indirect
3535
github.com/gogo/protobuf v1.3.2 // indirect
@@ -56,10 +56,10 @@ require (
5656
go.etcd.io/etcd/client/pkg/v3 v3.5.9 // indirect
5757
go.opencensus.io v0.22.5 // indirect
5858
go.uber.org/multierr v1.10.0 // indirect
59-
golang.org/x/mod v0.9.0 // indirect
60-
golang.org/x/net v0.17.0 // indirect
61-
golang.org/x/sys v0.13.0 // indirect
62-
golang.org/x/text v0.13.0 // indirect
59+
golang.org/x/mod v0.14.0 // indirect
60+
golang.org/x/net v0.19.0 // indirect
61+
golang.org/x/sys v0.15.0 // indirect
62+
golang.org/x/text v0.14.0 // indirect
6363
google.golang.org/protobuf v1.30.0 // indirect
6464
gopkg.in/yaml.v2 v2.4.0 // indirect
6565
)
@@ -83,7 +83,7 @@ require (
8383
github.com/prometheus/common v0.42.0 // indirect
8484
github.com/prometheus/procfs v0.10.1 // indirect
8585
github.com/tidwall/btree v1.6.0 // indirect
86-
golang.org/x/tools v0.6.0 // indirect
86+
golang.org/x/tools v0.16.0 // indirect
8787
google.golang.org/genproto v0.0.0-20230227214838-9b19f0bdc514 // indirect
8888
google.golang.org/grpc v1.53.0
8989
)

go.sum

+16-16
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cu
7171
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
7272
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
7373
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
74-
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
75-
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
7674
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
7775
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
7876
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
@@ -198,8 +196,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
198196
github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM=
199197
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
200198
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
201-
github.com/nutsdb/nutsdb v0.14.0 h1:W/ghJ/7hpQt88sgkqXViL3JgzGKWfnLqztj0xeGUg5o=
202-
github.com/nutsdb/nutsdb v0.14.0/go.mod h1:6inOji9rFBporXeHDjJny4g50RpQbkjSK5jI1hht0j8=
199+
github.com/nutsdb/nutsdb v0.14.2 h1:A5MnpgvgZr+L+xMuZ+Wy+FTIJkzck7xKGxpOVUgIOqQ=
200+
github.com/nutsdb/nutsdb v0.14.2/go.mod h1:6inOji9rFBporXeHDjJny4g50RpQbkjSK5jI1hht0j8=
203201
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
204202
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
205203
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
@@ -317,6 +315,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
317315
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
318316
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
319317
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
318+
golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No=
319+
golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
320320
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
321321
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
322322
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
@@ -325,8 +325,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
325325
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
326326
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
327327
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
328-
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
329-
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
328+
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
329+
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
330330
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
331331
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
332332
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -346,8 +346,8 @@ golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT
346346
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
347347
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
348348
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
349-
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
350-
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
349+
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
350+
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
351351
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
352352
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
353353
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -359,8 +359,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
359359
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
360360
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
361361
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
362-
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
363-
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
362+
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
363+
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
364364
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
365365
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
366366
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -395,8 +395,8 @@ golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBc
395395
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
396396
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
397397
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
398-
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
399-
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
398+
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
399+
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
400400
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
401401
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
402402
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
@@ -406,8 +406,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
406406
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
407407
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
408408
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
409-
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
410-
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
409+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
410+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
411411
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
412412
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
413413
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
@@ -420,8 +420,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
420420
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
421421
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
422422
golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
423-
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
424-
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
423+
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM=
424+
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
425425
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
426426
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
427427
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

pkg/middleware/middleware.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,12 @@ func (s *SouinBaseHandler) Upstream(
316316
customWriter.Header().Set("Cache-Control", s.DefaultMatchedUrl.DefaultCacheControl)
317317
}
318318

319-
select {
320-
case <-rq.Context().Done():
321-
return nil, baseCtx.Canceled
322-
default:
323-
err := s.Store(customWriter, rq, requestCc, cachedKey)
324-
325-
return singleflightValue{
326-
body: customWriter.Buf.Bytes(),
327-
headers: customWriter.Headers,
328-
code: customWriter.statusCode,
329-
}, err
330-
}
319+
err := s.Store(customWriter, rq, requestCc, cachedKey)
320+
return singleflightValue{
321+
body: customWriter.Buf.Bytes(),
322+
headers: customWriter.Headers.Clone(),
323+
code: customWriter.statusCode,
324+
}, err
331325
})
332326

333327
if err != nil {
@@ -419,6 +413,10 @@ func (s *SouinBaseHandler) HandleInternally(r *http.Request) (bool, http.Handler
419413
type handlerFunc = func(http.ResponseWriter, *http.Request) error
420414

421415
func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, next handlerFunc) error {
416+
start := time.Now()
417+
defer func(s time.Time) {
418+
prometheus.Add(prometheus.AvgResponseTime, float64(time.Since(s).Milliseconds()))
419+
}(start)
422420
s.Configuration.GetLogger().Sugar().Debugf("Incomming request %+v", rq)
423421
if b, handler := s.HandleInternally(rq); b {
424422
handler(rw, rq)
@@ -512,6 +510,7 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n
512510
return err
513511
}
514512
if resCc, _ := cacheobject.ParseResponseCacheControl(response.Header.Get("Cache-Control")); resCc.NoCachePresent {
513+
prometheus.Increment(prometheus.NoCachedResponseCounter)
515514
err := s.Revalidate(validator, next, customWriter, rq, requestCc, cachedKey)
516515
_, _ = customWriter.Send()
517516

@@ -524,6 +523,7 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n
524523
s.Configuration.GetLogger().Sugar().Debugf("Serve from cache %+v", rq)
525524
_, _ = io.Copy(customWriter.Buf, response.Body)
526525
_, err := customWriter.Send()
526+
prometheus.Increment(prometheus.CachedResponseCounter)
527527

528528
return err
529529
}
@@ -614,6 +614,8 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n
614614
}
615615
}
616616
}
617+
} else {
618+
prometheus.Increment(prometheus.NoCachedResponseCounter)
617619
}
618620

619621
errorCacheCh := make(chan error)

pkg/middleware/writer.go

+6-11
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package middleware
33
import (
44
"bytes"
55
"net/http"
6-
"strings"
76
"sync"
87

98
"github.com/darkweak/go-esi/esi"
109
"github.com/darkweak/souin/pkg/rfc"
10+
"golang.org/x/exp/maps"
1111
)
1212

1313
type SouinWriterInterface interface {
@@ -73,27 +73,22 @@ func (r *CustomWriter) Write(b []byte) (int, error) {
7373

7474
// Send delays the response to handle Cache-Status
7575
func (r *CustomWriter) Send() (int, error) {
76-
r.Headers.Del(rfc.StoredTTLHeader)
7776
contentLength := r.Headers.Get(rfc.StoredLengthHeader)
7877
if contentLength != "" {
79-
r.Headers.Del("Content-Length")
8078
r.Header().Set("Content-Length", contentLength)
8179
}
82-
r.Headers.Del(rfc.StoredLengthHeader)
8380
defer r.Buf.Reset()
8481
b := esi.Parse(r.Buf.Bytes(), r.Req)
85-
for h, v := range r.Headers {
86-
if len(v) > 0 {
87-
r.Rw.Header().Set(h, strings.Join(v, ", "))
88-
}
89-
}
82+
maps.Copy(r.Rw.Header(), r.Headers)
83+
r.Header().Del(rfc.StoredLengthHeader)
84+
r.Header().Del(rfc.StoredTTLHeader)
9085

91-
r.mutex.Lock()
9286
if !r.headersSent {
87+
9388
// r.Rw.Header().Set("Content-Length", fmt.Sprintf("%d", len(b)))
9489
r.Rw.WriteHeader(r.statusCode)
9590
r.headersSent = true
9691
}
97-
r.mutex.Unlock()
92+
9893
return r.Rw.Write(b)
9994
}

pkg/storage/nutsProvider.go

-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ func sanitizeProperties(m map[string]interface{}) map[string]interface{} {
5151
switch v {
5252
case 1:
5353
m["EntryIdxMode"] = nutsdb.HintKeyAndRAMIdxMode
54-
case 2:
55-
m["EntryIdxMode"] = nutsdb.HintBPTSparseIdxMode
5654
}
5755
}
5856

plugins/beego/go.mod

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.20
44

55
require (
66
github.com/beego/beego/v2 v2.1.1
7-
github.com/darkweak/souin v1.6.43
7+
github.com/darkweak/souin v1.6.44
88
)
99

1010
require (
@@ -26,7 +26,6 @@ require (
2626
github.com/dgraph-io/ristretto v0.1.1 // indirect
2727
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
2828
github.com/dustin/go-humanize v1.0.1 // indirect
29-
github.com/emirpasic/gods v1.18.1 // indirect
3029
github.com/go-redis/redis/v8 v8.11.5 // indirect
3130
github.com/gofrs/flock v0.8.1 // indirect
3231
github.com/gogo/protobuf v1.3.2 // indirect
@@ -51,7 +50,7 @@ require (
5150
github.com/miekg/dns v1.1.55 // indirect
5251
github.com/mitchellh/mapstructure v1.5.0 // indirect
5352
github.com/mschoch/smat v0.2.0 // indirect
54-
github.com/nutsdb/nutsdb v0.14.0 // indirect
53+
github.com/nutsdb/nutsdb v0.14.2 // indirect
5554
github.com/onsi/gomega v1.24.1 // indirect
5655
github.com/pkg/errors v0.9.1 // indirect
5756
github.com/pquerna/cachecontrol v0.2.0 // indirect
@@ -75,13 +74,14 @@ require (
7574
go.opencensus.io v0.24.0 // indirect
7675
go.uber.org/multierr v1.11.0 // indirect
7776
go.uber.org/zap v1.26.0 // indirect
78-
golang.org/x/crypto v0.14.0 // indirect
79-
golang.org/x/mod v0.12.0 // indirect
80-
golang.org/x/net v0.17.0 // indirect
81-
golang.org/x/sync v0.3.0 // indirect
82-
golang.org/x/sys v0.13.0 // indirect
83-
golang.org/x/text v0.13.0 // indirect
84-
golang.org/x/tools v0.12.0 // indirect
77+
golang.org/x/crypto v0.16.0 // indirect
78+
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
79+
golang.org/x/mod v0.14.0 // indirect
80+
golang.org/x/net v0.19.0 // indirect
81+
golang.org/x/sync v0.5.0 // indirect
82+
golang.org/x/sys v0.15.0 // indirect
83+
golang.org/x/text v0.14.0 // indirect
84+
golang.org/x/tools v0.16.0 // indirect
8585
google.golang.org/genproto v0.0.0-20230815205213-6bfd019c3878 // indirect
8686
google.golang.org/genproto/googleapis/api v0.0.0-20230815205213-6bfd019c3878 // indirect
8787
google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 // indirect
@@ -91,4 +91,4 @@ require (
9191
gopkg.in/yaml.v3 v3.0.1 // indirect
9292
)
9393

94-
replace github.com/darkweak/souin v1.6.43 => ../..
94+
replace github.com/darkweak/souin v1.6.44 => ../..

0 commit comments

Comments
 (0)