summaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorMartin Fietz <marf@hadiko-99-4.hadiko.uni-karlsruhe.de>2015-04-11 11:13:26 +0200
committerMartin Fietz <marf@hadiko-99-4.hadiko.uni-karlsruhe.de>2015-04-11 11:21:16 +0200
commita34acb71d117a153606f0af26c1a297e7e524455 (patch)
treeff1af278909215f005bc7fb24a331081de1d66bf /core/src/main
parent07ce9579fb61174ce173e84daebe60e493bd725c (diff)
downloadAntennaPod-a34acb71d117a153606f0af26c1a297e7e524455.zip
Add feed: remember credentials after selecting feed, try UTF-8 for HTTP basic authentication
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java34
1 files changed, 32 insertions, 2 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java
index 2cfea1f25..f7ce38cd5 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java
@@ -81,11 +81,12 @@ public class HttpDownloader extends Downloader {
if (userInfo != null) {
String[] parts = userInfo.split(":");
if (parts.length == 2) {
- String credentials = Credentials.basic(parts[0], parts[1]);
+ String credentials = encodeCredentials(parts[0], parts[1], "ISO-8859-1");
httpReq.header("Authorization", credentials);
}
} else if (!StringUtils.isEmpty(request.getUsername()) && request.getPassword() != null) {
- String credentials = Credentials.basic(request.getUsername(), request.getPassword());
+ String credentials = encodeCredentials(request.getUsername(), request.getPassword(),
+ "ISO-8859-1");
httpReq.header("Authorization", credentials);
}
@@ -104,6 +105,24 @@ public class HttpDownloader extends Downloader {
Log.d(TAG, "Response code is " + response.code());
+ if(!response.isSuccessful() && response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) {
+ Log.d(TAG, "Authorization failed, re-trying with UTF-8 encoding");
+ if (userInfo != null) {
+ String[] parts = userInfo.split(":");
+ if (parts.length == 2) {
+ String credentials = encodeCredentials(parts[0], parts[1], "UTF-8");
+ httpReq.header("Authorization", credentials);
+ }
+ } else if (!StringUtils.isEmpty(request.getUsername()) && request.getPassword() != null) {
+ String credentials = encodeCredentials(request.getUsername(), request.getPassword(),
+ "UTF-8");
+ httpReq.header("Authorization", credentials);
+ }
+ response = httpClient.newCall(httpReq.build()).execute();
+ responseBody = response.body();
+ contentEncodingHeader = response.header("Content-Encoding");
+ isGzip = StringUtils.equalsIgnoreCase(contentEncodingHeader, "gzip");
+ }
if(!response.isSuccessful() && response.code() == HttpURLConnection.HTTP_NOT_MODIFIED) {
Log.d(TAG, "Feed '" + request.getSource() + "' not modified since last update, Download canceled");
@@ -253,4 +272,15 @@ public class HttpDownloader extends Downloader {
}
}
+ private static String encodeCredentials(String username, String password, String charset) {
+ try {
+ String credentials = username + ":" + password;
+ byte[] bytes = credentials.getBytes(charset);
+ String encoded = ByteString.of(bytes).base64();
+ return "Basic " + encoded;
+ } catch (UnsupportedEncodingException e) {
+ throw new AssertionError();
+ }
+ }
+
}