Skip to content

Commit 986a51e

Browse files
authored
fix(gzhttp): preserve qvalue when extra parameters follow in Accept-Encoding (#1116)
parseCoding() reset qvalue to DefaultQValue on every loop iteration, causing "gzip;q=0.5;level=6" to incorrectly return qvalue=1.0 instead of 0.5. Move qvalue initialization before the loop. Signed-off-by: Mathias Bogaert <mathias.bogaert@gmail.com>
1 parent fbe3b12 commit 986a51e

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

gzhttp/compress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,9 +881,9 @@ func parseCoding(s string) (coding string, qvalue float64, err error) {
881881
}
882882
return coding, DefaultQValue, err
883883
}
884+
qvalue = DefaultQValue
884885
for n, part := range strings.Split(s, ";") {
885886
part = strings.TrimSpace(part)
886-
qvalue = DefaultQValue
887887

888888
if n == 0 {
889889
coding = strings.ToLower(part)

gzhttp/compress_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ func TestParseEncodings(t *testing.T) {
4040
// More random stuff
4141
"AAA;q=1": {"aaa": 1.0},
4242
"BBB ; q = 2": {"bbb": 1.0},
43+
44+
"gzip;q=0.5;level=6": {"gzip": 0.5},
45+
"gzip;q=0.3;level=6;x=y": {"gzip": 0.3},
4346
}
4447

4548
for eg, exp := range examples {

0 commit comments

Comments
 (0)