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

Vary headers gets overwritten instead of it being added. #49

Open
TerraSkye opened this issue Mar 30, 2022 · 1 comment
Open

Vary headers gets overwritten instead of it being added. #49

TerraSkye opened this issue Mar 30, 2022 · 1 comment

Comments

@TerraSkye
Copy link

package main

import (
	"fmt"
	"github.com/gin-contrib/gzip"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
	"time"
)

func main() {

	r := gin.Default()
	r.Use(func(c *gin.Context) {
		c.Writer.Header().Add("Vary", "Origin")
	}, gzip.Gzip(gzip.DefaultCompression))
	r.GET("/ping", func(c *gin.Context) {
		c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
	})

	// Listen and Server in 0.0.0.0:8080
	if err := r.Run(":9000"); err != nil {
		log.Fatal(err)
	}

}

when running the folowing setup. i expect the Vary headers to contain
Accept-Encoding and Origin

but due to the behavior of the gzip middleware, the Vary header is being overwritten

shouldnt gzip add the the Accept-Encoding instead over overwriting it ?

@runephilosof-karnovgroup

Also, Vary should also include Accept-Encoding when the request did include Accept-Encoding

runephilosof@fedora:~/code/go-test$ curl -i localhost:9000/ping
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Vary: Origin
Date: Wed, 20 Sep 2023 12:09:17 GMT
Content-Length: 15

pong 1695211757runephilosof@fedora:~/code/go-test$ 
runephilosof@fedora:~/code/go-test$ curl -i -H 'Accept-Encoding: gzip' localhost:9000/ping
HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Type: text/plain; charset=utf-8
Vary: Accept-Encoding
Date: Wed, 20 Sep 2023 12:10:09 GMT
Content-Length: 39

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