valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.94k stars 1.76k forks source link

Auto add 'Vary' header after compression #1585

Closed AutumnSun1996 closed 1 year ago

AutumnSun1996 commented 1 year ago

Add config SetAddVaryHeaderForCompression to enable 'Vary: Accept-Encoding' header when compression is used.

Added a config variable addVaryHeaderForCompress to control this feature, with setter SetAddVaryHeaderForCompression. To remain backward compatible, it's false by default. When enabled, 'Vary: Accept-Encoding' header will be added when compression is used.

fix #1583

erikdubbelboer commented 1 year ago

I have thought about it and I think it's better to remove SetAddVaryHeaderForCompression and always set the Vary header. We also always set Content-Encoding. Can you change that, then I can merge it. Thanks.

AutumnSun1996 commented 1 year ago

Hi, the code is updated, please review again. Thanks.

AutumnSun1996 commented 1 year ago

See what you mean. But this leads to another question: should we also handle the case where the user has added 'Vary: Accept-Encoding'?

erikdubbelboer commented 1 year ago

That's exactly what my example does.

AutumnSun1996 commented 1 year ago

oh sorry, I just missed the second check. going to update it now

AutumnSun1996 commented 1 year ago

I created such a function to check and update the Header, instead of copy-paste. any more comments?

// AddVaryBytes add value to the 'Vary' header if it's not included
func (h *ResponseHeader) AddVaryBytes(value []byte) 
erikdubbelboer commented 1 year ago

Thanks!