Skip to content

Commit

Permalink
feat: add logic to handle weak ETag headers (#100)
Browse files Browse the repository at this point in the history
- Add logic to handle weak ETag headers by prefixing them with "W/" if they are not already weak

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy authored Jan 27, 2025
1 parent 3bd96db commit c881664
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func (g *gzipHandler) Handle(c *gin.Context) {

c.Header(headerContentEncoding, "gzip")
c.Writer.Header().Add(headerVary, headerAcceptEncoding)
// check ETag Header
originalEtag := c.GetHeader("ETag")
if originalEtag != "" && !strings.HasPrefix(originalEtag, "W/") {
c.Header("ETag", "W/"+originalEtag)
}
c.Writer = &gzipWriter{c.Writer, gz}
defer func() {
if c.Writer.Size() < 0 {
Expand Down

0 comments on commit c881664

Please sign in to comment.