File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -544,6 +544,14 @@ export function createRequest(
544544 const tag = `okhttp_request_${ CALL_ID ++ } ` ;
545545 const call = client . newCall ( request . tag ( tag ) . build ( ) ) ;
546546
547+ // We have to allow networking on the main thread because larger responses will crash the app with an NetworkOnMainThreadException.
548+ // Note that it would probably be better to offload it to a Worker or (natively running) AsyncTask.
549+ // Also note that once set, this policy remains active until the app is killed.
550+ if ( opts . useLegacy === false && opts . allowLargeResponse ) {
551+ android . os . StrictMode . setThreadPolicy (
552+ android . os . StrictMode . ThreadPolicy . LAX
553+ ) ;
554+ }
547555 return {
548556 nativeRequest : call ,
549557 cancel : ( ) => cancelRequest ( tag , client ) ,
Original file line number Diff line number Diff line change @@ -45,6 +45,13 @@ export interface HttpsRequestOptions extends HttpRequestOptions {
4545 */
4646 timeout ?: number ;
4747
48+ /**
49+ * On Android large responses may crash the app (fi. https://httpbin.org/bytes/10000).
50+ * By setting this to true and when not using useLegacy, we allow large responses on the main thread (which this plugin currently does).
51+ * Note that once set to true, this policy remains active until the app is killed.
52+ */
53+ allowLargeResponse ?: boolean ;
54+
4855 /**
4956 * iOS for now
5057 */
You can’t perform that action at this time.
0 commit comments