diff options
author | Christopher Szucko <cszucko@gmail.com> | 2014-02-14 09:24:39 -0600 |
---|---|---|
committer | Christopher Szucko <cszucko@gmail.com> | 2014-02-14 09:24:39 -0600 |
commit | 1feb62ae853443168c27f088fcc30d5b8feb6507 (patch) | |
tree | cfd4b3a584f8b33a94ddf54fae39b4ec8a9494d7 | |
parent | 967e322913b5505029ecdcd084c058a5b286d274 (diff) | |
download | AntennaPod-1feb62ae853443168c27f088fcc30d5b8feb6507.zip |
Support HTTP Basic Authentication for Feeds
Enables the use of feed URLs with the format http://user:password@example.com
-rw-r--r-- | src/de/danoeh/antennapod/service/download/HttpDownloader.java | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/de/danoeh/antennapod/service/download/HttpDownloader.java b/src/de/danoeh/antennapod/service/download/HttpDownloader.java index fc2b3178b..1ffea19d5 100644 --- a/src/de/danoeh/antennapod/service/download/HttpDownloader.java +++ b/src/de/danoeh/antennapod/service/download/HttpDownloader.java @@ -11,8 +11,10 @@ import org.apache.commons.io.IOUtils; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; +import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.auth.BasicScheme; import java.io.*; import java.net.*; @@ -44,6 +46,15 @@ public class HttpDownloader extends Downloader { InputStream connection = null; try { HttpGet httpGet = new HttpGet(getURIFromRequestUrl(request.getSource())); + String userInfo = httpGet.getURI().getUserInfo(); + if (userInfo != null) { + String[] parts = userInfo.split(":"); + if (parts.length == 2) { + httpGet.addHeader(BasicScheme.authenticate( + new UsernamePasswordCredentials(parts[0], parts[1]), + "UTF-8", false)); + } + } HttpResponse response = httpClient.execute(httpGet); HttpEntity httpEntity = response.getEntity(); int responseCode = response.getStatusLine().getStatusCode(); |