-
Notifications
You must be signed in to change notification settings - Fork 93
Mishandling 404? #98
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
Comments
It looks like this was introduced between v1.0.1 and v1.1.0 |
Same stuff |
Hello, same here |
The bug is that |
I'm working on a test case: func Test404WithGzip(t *testing.T) {
req, _ := http.NewRequestWithContext(context.Background(), "GET", "/bar", nil)
req.Header.Add(headerAcceptEncoding, "gzip")
router := gin.New()
router.Use(Gzip(DefaultCompression, WithDecompressFn(DefaultDecompressHandle)))
router.GET("/foo", func(c *gin.Context) {
c.String(200, "ok")
})
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
assert.Equal(t, http.StatusNotFound, w.Code)
assert.Equal(t, "gzip", w.Header().Get(headerContentEncoding))
assert.Equal(t, "Accept-Encoding", w.Header().Get(headerVary))
assert.Equal(t, "23", w.Header().Get("Content-Length"))
gr, err := gzip.NewReader(w.Body)
assert.NoError(t, err)
defer gr.Close()
body, _ := io.ReadAll(gr)
assert.Equal(t, "404 page not found", string(body))
} I found that the setting of the 200 seems to be coming from |
Same |
I try to add func (g *gzipWriter) Write(data []byte) (int, error) {
g.Header().Del("Content-Length")
+ g.WriteHeaderNow()
return g.writer.Write(data)
} compare with default writer func (w *responseWriter) Write(data []byte) (n int, err error) {
w.WriteHeaderNow()
n, err = w.ResponseWriter.Write(data)
w.size += n
return
} |
Have added a test here to the existing suite which demonstrates the issue
|
…empty responses
Uh oh!
There was an error while loading. Please reload this page.
I have a simple program
when i do
curl localhost:8080 -H 'accept-encoding: gzip' -v
I get a 200 response and when I docurl localhost:8080 -v
I get a 404 response.I am not sure what I am doing wrong but it seems like the gzip buffer is being closed before gin writes its 404 which somehow messes up the eventual response object.
hitting the
localhost:8080/x
endpoint works fineThe text was updated successfully, but these errors were encountered: