Last active
May 26, 2020 21:36
-
-
Save janicduplessis/211313b1019acdb2b1b517eb90133e36 to your computer and use it in GitHub Desktop.
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
dependencies { | |
... | |
+ implementation "com.squareup.okhttp3:okhttp-brotli:4.7.2" | |
} |
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
async function fetchData() { | |
return await fetch('https://www.google.com', { | |
headers: | |
// It is important that the Accept-Encoding key is not present on Android. | |
// Null / undefined won't work. | |
Platform.OS === 'ios' && parseInt(Platform.Version as string, 10) >= 11 | |
? { | |
'Accept-Encoding': 'br,gzip', | |
} | |
: {}, | |
}).then((res) => res.text()); | |
} |
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
+ import com.facebook.react.modules.network.OkHttpClientProvider; | |
+ import okhttp3.OkHttpClient; | |
+ import okhttp3.brotli.BrotliInterceptor; | |
... | |
public void onCreate() { | |
super.onCreate(); | |
+ OkHttpClientProvider.setOkHttpClientFactory(() -> { | |
+ OkHttpClient.Builder builder = OkHttpClientProvider.createClientBuilder(); | |
+ builder.addInterceptor(BrotliInterceptor.INSTANCE); | |
+ return builder.build(); | |
+ }); | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment