mirror of
https://github.com/alibaba/higress.git
synced 2026-04-21 12:07:26 +08:00
fix disableOnEtagHeader can't work in configmap gzip envoyfiler (#731)
This commit is contained in:
@@ -15,7 +15,6 @@
|
|||||||
package configmap
|
package configmap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -130,12 +129,17 @@ func compareGzip(old *Gzip, new *Gzip) (Result, error) {
|
|||||||
|
|
||||||
func deepCopyGzip(gzip *Gzip) (*Gzip, error) {
|
func deepCopyGzip(gzip *Gzip) (*Gzip, error) {
|
||||||
newGzip := NewDefaultGzip()
|
newGzip := NewDefaultGzip()
|
||||||
bytes, err := json.Marshal(gzip)
|
newGzip.Enable = gzip.Enable
|
||||||
if err != nil {
|
newGzip.MinContentLength = gzip.MinContentLength
|
||||||
return nil, err
|
newGzip.ContentType = make([]string, 0, len(gzip.ContentType))
|
||||||
}
|
newGzip.ContentType = append(newGzip.ContentType, gzip.ContentType...)
|
||||||
err = json.Unmarshal(bytes, newGzip)
|
newGzip.DisableOnEtagHeader = gzip.DisableOnEtagHeader
|
||||||
return newGzip, err
|
newGzip.MemoryLevel = gzip.MemoryLevel
|
||||||
|
newGzip.WindowBits = gzip.WindowBits
|
||||||
|
newGzip.ChunkSize = gzip.ChunkSize
|
||||||
|
newGzip.CompressionLevel = gzip.CompressionLevel
|
||||||
|
newGzip.CompressionStrategy = gzip.CompressionStrategy
|
||||||
|
return newGzip, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDefaultGzip() *Gzip {
|
func NewDefaultGzip() *Gzip {
|
||||||
@@ -305,9 +309,9 @@ func (g *GzipController) constructGzipStruct(gzip *Gzip, namespace string) strin
|
|||||||
"response_direction_config": {
|
"response_direction_config": {
|
||||||
"common_config": {
|
"common_config": {
|
||||||
"min_content_length": %d,
|
"min_content_length": %d,
|
||||||
"content_type": [%s],
|
"content_type": [%s]
|
||||||
"disable_on_etag_header": %t
|
},
|
||||||
}
|
"disable_on_etag_header": %t
|
||||||
},
|
},
|
||||||
"request_direction_config": {
|
"request_direction_config": {
|
||||||
"common_config": {
|
"common_config": {
|
||||||
|
|||||||
@@ -277,27 +277,54 @@ func Test_deepCopyGzip(t *testing.T) {
|
|||||||
wantErr error
|
wantErr error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "deep copy",
|
name: "deep copy case 1",
|
||||||
gzip: &Gzip{
|
gzip: &Gzip{
|
||||||
Enable: false,
|
Enable: false,
|
||||||
MinContentLength: 1024,
|
MinContentLength: 102,
|
||||||
ContentType: []string{"text/html", "text/css", "text/plain", "text/xml", "application/json", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
ContentType: []string{"text/css", "text/plain", "text/xml", "application/json", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
||||||
DisableOnEtagHeader: true,
|
DisableOnEtagHeader: false,
|
||||||
MemoryLevel: 5,
|
MemoryLevel: 6,
|
||||||
WindowBits: 12,
|
WindowBits: 11,
|
||||||
ChunkSize: 4096,
|
ChunkSize: 4096,
|
||||||
CompressionLevel: "BEST_COMPRESSION",
|
CompressionLevel: "BEST_SPEED",
|
||||||
CompressionStrategy: "DEFAULT_STRATEGY",
|
CompressionStrategy: "DEFAULT_STRATEGY",
|
||||||
},
|
},
|
||||||
wantGzip: &Gzip{
|
wantGzip: &Gzip{
|
||||||
Enable: false,
|
Enable: false,
|
||||||
MinContentLength: 1024,
|
MinContentLength: 102,
|
||||||
ContentType: []string{"text/html", "text/css", "text/plain", "text/xml", "application/json", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
ContentType: []string{"text/css", "text/plain", "text/xml", "application/json", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
||||||
DisableOnEtagHeader: true,
|
DisableOnEtagHeader: false,
|
||||||
MemoryLevel: 5,
|
MemoryLevel: 6,
|
||||||
WindowBits: 12,
|
WindowBits: 11,
|
||||||
ChunkSize: 4096,
|
ChunkSize: 4096,
|
||||||
CompressionLevel: "BEST_COMPRESSION",
|
CompressionLevel: "BEST_SPEED",
|
||||||
|
CompressionStrategy: "DEFAULT_STRATEGY",
|
||||||
|
},
|
||||||
|
wantErr: nil,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "deep copy case 2",
|
||||||
|
gzip: &Gzip{
|
||||||
|
Enable: true,
|
||||||
|
MinContentLength: 102,
|
||||||
|
ContentType: []string{"text/css", "text/plain", "text/xml", "application/json", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
||||||
|
DisableOnEtagHeader: true,
|
||||||
|
MemoryLevel: 6,
|
||||||
|
WindowBits: 11,
|
||||||
|
ChunkSize: 4096,
|
||||||
|
CompressionLevel: "BEST_SPEED",
|
||||||
|
CompressionStrategy: "DEFAULT_STRATEGY",
|
||||||
|
},
|
||||||
|
wantGzip: &Gzip{
|
||||||
|
Enable: true,
|
||||||
|
MinContentLength: 102,
|
||||||
|
ContentType: []string{"text/css", "text/plain", "text/xml", "application/json", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
||||||
|
DisableOnEtagHeader: true,
|
||||||
|
MemoryLevel: 6,
|
||||||
|
WindowBits: 11,
|
||||||
|
ChunkSize: 4096,
|
||||||
|
CompressionLevel: "BEST_SPEED",
|
||||||
CompressionStrategy: "DEFAULT_STRATEGY",
|
CompressionStrategy: "DEFAULT_STRATEGY",
|
||||||
},
|
},
|
||||||
wantErr: nil,
|
wantErr: nil,
|
||||||
|
|||||||
Reference in New Issue
Block a user