File tree Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,15 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
186186 if ( opts . allowLargeResponse ) {
187187 android . os . StrictMode . setThreadPolicy ( android . os . StrictMode . ThreadPolicy . LAX ) ;
188188 }
189+
190+ //set connection timeout to override okhttp3 default
191+ if ( opts . timeout ) {
192+ client = client . newBuilder ( )
193+ . connectTimeout ( opts . timeout , java . util . concurrent . TimeUnit . MILLISECONDS )
194+ . writeTimeout ( opts . timeout , java . util . concurrent . TimeUnit . MILLISECONDS )
195+ . readTimeout ( opts . timeout , java . util . concurrent . TimeUnit . MILLISECONDS )
196+ . build ( ) ;
197+ }
189198
190199 client . newCall ( request . build ( ) ) . enqueue ( new okhttp3 . Callback ( {
191200 onResponse : ( task , response ) => {
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ export interface HttpsRequestOptions {
2323 * Note that once set to true, this policy remains active until the app is killed.
2424 */
2525 allowLargeResponse ?: boolean ;
26+ timeout ?: number ;
2627}
2728
2829export interface HttpsResponse {
Original file line number Diff line number Diff line change @@ -166,6 +166,10 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
166166 Object . keys ( cont ) . forEach ( key => dict . setValueForKey ( cont [ key ] as any , key ) ) ;
167167 }
168168 }
169+
170+ if ( opts . timeout ) {
171+ manager . requestSerializer . timeoutInterval = opts . timeout / 1000 ;
172+ }
169173
170174 let methods = {
171175 'GET' : 'GETParametersSuccessFailure' ,
You can’t perform that action at this time.
0 commit comments