Skip to content

Commit 4487697

Browse files
cortinicofacebook-github-bot
authored andcommitted
Migrate OkHttpCompat to Kotlin (#51625)
Summary: Pull Request resolved: #51625 This just migrates this class to Kotlin, which is also the last class in this package. Changelog: [Internal] [Changed] - Reviewed By: rshest Differential Revision: D75448161 fbshipit-source-id: d5457dd8017fd459d166d2945ff440c303943db2
1 parent 66aca66 commit 4487697

3 files changed

Lines changed: 35 additions & 42 deletions

File tree

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,10 +3025,10 @@ public final class com/facebook/react/modules/network/OkHttpClientProvider {
30253025
public static final fun setOkHttpClientFactory (Lcom/facebook/react/modules/network/OkHttpClientFactory;)V
30263026
}
30273027

3028-
public class com/facebook/react/modules/network/OkHttpCompat {
3029-
public fun <init> ()V
3030-
public static fun getCookieJarContainer (Lokhttp3/OkHttpClient;)Lcom/facebook/react/modules/network/CookieJarContainer;
3031-
public static fun getHeadersFromMap (Ljava/util/Map;)Lokhttp3/Headers;
3028+
public final class com/facebook/react/modules/network/OkHttpCompat {
3029+
public static final field INSTANCE Lcom/facebook/react/modules/network/OkHttpCompat;
3030+
public final fun getCookieJarContainer (Lokhttp3/OkHttpClient;)Lcom/facebook/react/modules/network/CookieJarContainer;
3031+
public final fun getHeadersFromMap (Ljava/util/Map;)Lokhttp3/Headers;
30323032
}
30333033

30343034
public abstract interface class com/facebook/react/modules/network/ProgressListener {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/OkHttpCompat.java

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
@file:Suppress("DEPRECATION_ERROR") // Conflicting okhttp versions
9+
10+
package com.facebook.react.modules.network
11+
12+
import com.facebook.infer.annotation.Nullsafe
13+
import okhttp3.Headers
14+
import okhttp3.OkHttpClient
15+
16+
/**
17+
* Helper class that provides wrappers for compatibility between different OkHttp versions.
18+
*
19+
* This is required for Kotlin code compatibility, in particular, therefore if you are going to
20+
* migrate this file to Kotlin, please first ensure that there is no OkHttp API discrepancy between
21+
* different RN platform environments, and then consider getting rid of this compat layer
22+
* altogether.
23+
*/
24+
@Nullsafe(Nullsafe.Mode.LOCAL)
25+
public object OkHttpCompat {
26+
public fun getCookieJarContainer(client: OkHttpClient): CookieJarContainer =
27+
client.cookieJar() as CookieJarContainer
28+
29+
public fun getHeadersFromMap(headers: Map<String, String>?): Headers =
30+
Headers.of(headers ?: emptyMap())
31+
}

0 commit comments

Comments
 (0)