public class StandardHttpRequestor extends HttpRequestor
HttpRequestor
implementation that uses Java's standard library
HttpsURLConnection
. If you just want a connection with the
default settings, use the predefined INSTANCE
.
If you want to customize the way the connection is configured, create a
subclass that overrides configureConnection(javax.net.ssl.HttpsURLConnection)
.
Modifier and Type | Class and Description |
---|---|
static class |
StandardHttpRequestor.Config
Configuration for
StandardHttpRequestor that determines
how network connections to the server are established. |
HttpRequestor.Header, HttpRequestor.Response
Modifier and Type | Field and Description |
---|---|
static StandardHttpRequestor |
INSTANCE
A thread-safe instance of
StandardHttpRequestor that connects directly
(as opposed to using a proxy). |
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS
Constructor and Description |
---|
StandardHttpRequestor(StandardHttpRequestor.Config config)
Creates an instance that connects through the given proxy.
|
Modifier and Type | Method and Description |
---|---|
protected void |
configure(HttpURLConnection conn)
Can be overriden to configure the underlying
HttpURLConnection used to make network
requests using https. |
protected void |
configureConnection(HttpsURLConnection conn)
Deprecated.
use
configure(java.net.HttpURLConnection) instead. |
HttpRequestor.Response |
doGet(String url,
Iterable<HttpRequestor.Header> headers) |
protected void |
interceptResponse(HttpURLConnection conn)
Called before returning
Response from a request. |
com.dropbox.core.http.StandardHttpRequestor.Uploader |
startPost(String url,
Iterable<HttpRequestor.Header> headers) |
com.dropbox.core.http.StandardHttpRequestor.Uploader |
startPut(String url,
Iterable<HttpRequestor.Header> headers) |
public static final StandardHttpRequestor INSTANCE
StandardHttpRequestor
that connects directly
(as opposed to using a proxy).public StandardHttpRequestor(StandardHttpRequestor.Config config)
public HttpRequestor.Response doGet(String url, Iterable<HttpRequestor.Header> headers) throws IOException
doGet
in class HttpRequestor
IOException
public com.dropbox.core.http.StandardHttpRequestor.Uploader startPost(String url, Iterable<HttpRequestor.Header> headers) throws IOException
startPost
in class HttpRequestor
IOException
public com.dropbox.core.http.StandardHttpRequestor.Uploader startPut(String url, Iterable<HttpRequestor.Header> headers) throws IOException
startPut
in class HttpRequestor
IOException
@Deprecated protected void configureConnection(HttpsURLConnection conn) throws IOException
configure(java.net.HttpURLConnection)
instead.HttpsURLConnection
used to make
network requests. If you override this method, you should probably call
super.configureConnection(conn)
in your overridden method.IOException
protected void configure(HttpURLConnection conn) throws IOException
HttpURLConnection
used to make network
requests using https. Typically the connection will be a HttpsURLConnection
, but that is dependent on the Java runtime. Care should be
taken when casting the connection (check your JRE).
If you are using Google App Engine, configure your DbxRequestConfig
to use GoogleAppEngineRequestor
as its default
HttpRequestor
. If you use StandardHttpRequestor
in Google App Engine, SSL
certificates may not be validated and your app will susceptible to Man-in-the-Middle attacks.
conn
- URL connection object returned after creating an https network request.IOException
protected void interceptResponse(HttpURLConnection conn) throws IOException
Response
from a request.
This method should be used by subclasses to add any logging, analytics, or cleanup
necessary. Note that the connection response code and response streams will already be
fetched before calling this method. This means any IOException
from reading the
response should already have occurred before this method is called.
Do not consume the response or error streams in this method.
conn
- HTTP URL connectionIOException