支持压缩请求体下的 Fast service_tier 注入#6
Open
Basic-XYZ wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Codex App 通过本地代理发送
/v1/responses请求时,请求体可能不是普通 JSON,而是带有压缩或分块传输。例如实际流量里会出现:Content-Encoding: zstdContent-Encoding: gzipTransfer-Encoding: chunked在这些情况下,proxy 如果直接按 UTF-8 JSON 解码请求体,会解析失败,导致
service_tier_policy=inject_missing无法正确兜底注入service_tier: "priority"。改动
service_tier前读取并合并 chunked 请求体。Content-Encoding: gzip请求体:解压、注入、再按 gzip 压回。Content-Encoding: zstd请求体:解压、注入、再按 zstd 压回。python-zstandard无法处理某些 frame 时,尝试使用本机zstd -dc。zstandard>=0.25.0,保证安装后具备 zstd 处理能力。行为说明
这个改动不会覆盖已有
service_tier:service_tier: "priority",proxy 会保留原值,记录为priority -> priority,Inject = no。service_tier,且策略是inject_missing,proxy 会补上service_tier: "priority",记录为<absent> -> priority,Inject = yes。验证
本地已执行:
python -m unittest discover -s tests -p 'test_proxy.py'结果:
同时执行了本地可执行入口校验:
python -m pip install -e . --quiet python -m codex_fast_proxy --help