Skip to content

fix(gzhttp): preserve qvalue when extra parameters follow in Accept-Encoding#1116

Merged
klauspost merged 1 commit intoklauspost:masterfrom
analytically:fix/q
Dec 2, 2025
Merged

fix(gzhttp): preserve qvalue when extra parameters follow in Accept-Encoding#1116
klauspost merged 1 commit intoklauspost:masterfrom
analytically:fix/q

Conversation

@analytically
Copy link
Contributor

@analytically analytically commented Dec 1, 2025

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.

Summary by CodeRabbit

  • Bug Fixes

    • HTTP compression encoding parsing now correctly processes quality parameters in Accept-Encoding headers with multiple specifications and extended parameters.
  • Tests

    • Added test cases for gzip encoding with quality values and additional parameters to ensure proper parsing behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

…ncoding

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>
@coderabbitai
Copy link

coderabbitai bot commented Dec 1, 2025

📝 Walkthrough

Walkthrough

The qvalue initialization in the parseCoding function was relocated from inside the parsing loop to before it, changing how encoding parameters are processed. Previously, qvalue was reset to the default for each part; now it retains the last explicitly parsed value across subsequent parts.

Changes

Cohort / File(s) Summary
qvalue parsing logic
gzhttp/compress.go
Moved qvalue initialization (qvalue = DefaultQValue) from inside loop to before loop; subsequent parts without explicit q= now retain previous qvalue instead of resetting to default.
Test coverage for q-value parsing
gzhttp/compress_test.go
Added two test cases: "gzip;q=0.5;level=6" and "gzip;q=0.3;level=6;x=y" to verify q-value parsing and parameter handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Focus on verifying that the behavioral change (qvalue persistence across parts) is intentional and doesn't break existing use cases
  • Confirm the new test cases adequately cover the modified parsing behavior, particularly edge cases with multiple parts and varying q-value specifications

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: preserving the qvalue parameter when extra parameters follow in Accept-Encoding headers, which directly addresses the bug documented in the PR objectives.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between daa180d and a7eb556.

📒 Files selected for processing (2)
  • gzhttp/compress.go (1 hunks)
  • gzhttp/compress_test.go (1 hunks)
🔇 Additional comments (2)
gzhttp/compress_test.go (1)

44-45: LGTM! Test cases validate the qvalue preservation fix.

These test cases correctly verify that the qvalue is preserved when additional parameters (like level=6 or x=y) follow the q= parameter. This directly validates the bug fix described in the PR.

gzhttp/compress.go (1)

884-884: Excellent fix! Moving qvalue initialization before the loop preserves the parsed value.

This change correctly addresses the bug where qvalue was being reset to DefaultQValue on every loop iteration. Now the qvalue is initialized once and only updated when an explicit q= parameter is encountered, allowing subsequent parameters like level=6 to be ignored without affecting the qvalue.

The fix is minimal, focused, and correctly implements HTTP Accept-Encoding header parsing semantics.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@klauspost klauspost merged commit 986a51e into klauspost:master Dec 2, 2025
22 checks passed
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

Successfully merging this pull request may close these issues.

2 participants