Add support for Zstandard to the Compression middleware
This commit is contained in:
parent
3f48e6f8ef
commit
b795f128d7
7 changed files with 576 additions and 213 deletions
|
@ -18,6 +18,11 @@ func Test_getCompressionType(t *testing.T) {
|
|||
values: []string{"gzip, br"},
|
||||
expected: brotliName,
|
||||
},
|
||||
{
|
||||
desc: "zstd > br > gzip (no weight)",
|
||||
values: []string{"zstd, gzip, br"},
|
||||
expected: zstdName,
|
||||
},
|
||||
{
|
||||
desc: "known compression type (no weight)",
|
||||
values: []string{"compress, gzip"},
|
||||
|
@ -49,6 +54,11 @@ func Test_getCompressionType(t *testing.T) {
|
|||
values: []string{"compress;q=1.0, gzip;q=0.5"},
|
||||
expected: gzipName,
|
||||
},
|
||||
{
|
||||
desc: "fallback on non-zero compression type",
|
||||
values: []string{"compress;q=1.0, gzip, identity;q=0"},
|
||||
expected: gzipName,
|
||||
},
|
||||
{
|
||||
desc: "not acceptable (identity)",
|
||||
values: []string{"compress;q=1.0, identity;q=0"},
|
||||
|
@ -86,9 +96,10 @@ func Test_parseAcceptEncoding(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
desc: "weight",
|
||||
values: []string{"br;q=1.0, gzip;q=0.8, *;q=0.1"},
|
||||
values: []string{"br;q=1.0, zstd;q=0.9, gzip;q=0.8, *;q=0.1"},
|
||||
expected: []Encoding{
|
||||
{Type: brotliName, Weight: ptr[float64](1)},
|
||||
{Type: zstdName, Weight: ptr(0.9)},
|
||||
{Type: gzipName, Weight: ptr(0.8)},
|
||||
{Type: wildcardName, Weight: ptr(0.1)},
|
||||
},
|
||||
|
@ -96,9 +107,10 @@ func Test_parseAcceptEncoding(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "mixed",
|
||||
values: []string{"gzip, br;q=1.0, *;q=0"},
|
||||
values: []string{"zstd,gzip, br;q=1.0, *;q=0"},
|
||||
expected: []Encoding{
|
||||
{Type: brotliName, Weight: ptr[float64](1)},
|
||||
{Type: zstdName},
|
||||
{Type: gzipName},
|
||||
{Type: wildcardName, Weight: ptr[float64](0)},
|
||||
},
|
||||
|
@ -106,8 +118,9 @@ func Test_parseAcceptEncoding(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "no weight",
|
||||
values: []string{"gzip, br, *"},
|
||||
values: []string{"zstd, gzip, br, *"},
|
||||
expected: []Encoding{
|
||||
{Type: zstdName},
|
||||
{Type: gzipName},
|
||||
{Type: brotliName},
|
||||
{Type: wildcardName},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue