Skip to content

Instantly share code, notes, and snippets.

@janicduplessis
Last active May 26, 2020 21:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save janicduplessis/211313b1019acdb2b1b517eb90133e36 to your computer and use it in GitHub Desktop.
Save janicduplessis/211313b1019acdb2b1b517eb90133e36 to your computer and use it in GitHub Desktop.
dependencies {
...
+ implementation "com.squareup.okhttp3:okhttp-brotli:4.7.2"
}
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());
}
+ 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