Skip to content

Commit 3830b8f

Browse files
authored
fix http: invalid Content-Length of "-1" (#97)
1 parent 79e888f commit 3830b8f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

handler.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package gzip
22

33
import (
44
"compress/gzip"
5-
"fmt"
65
"io"
76
"net/http"
87
"path/filepath"
8+
"strconv"
99
"strings"
1010
"sync"
1111

@@ -92,8 +92,10 @@ func (g *gzipHandler) Handle(c *gin.Context) {
9292
// do not write gzip footer when nothing is written to the response body
9393
gz.Reset(io.Discard)
9494
}
95-
gz.Close()
96-
c.Header("Content-Length", fmt.Sprint(c.Writer.Size()))
95+
_ = gz.Close()
96+
if c.Writer.Size() > -1 {
97+
c.Header("Content-Length", strconv.Itoa(c.Writer.Size()))
98+
}
9799
}()
98100
c.Next()
99101
}

0 commit comments

Comments
 (0)