hacking into http client trying to fix connectivity problem

This commit is contained in:
Mariotaku Lee 2016-02-13 19:46:26 +08:00
parent 787b780960
commit a750f3cb7e
3 changed files with 31 additions and 10 deletions

View File

@ -33,7 +33,7 @@ import org.mariotaku.restfu.http.mime.Body;
import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
import org.mariotaku.twidere.api.twitter.model.ResponseCode;
import org.mariotaku.twidere.api.twitter.model.TwitterResponseObject;
import org.mariotaku.twidere.api.twitter.model.TwitterResponse;
import org.mariotaku.twidere.api.twitter.model.User;
import java.io.IOException;
@ -125,8 +125,8 @@ public class TwitterConverterFactory extends RestConverter.SimpleFactory<Twitter
final InputStream stream = body.stream();
final Object object = parseOrThrow(stream, type);
checkResponse(type, object, httpResponse);
if (object instanceof TwitterResponseObject) {
((TwitterResponseObject) object).processResponseHeader(httpResponse);
if (object instanceof TwitterResponse) {
((TwitterResponse) object).processResponseHeader(httpResponse);
}
return object;
}

View File

@ -0,0 +1,20 @@
package okhttp3;
import android.support.annotation.Nullable;
import okhttp3.internal.http.HttpEngine;
/**
* Created by mariotaku on 16/2/13.
*/
public class RealCallAccessor {
@Nullable
public static HttpEngine getHttpEngine(Call call) {
if (call instanceof RealCall) {
return ((RealCall) call).engine;
}
return null;
}
}

View File

@ -34,14 +34,15 @@ import java.util.List;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.ConnectionPool;
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.RealCallAccessor;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.internal.http.HttpEngine;
import okio.BufferedSink;
import okio.Okio;
@ -303,13 +304,13 @@ public class OkHttpRestClient implements RestHttpClient {
public Response getResponse() throws IOException {
if (exception != null) throw exception;
if (response == null) {
if (!call.isCanceled()) {
call.cancel();
}
if (reachedTimeout()) {
ConnectionPool pool = call.client.client.connectionPool();
pool.evictAll();
throw new SocketTimeoutException("Request timed out after " + timeout + " ms");
final SocketTimeoutException exception = new SocketTimeoutException("Request timed out after " + timeout + " ms");
final HttpEngine httpEngine = RealCallAccessor.getHttpEngine(call.call);
if (httpEngine != null) {
httpEngine.streamAllocation.connectionFailed(exception);
}
throw exception;
} else {
throw new IOException("Request cancelled");
}