Last active
August 29, 2015 13:56
-
-
Save stonecs/9068920 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BasicAuthOkHttpLoader extends OkHttpDownloader { | |
private static final int MAX_SIZE = 1024 * 1024 * 7; // 7MB | |
private static final int MAX_STALE = 30 * 24 * 60 * 60; // 30 days | |
@Inject | |
public BasicAuthOkHttpLoader() { | |
super(Utils.getImageCacheDirectory(), MAX_SIZE); | |
} | |
@Override | |
protected HttpURLConnection openConnection(Uri uri) throws IOException { | |
HttpURLConnection connection = super.openConnection(uri); | |
String authString = getHttpUsername() + ":" + getHttpPassword(); | |
final String authStringEnc = Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP); | |
connection.setRequestProperty("Authorization", "Basic " + authStringEnc); | |
connection.setRequestProperty("Cache-Control", "max-stale=" + MAX_STALE); | |
return connection; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment