77import okhttp3 .OkHttpClient ;
88import okhttp3 .Request ;
99import okhttp3 .RequestBody ;
10- import okhttp3 .internal .Util ;
1110
1211import java .io .Closeable ;
1312import java .io .File ;
14- import java .io .InputStream ;
1513import java .io .InterruptedIOException ;
1614import java .io .IOException ;
1715import java .io .OutputStream ;
2018import java .util .Map ;
2119import java .util .concurrent .TimeUnit ;
2220
23- import okio .Buffer ;
2421import okio .BufferedSink ;
2522
2623/*>>> import checkers.nullness.quals.Nullable; */
2724
2825/**
2926 * {@link HttpRequestor} implementation that uses <a href="http://square.github.io/okhttp/">OkHttp
3027 * v3</a>. You can only use this if your project includes the OkHttp v3 library.
31- *
32- * <p>
33- * To use this, pass {@link #INSTANCE} to the {@link com.dropbox.core.DbxRequestConfig} constructor.
34- * </p>
3528 */
3629public class OkHttp3Requestor extends HttpRequestor {
3730/**
38- *A thread-safe instance of {@code OkHttp3Requestor} that connects directly
39- *(as opposed to using a proxy).
31+ *@deprecated This field will be removed. Instead, do:
32+ * {@code new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient())}
4033 */
34+ @ Deprecated
4135public static final OkHttp3Requestor INSTANCE =new OkHttp3Requestor (defaultOkHttpClient ());
4236
43- private final OkHttpClient client ;
37+ /**
38+ * Returns an {@code OkHttpClient} instance with the default settings for this SDK.
39+ */
40+ public static OkHttpClient defaultOkHttpClient () {
41+ return defaultOkHttpClientBuilder ().build ();
42+ }
4443
45- private static OkHttpClient defaultOkHttpClient () {
44+ /**
45+ * Returns an {@code OkHttpClient.Builder} instance with the default settings for this SDK.
46+ */
47+ public static OkHttpClient .Builder defaultOkHttpClientBuilder () {
4648return new OkHttpClient .Builder ()
4749 .connectTimeout (DEFAULT_CONNECT_TIMEOUT_MILLIS ,TimeUnit .MILLISECONDS )
4850 .readTimeout (DEFAULT_READ_TIMEOUT_MILLIS ,TimeUnit .MILLISECONDS )
4951 .writeTimeout (DEFAULT_READ_TIMEOUT_MILLIS ,TimeUnit .MILLISECONDS )
5052// enables certificate pinning
51- .sslSocketFactory (SSLConfig .getSSLSocketFactory (),SSLConfig .getTrustManager ())
52- .build ();
53+ .sslSocketFactory (SSLConfig .getSSLSocketFactory (),SSLConfig .getTrustManager ());
5354 }
5455
56+ private final OkHttpClient client ;
57+
5558/**
5659 * Creates a new instance of this requestor that uses {@code client} for its requests.
5760 *
58- * <p> NOTE: This constructor will not enable certificate pinning on the client. If you want
59- * certificate pinning, use the default instance, {@link #INSTANCE}, or clone the default client
60- * and modify it accordingly:
61+ * <pre>
62+ * OkHttpClient client = OkHttp3Requestor.defaultOkHttpClient();
63+ * HttpRequestor requestor = new OkHttp3Requestor(client);
64+ * </pre>
6165 *
62- * <p> NOTE: This SDK requires that OkHttp clients do not use same-thread executors for issuing
63- *calls. The SDK relies on the assumption that all asynchronous calls will actually be executed
64- *asynchronously. Using a same-thread executor for your OkHttp client may result in dead-locks.
66+ * <p>
67+ *If you need to make modifications to the {@link OkHttpClient} settings:
68+ *</p>
6569 *
6670 * <pre>
67- * OkHttpClient client = OkHttpRequestor.INSTANCE.getClient()
68- * .readTimeout(2, TimeUnit.MINUTES)
69- * // ... other modifications
70- * .build();
71- * HttpRequestor requestor = new OkHttpRequestor(client);
71+ * OkHttpClient client = OkHttp3Requestor.defaultOkHttpClientBuilder()
72+ * .readTimeout(2, TimeUnit.MINUTES)
73+ * ...
74+ * .build();
7275 * </pre>
7376 *
74- * @param client {@code OkHttpClient} to use for requests, never {@code null}
77+ * If you don't use {@link #defaultOkHttpClient()} or {@link #defaultOkHttpClientBuilder()},
78+ * make sure to use Dropbox's hardened SSL settings from {@link SSLConfig}:
79+ * </p>
7580 *
76- * @throws IllegalArgumentException if client uses a same-thread executor for its dispatcher
81+ * <pre>
82+ * OkHttpClient client = OkHttpClient.Builder()
83+ * ...
84+ * .sslSocketFactory(SSLConfig.getSSLSocketFactory(), SSLConfig.getTrustManager())
85+ * .build();
86+ * </pre>
7787 */
7888public OkHttp3Requestor (OkHttpClient client ) {
7989if (client ==null )throw new NullPointerException ("client" );
@@ -82,10 +92,13 @@ public OkHttp3Requestor(OkHttpClient client) {
8292 }
8393
8494/**
85- * @deprecated If you need access to the {@link OkHttpClient} instance you passed
86- * into the constructor, keep track of it yourself.
95+ * Returns the underlying {@code OkHttpClient} used to make requests.
96+ *
97+ * If you want to modify the client for a particular request, create a new instance of this
98+ * requestor with the modified client.
99+ *
100+ * @return underlying {@code OkHttpClient} used by this requestor.
87101 */
88- @ Deprecated
89102public OkHttpClient getClient () {
90103return client ;
91104 }