public class OkHttp3Requestor extends HttpRequestor
HttpRequestor
implementation that uses OkHttp
v3. You can only use this if your project includes the OkHttp v3 library.Modifier and Type | Class and Description |
---|---|
static class |
OkHttp3Requestor.AsyncCallback |
HttpRequestor.Header, HttpRequestor.Response, HttpRequestor.Uploader
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS
Constructor and Description |
---|
OkHttp3Requestor(okhttp3.OkHttpClient client)
Creates a new instance of this requestor that uses
client for its requests. |
Modifier and Type | Method and Description |
---|---|
protected void |
configureRequest(okhttp3.Request.Builder request)
Called beforing building the request and executing it.
|
static okhttp3.OkHttpClient |
defaultOkHttpClient()
Returns an
OkHttpClient instance with the default settings for this SDK. |
static okhttp3.OkHttpClient.Builder |
defaultOkHttpClientBuilder()
Returns an
OkHttpClient.Builder instance with the default settings for this SDK. |
HttpRequestor.Response |
doGet(java.lang.String url,
java.lang.Iterable<HttpRequestor.Header> headers) |
okhttp3.OkHttpClient |
getClient()
Returns the underlying
OkHttpClient used to make requests. |
protected okhttp3.Response |
interceptResponse(okhttp3.Response response)
Called before returning
Response from a request. |
HttpRequestor.Uploader |
startPost(java.lang.String url,
java.lang.Iterable<HttpRequestor.Header> headers) |
HttpRequestor.Uploader |
startPut(java.lang.String url,
java.lang.Iterable<HttpRequestor.Header> headers) |
startPostInStreamingMode
public OkHttp3Requestor(okhttp3.OkHttpClient client)
client
for its requests.
OkHttpClient client = OkHttp3Requestor.defaultOkHttpClient(); HttpRequestor requestor = new OkHttp3Requestor(client);
If you need to make modifications to the OkHttpClient
settings:
OkHttpClient client = OkHttp3Requestor.defaultOkHttpClientBuilder() .readTimeout(2, TimeUnit.MINUTES) ... .build();
If you don't use defaultOkHttpClient()
or defaultOkHttpClientBuilder()
,
make sure to use Dropbox's hardened SSL settings from SSLConfig
:
OkHttpClient client = OkHttpClient.Builder() ... .sslSocketFactory(SSLConfig.getSSLSocketFactory(), SSLConfig.getTrustManager()) .build();
public static okhttp3.OkHttpClient defaultOkHttpClient()
OkHttpClient
instance with the default settings for this SDK.public static okhttp3.OkHttpClient.Builder defaultOkHttpClientBuilder()
OkHttpClient.Builder
instance with the default settings for this SDK.public okhttp3.OkHttpClient getClient()
OkHttpClient
used 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.OkHttpClient
used by this requestor.protected void configureRequest(okhttp3.Request.Builder request)
This method should be used by subclasses to make any changes or additions to the request before it is issued.
request
- Builder of request to be executedprotected okhttp3.Response interceptResponse(okhttp3.Response response)
Response
from 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.
response
- OkHttp responsepublic HttpRequestor.Response doGet(java.lang.String url, java.lang.Iterable<HttpRequestor.Header> headers) throws java.io.IOException
doGet
in class HttpRequestor
java.io.IOException
public HttpRequestor.Uploader startPost(java.lang.String url, java.lang.Iterable<HttpRequestor.Header> headers) throws java.io.IOException
startPost
in class HttpRequestor
java.io.IOException
public HttpRequestor.Uploader startPut(java.lang.String url, java.lang.Iterable<HttpRequestor.Header> headers) throws java.io.IOException
startPut
in class HttpRequestor
java.io.IOException