Skip to content

Commit 027b0fe

Browse files
committed
Allow override BaseImageDownloader.createConnection(String)
1 parent 012f7df commit 027b0fe

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

library/src/com/nostra13/universalimageloader/core/download/BaseImageDownloader.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class BaseImageDownloader implements ImageDownloader {
5555
/** {@value} */
5656
protected static final String ALLOWED_URI_CHARS = "@#&=*+-_.,:!?()/~'%";
5757

58-
private static final int MAX_REDIRECT_COUNT = 5;
58+
protected static final int MAX_REDIRECT_COUNT = 5;
5959

6060
private static final String ERROR_UNSUPPORTED_SCHEME = "UIL doesn't support scheme(protocol) by default [%s]. "
6161
+ "You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))";
@@ -104,26 +104,34 @@ public InputStream getStream(String imageUri, Object extra) throws IOException {
104104
* DisplayImageOptions.extraForDownloader(Object)}; can be null
105105
* @return {@link InputStream} of image
106106
* @throws IOException if some I/O error occurs during network request or if no InputStream could be created for
107-
* URI.
107+
* URL.
108108
*/
109109
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
110-
HttpURLConnection conn = connectTo(imageUri);
110+
HttpURLConnection conn = createConnection(imageUri);
111111

112112
int redirectCount = 0;
113113
while (conn.getResponseCode() / 100 == 3 && redirectCount < MAX_REDIRECT_COUNT) {
114-
conn = connectTo(conn.getHeaderField("Location"));
114+
conn = createConnection(conn.getHeaderField("Location"));
115115
redirectCount++;
116116
}
117117

118118
return new BufferedInputStream(conn.getInputStream(), BUFFER_SIZE);
119119
}
120120

121-
private HttpURLConnection connectTo(String url) throws IOException {
121+
/**
122+
* Create {@linkplain HttpURLConnection HTTP connection} for incoming URL
123+
*
124+
* @param url URL to connect to
125+
* @return {@linkplain HttpURLConnection Connection} for incoming URL. Connection isn't established so it still
126+
* configurable.
127+
* @throws IOException if some I/O error occurs during network request or if no InputStream could be created for
128+
* URL.
129+
*/
130+
protected HttpURLConnection createConnection(String url) throws IOException {
122131
String encodedUrl = Uri.encode(url, ALLOWED_URI_CHARS);
123132
HttpURLConnection conn = (HttpURLConnection) new URL(encodedUrl).openConnection();
124133
conn.setConnectTimeout(connectTimeout);
125134
conn.setReadTimeout(readTimeout);
126-
conn.connect();
127135
return conn;
128136
}
129137

0 commit comments

Comments
 (0)