gin-cache
gin-cache copied to clipboard
Exception using both gin-cache and nanmu42/gzip middleware
package main
import (
"strings"
"time"
cache "github.com/chenyahui/gin-cache"
"github.com/chenyahui/gin-cache/persist"
"github.com/gin-gonic/gin"
"github.com/nanmu42/gzip"
)
func main() {
app := gin.New()
app.Use(gzip.DefaultHandler().Gin)
memoryStore := persist.NewMemoryStore(1 * time.Minute)
body := strings.Repeat("hello world", 100)
app.GET("/hello",
cache.CacheByRequestURI(memoryStore, 2*time.Second),
func(c *gin.Context) {
c.String(200, body)
},
)
if err := app.Run(":8080"); err != nil {
panic(err)
}
}
Run multiple requests:
curl --compressed 127.0.0.1:8080/hello -v
curl --compressed 127.0.0.1:8080/hello -v
curl --compressed 127.0.0.1:8080/hello -v
Should get the error message:
# curl --compressed 127.0.0.1:8080/hello -v
* Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /hello HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.68.0
> Accept: */*
> Accept-Encoding: deflate, gzip, br
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Encoding: gzip
< Content-Type: text/plain; charset=utf-8
< Vary: Accept-Encoding
< Date: Sun, 04 Sep 2022 03:18:33 GMT
< Content-Length: 1100
<
* Error while processing content unencoding: incorrect header check
* Closing connection 0
curl: (61) Error while processing content unencoding: incorrect header check
I can't reproduce this issue in my environment, are you using the latest version of gin-cache?