Skip to content

Add q-factor parsing feature - #13

Open
timothy-jeong wants to merge 4 commits into
tuffnatty:masterfrom
timothy-jeong:add-qfactor-parsing-feature
Open

Add q-factor parsing feature#13
timothy-jeong wants to merge 4 commits into
tuffnatty:masterfrom
timothy-jeong:add-qfactor-parsing-feature

Conversation

@timothy-jeong

Copy link
Copy Markdown
Contributor

This PR introduces optional support for q-factor (quality value) negotiation for the Accept-Encoding header, aligning the middleware's behavior more closely with RFC 9110 (Section 12.5.3).

Key Changes

  • New Flag: Introduces a respect_q_factors: bool = False argument to the ZstdMiddleware constructor.
  • Backward Compatibility: The default behavior (False) is unchanged, ensuring zero performance impact or breaking changes for existing users.
  • Opt-In Logic: When respect_q_factors=True, the middleware uses a new header-parsing utility to select the best encoding (zstd, gzip, or identity) based on the client's q values.
  • Performance: The new get_preferred_encoding function is cached with @lru_cache(maxsize=128) to mitigate any performance overhead from parsing the same header strings on subsequent requests.

Resolve: #12

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.

Feature Proposal Add optional support for q-factor parsing in Accept-Encoding header

1 participant