fix: resolve UTF-8 encoding issues in HTTP request bodies#158
Conversation
- Add charset=utf-8 to Content-Type and Accept headers - Serialize JSON with ensure_ascii=False for proper UTF-8 encoding - Fix body size calculation to prevent Content-Length mismatches - Apply changes to sync HTTP, async HTTP, WebSocket, and form data paths - Add comprehensive unit and integration tests This fix reduces request body size by 57.5% for non-ASCII content (e.g., 12.41MB → 5.27MB for websearch.json test data) and ensures compatibility with servers that enforce strict body size limits. Closes issue with large UTF-8 payloads exceeding server limits.
There was a problem hiding this comment.
Code Review
This pull request updates the SDK to support UTF-8 encoding for JSON payloads across HTTP, async HTTP, and WebSocket requests by using ensure_ascii=False and explicitly setting charset=utf-8 in headers. It also adds comprehensive integration and unit tests to verify these changes. The reviewer feedback highlights a critical backward compatibility issue where renaming the json parameter to json_body in the update and put methods of base_api.py will break existing callers using keyword arguments. The reviewer suggests keeping the parameter optional and resolving the legacy json key from kwargs to maintain compatibility.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
1f72af7 to
d47c4ec
Compare
… due to SDK dataclass return types
The 'json' parameter in UpdateMixin.update() and PutMixin.put() shadowed the 'json' module, causing AttributeError when calling json.dumps(). Use local 'import json as _json' alias to avoid the conflict while keeping the public API parameter name unchanged.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
These local config directories should not be tracked in git. They are now properly excluded via .gitignore. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This fix reduces request body size by 57.5% for non-ASCII content (e.g., 12.41MB → 5.27MB for websearch.json test data) and ensures compatibility with servers that enforce strict body size limits.
Closes issue with large UTF-8 payloads exceeding server limits.
Description
[Describe what this PR does and why]
Related Issue: Fixes #[issue_number] or Relates to #[issue_number]
Security Considerations: [Check if API keys or sensitive credentials are exposed in code/logs]
Type of Change
Component(s) Affected
Checklist
Testing
[How to test these changes]
Additional Notes
[Optional: any other context]