|
@@ -44,10 +44,11 @@ class NetworkHelper(context: Context) {
|
|
|
|
|
|
@JvmOverloads
|
|
@JvmOverloads
|
|
fun request(request: Request, forceCache: Boolean = false): Observable<Response> {
|
|
fun request(request: Request, forceCache: Boolean = false): Observable<Response> {
|
|
|
|
+ var response: Response? = null
|
|
return Observable.fromCallable {
|
|
return Observable.fromCallable {
|
|
val c = if (forceCache) forceCacheClient else client
|
|
val c = if (forceCache) forceCacheClient else client
|
|
- c.newCall(request).execute()
|
|
|
|
- }
|
|
|
|
|
|
+ c.newCall(request).execute().apply { response = this }
|
|
|
|
+ }.doOnUnsubscribe { response?.body()?.close() }
|
|
}
|
|
}
|
|
|
|
|
|
@JvmOverloads
|
|
@JvmOverloads
|
|
@@ -57,6 +58,7 @@ class NetworkHelper(context: Context) {
|
|
}
|
|
}
|
|
|
|
|
|
fun requestBodyProgress(request: Request, listener: ProgressListener): Observable<Response> {
|
|
fun requestBodyProgress(request: Request, listener: ProgressListener): Observable<Response> {
|
|
|
|
+ var response: Response? = null
|
|
return Observable.fromCallable {
|
|
return Observable.fromCallable {
|
|
val progressClient = client.newBuilder()
|
|
val progressClient = client.newBuilder()
|
|
.cache(null)
|
|
.cache(null)
|
|
@@ -68,8 +70,8 @@ class NetworkHelper(context: Context) {
|
|
}
|
|
}
|
|
.build()
|
|
.build()
|
|
|
|
|
|
- progressClient.newCall(request).execute()
|
|
|
|
- }.retry(1)
|
|
|
|
|
|
+ progressClient.newCall(request).execute().apply { response = this }
|
|
|
|
+ }.doOnUnsubscribe { response?.body()?.close() }.retry(1)
|
|
}
|
|
}
|
|
|
|
|
|
val cookies: CookieStore
|
|
val cookies: CookieStore
|