Package com.dropbox.core.http
Class OkHttp3Requestor
java.lang.Object
com.dropbox.core.http.HttpRequestor
com.dropbox.core.http.OkHttp3Requestor
HttpRequestor implementation that uses OkHttp
v3. You can only use this if your project includes the OkHttp v3 library.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.dropbox.core.http.HttpRequestor
HttpRequestor.Header, HttpRequestor.Response, HttpRequestor.Uploader -
Field Summary
Fields inherited from class com.dropbox.core.http.HttpRequestor
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS -
Constructor Summary
ConstructorsConstructorDescriptionOkHttp3Requestor(okhttp3.OkHttpClient client) Creates a new instance of this requestor that usesclientfor its requests. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconfigureRequest(okhttp3.Request.Builder request) Called beforing building the request and executing it.static okhttp3.OkHttpClientReturns anOkHttpClientinstance with the default settings for this SDK.static okhttp3.OkHttpClient.BuilderReturns anOkHttpClient.Builderinstance with the default settings for this SDK.doGet(String url, Iterable<HttpRequestor.Header> headers) okhttp3.OkHttpClientReturns the underlyingOkHttpClientused to make requests.protected okhttp3.ResponseinterceptResponse(okhttp3.Response response) Called before returningHttpRequestor.Responsefrom a request.startPost(String url, Iterable<HttpRequestor.Header> headers) startPut(String url, Iterable<HttpRequestor.Header> headers) Methods inherited from class com.dropbox.core.http.HttpRequestor
startPostInStreamingMode
-
Constructor Details
-
OkHttp3Requestor
public OkHttp3Requestor(okhttp3.OkHttpClient client) Creates a new instance of this requestor that usesclientfor its requests.OkHttpClient client = OkHttp3Requestor.defaultOkHttpClient(); HttpRequestor requestor = new OkHttp3Requestor(client);
If you need to make modifications to the
OkHttpClientsettings:OkHttpClient client = OkHttp3Requestor.defaultOkHttpClientBuilder() .readTimeout(2, TimeUnit.MINUTES) ... .build();
-
-
Method Details
-
defaultOkHttpClient
public static okhttp3.OkHttpClient defaultOkHttpClient()Returns anOkHttpClientinstance with the default settings for this SDK. -
defaultOkHttpClientBuilder
public static okhttp3.OkHttpClient.Builder defaultOkHttpClientBuilder()Returns anOkHttpClient.Builderinstance with the default settings for this SDK. -
getClient
public okhttp3.OkHttpClient getClient()Returns the underlyingOkHttpClientused to make requests. If you want to modify the client for a particular request, create a new instance of this requestor with the modified client.- Returns:
- underlying
OkHttpClientused by this requestor.
-
configureRequest
protected void configureRequest(okhttp3.Request.Builder request) Called beforing building the request and executing it.This method should be used by subclasses to make any changes or additions to the request before it is issued.
- Parameters:
request- Builder of request to be executed
-
interceptResponse
protected okhttp3.Response interceptResponse(okhttp3.Response response) Called before returningHttpRequestor.Responsefrom a request.This method should be used by subclasses to add any logging, analytics, or cleanup necessary.
If the response body is consumed, it should be replaced.
- Parameters:
response- OkHttp response- Returns:
- OkHttp response
-
doGet
public HttpRequestor.Response doGet(String url, Iterable<HttpRequestor.Header> headers) throws IOException - Specified by:
doGetin classHttpRequestor- Throws:
IOException
-
startPost
public HttpRequestor.Uploader startPost(String url, Iterable<HttpRequestor.Header> headers) throws IOException - Specified by:
startPostin classHttpRequestor- Throws:
IOException
-
startPut
public HttpRequestor.Uploader startPut(String url, Iterable<HttpRequestor.Header> headers) throws IOException - Specified by:
startPutin classHttpRequestor- Throws:
IOException
-