com.facebook.react.modules.network.OkHttpClientProvider Java Examples
The following examples show how to use
com.facebook.react.modules.network.OkHttpClientProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FrescoModule.java From react-native-GPay with MIT License | 6 votes |
/** * Get the default Fresco configuration builder. * Allows adding of configuration options in addition to the default values. * * @return {@link ImagePipelineConfig.Builder} that has been initialized with default values */ public static ImagePipelineConfig.Builder getDefaultConfigBuilder(ReactContext context) { HashSet<RequestListener> requestListeners = new HashSet<>(); requestListeners.add(new SystraceRequestListener()); OkHttpClient client = OkHttpClientProvider.createClient(); // make sure to forward cookies for any requests via the okHttpClient // so that image requests to endpoints that use cookies still work CookieJarContainer container = (CookieJarContainer) client.cookieJar(); ForwardingCookieHandler handler = new ForwardingCookieHandler(context); container.setCookieJar(new JavaNetCookieJar(handler)); return OkHttpImagePipelineConfigFactory .newBuilder(context.getApplicationContext(), client) .setNetworkFetcher(new ReactOkHttpNetworkFetcher(client)) .setDownsampleEnabled(false) .setRequestListeners(requestListeners); }
Example #2
Source File: ResourceManager.java From react-native-tensorflow with Apache License 2.0 | 5 votes |
private byte[] loadFromUrl(String url) { try { Request request = new Request.Builder().url(url).get().build(); Response response = OkHttpClientProvider.createClient().newCall(request).execute(); return response.body().bytes(); } catch (IOException e) { throw new IllegalStateException("Could not fetch data from url " + url); } }
Example #3
Source File: DataSourceUtil.java From react-native-video with MIT License | 5 votes |
private static HttpDataSource.Factory buildHttpDataSourceFactory(ReactContext context, DefaultBandwidthMeter bandwidthMeter, Map<String, String> requestHeaders) { OkHttpClient client = OkHttpClientProvider.getOkHttpClient(); CookieJarContainer container = (CookieJarContainer) client.cookieJar(); ForwardingCookieHandler handler = new ForwardingCookieHandler(context); container.setCookieJar(new JavaNetCookieJar(handler)); OkHttpDataSourceFactory okHttpDataSourceFactory = new OkHttpDataSourceFactory(client, getUserAgent(context), bandwidthMeter); if (requestHeaders != null) okHttpDataSourceFactory.getDefaultRequestProperties().set(requestHeaders); return okHttpDataSourceFactory; }