Migrate HeaderUtil to Kotlin (#48676)

Summary:
Migrate `HeaderUtil` to Kotlin.

## Changelog:

[INTERNAL] - Migrate `HeaderUtil` to Kotlin

Pull Request resolved: https://github.com/facebook/react-native/pull/48676

Test Plan:
The file had tests:

```bash
yarn test-android
```

Reviewed By: fabriziocucci

Differential Revision: D68205283

Pulled By: javache

fbshipit-source-id: 23ad7726a5e597d5012eec6b194af3b1e10a8b7a
This commit is contained in:
Mateo Guzmán
2025-01-15 04:45:02 -08:00
committed by Facebook GitHub Bot
parent d90c278672
commit e7378f0d9e
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.modules.network;
package com.facebook.react.modules.network
/**
* The class purpose is to weaken too strict OkHttp restriction on http headers. See:
@@ -13,19 +13,21 @@ package com.facebook.react.modules.network;
* information. It is better to get 401 from the server in this case, rather than non descriptive
* error as 401 could be handled to invalidate the wrong token in the client code.
*/
class HeaderUtil {
public static String stripHeaderName(String name) {
StringBuilder builder = new StringBuilder(name.length());
boolean modified = false;
for (int i = 0, length = name.length(); i < length; i++) {
char c = name.charAt(i);
if (c > '\u0020' && c < '\u007f') {
builder.append(c);
} else {
modified = true;
internal class HeaderUtil {
public companion object {
@JvmStatic
public fun stripHeaderName(name: String): String {
val builder = StringBuilder(name.length)
var modified = false
for (i in 0 until name.length) {
val c = name[i]
if (c > '\u0020' && c < '\u007f') {
builder.append(c)
} else {
modified = true
}
}
return if (modified) builder.toString() else name
}
return modified ? builder.toString() : name;
}
}