Skip to content
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

conflict with gin cache #5

Open
julaee opened this issue Jan 31, 2017 · 2 comments
Open

conflict with gin cache #5

julaee opened this issue Jan 31, 2017 · 2 comments

Comments

@julaee
Copy link

julaee commented Jan 31, 2017

I have a problem when using gin cache.
The first request serves correctly, but second request that was cached in gin cache middleware returns response with length 0

@easonlin404
Copy link

@acegishniz can you post your example code?

@julaee
Copy link
Author

julaee commented Jul 30, 2017

@easonlin404
@appleboy
i did fixed it.
i did comment this line in gzip.go file:
//c.Header("Content-Length", "0")
and in cache middleware ( https://github.com/gin-contrib/cache ) in file cache.go
in this function:

func CachePage(store persistence.CacheStore, expire time.Duration, handle gin.HandlerFunc) gin.HandlerFunc {

	return func(c *gin.Context) {
		var cache responseCache
		url := c.Request.URL
		key := urlEscape(PageCachePrefix, url.RequestURI())
		log.Println(key)
		if err := store.Get(key, &cache); err != nil {
			log.Println(err.Error())
			// replace writer
			writer := newCachedWriter(store, expire, c.Writer, key)
			c.Writer = writer
			handle(c)
		} else {
			log.Println(cache.status)
			c.Writer.WriteHeader(cache.status)
			for k, vals := range cache.header {
				for _, v := range vals {
					c.Writer.Header().Add(k, v)
				}
			}
			c.Writer.Write(cache.data)
		}
	}
}

change this slice code:


			for k, vals := range cache.header {
				for _, v := range vals {
					c.Writer.Header().Add(k, v)
				}
			}

to this:

			for k, vals := range cache.header {
				for _, v := range vals {
					if (k=="Content-Encoding" && v=="gzip") {
						continue
					}
					c.Writer.Header().Add(k, v)
				}
			}

fntlnz added a commit to seqeralabs/staticreg that referenced this issue Jul 24, 2024
it has a conflict with the gin cache middleware
see: gin-contrib/gzip#5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants