-
Notifications
You must be signed in to change notification settings - Fork 1.3k
HttpClient configuration #12423
HttpClient configuration #12423
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.mapbox.mapboxsdk.http; | ||
|
||
import android.support.annotation.Nullable; | ||
|
||
public abstract class HttpRequest { | ||
|
||
private static HttpRequest httpRequest; | ||
|
||
static final int CONNECTION_ERROR = 0; | ||
static final int TEMPORARY_ERROR = 1; | ||
static final int PERMANENT_ERROR = 2; | ||
|
||
public static synchronized void setHttpRequest(@Nullable HttpRequest requestImpl) { | ||
httpRequest = requestImpl; | ||
} | ||
|
||
public abstract void executeRequest(NativeHttpRequest httpRequest, long nativePtr, String resourceUrl, | ||
String etag, String modified); | ||
|
||
public abstract void cancelRequest(long nativePtr); | ||
|
||
static void execute(NativeHttpRequest httpRequest, long nativePtr, String resourceUrl, | ||
String etag, String modified) { | ||
getInstance().executeRequest(httpRequest, nativePtr, resourceUrl, etag, modified); | ||
} | ||
|
||
static void cancel(long nativePtr) { | ||
getInstance().cancelRequest(nativePtr); | ||
} | ||
|
||
private static synchronized HttpRequest getInstance() { | ||
if (httpRequest == null) { | ||
httpRequest = new OkHttpRequest(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Part of the goal of having modules is that OkHttp does not need to be compiled into the APK. I think there should be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm aware of two techniques to remove code from an aar/binary:
Please elaborate how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking an option in the build rules to leave |
||
} | ||
return httpRequest; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to invoke a
cancelAll
method here because we will lose the reference to the calls when the request impl is changed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of this PR is to be able exclude okhttp, a
cancelAll
invocation in this code path on theOkHttpRequest
will result in the initiatingOkHttpRequest
and the classloader will hit aNoClassDefFoundError
.imo switching out httpclients on the fly isn't a supported use-case. You either use the default okhttp implementation or you provide an alternate implementation before requesting any resources.
I'm down with different suggestions to tackle this but don't think there is much we can do other than documenting this clearly in the javadoc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, let's document it extensively then.
What about throwing an exception when resources were already requested and a user wants to switch the implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍