Skip to content

Gzip middleware breaks Recovery middleware setting the status code #28

Open
@segevfiner

Description

@segevfiner

Build:

package main

import (
	"github.com/gin-contrib/gzip"
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	r.Use(gzip.Gzip(gzip.DefaultCompression))
	r.GET("/", func(c *gin.Context) {
		panic("panic")
	})
	r.Run()
}

Run:

$ curl -v --compressed http://localhost:8080/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
> Accept-Encoding: deflate, gzip
> 
< HTTP/1.1 200 OK
< Content-Encoding: gzip
< Vary: Accept-Encoding
< Date: Tue, 09 Jul 2019 10:02:44 GMT
< Content-Length: 23
< Content-Type: application/x-gzip
< 
* Connection #0 to host localhost left intact

You get the following warning from Gin:

[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 200 with 500

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions