Add ASCII sanitization utility for HTTP header compatibility#1596
Add ASCII sanitization utility for HTTP header compatibility#1596rahul-lohra merged 3 commits intodevelopfrom
Conversation
Removes a redundant `/**/` comment from the `buildUserAgent` function in `HeadersUtil.kt`.
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
WalkthroughThe change adds a header sanitization feature to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Fix all issues with AI Agents 🤖
In
@stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/header/HeadersUtil.kt:
- Around line 101-104: The String.sanitize() extension currently compiles the
regex on every call, hurting performance; move the pattern to a precompiled
companion object constant (e.g. private val NON_ASCII_REGEX =
"[^\\p{ASCII}]".toRegex()) and use it in sanitize() instead of creating a new
regex each time, and add a brief KDoc to sanitize() explaining it performs
Unicode normalization (Normalizer.Form.NFD) and strips non-ASCII characters;
reference the sanitize() function and the new companion object constant when
making the change.
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/header/HeadersUtil.kt
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{kt,java}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{kt,java}: Use Kotlin with JVM toolchain 17; Java is legacy-only
Use 4-space indentation with no trailing whitespace
Avoid wildcard imports
Files:
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/header/HeadersUtil.kt
**/*.{kt,kts}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{kt,kts}: Use PascalCase for types and Composables (e.g.,StreamCallActivity,ParticipantGrid)
Use camelCase for functions and values
Use UPPER_SNAKE_CASE for constants only when truly constant
Prefer explicit visibility modifiers; limitinternalleakage across modules
Keep critical RTC paths off the main thread; prefer coroutines with structured scopes
Monitor logging verbosity; rely onStreamVideoImpl.developmentModefor guardrails
Use KDoc (/** ... */) for public APIs and complex subsystems; link to Stream docs when relevant
Group large files with// regionjudiciously; keep commentary purposeful
Sanitize logs to avoid dumping JWTs, ICE tokens, or call IDs in verbose logs
Pause/resume capture on lifecycle changes; ensure background audio routing is intentional
Validate orientation, aspect ratio, and dynascale handling for both portrait/landscape phones and tablets
Keep concurrency deterministic—use structured coroutines and avoid global scope
Ensure cleanup/teardown paths handle cancellation and failure (important for sockets, queues, retries)
Files:
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/header/HeadersUtil.kt
**/*.{kt,java,kts,gradle.kts}
📄 CodeRabbit inference engine (AGENTS.md)
Follow Spotless formatting; ensure custom license headers are in
spotless/directory
Files:
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/header/HeadersUtil.kt
🧠 Learnings (1)
📚 Learning: 2025-12-19T09:15:37.269Z
Learnt from: CR
Repo: GetStream/stream-video-android PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-19T09:15:37.269Z
Learning: Applies to **/*.{kt,kts} : Sanitize logs to avoid dumping JWTs, ICE tokens, or call IDs in verbose logs
Applied to files:
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/header/HeadersUtil.kt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build / compose apks
- GitHub Check: compare-sdk-sizes / Compare SDK sizes
- GitHub Check: base-android-ci / Run unit tests
- GitHub Check: base-android-ci / Build
- GitHub Check: base-android-ci / Run static checks
🔇 Additional comments (2)
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/header/HeadersUtil.kt (2)
25-25: LGTM - Import is necessary for Unicode normalization.The import of
java.text.Normalizeris required for the ASCII sanitization feature.
85-85: LGTM - Sanitization applied at the correct point.Applying
.sanitize()to the fully assembled header string ensures the entire header value is ASCII-safe before being used in HTTP requests.
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/header/HeadersUtil.kt
Show resolved
Hide resolved
SDK Size Comparison 📏
|
This commit optimizes the `sanitize` function in `HeadersUtil` by extracting the regex for non-ASCII characters into a pre-compiled `private val`. This avoids recompiling the regular expression on every invocation of the function, improving performance. Additionally, detailed KDoc has been added to the `sanitize` function to better explain its purpose and behavior, including examples of character decomposition.
|



Goal
Ensure HTTP headers are ASCII-safe by normalizing and stripping non-ASCII characters to prevent OkHttp header validation issues and align with Chat product behavior.
Implementation
Ensure HTTP headers are ASCII-safe by normalizing and stripping non-ASCII characters to prevent OkHttp header validation issues and align with Chat product behavior.
🎨 UI Changes
None
Testing
Pass special character in
appNamein StringBuilder and sdk should work as usualSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.