aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-10-14 13:30:01 -0700
committerScott Jackson <daneren2005@gmail.com>2016-10-17 17:07:55 -0700
commit4f2655b59a323f1936a72b2622e693c589f18fbb (patch)
tree5bccd44a02e3de4840e07e75d39b31a81388709b /app
parentb53cff3acfb12980001c30cf262d8f74f4740e68 (diff)
downloaddsub-4f2655b59a323f1936a72b2622e693c589f18fbb.tar.gz
dsub-4f2655b59a323f1936a72b2622e693c589f18fbb.tar.bz2
dsub-4f2655b59a323f1936a72b2622e693c589f18fbb.zip
HttpUrlConnection doesn't auto follow http -> https redirects
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
index b05a569d..cb8871a0 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
@@ -1875,12 +1875,29 @@ public class RESTMusicService implements MusicService {
if(connection.getResponseCode() >= 500) {
throw new IOException("Error code: " + connection.getResponseCode());
}
- detectRedirect(context, urlObj, connection);
+ if(detectRedirect(context, urlObj, connection)) {
+ String rewrittenUrl = rewriteUrlWithRedirect(context, url);
+ if(!rewrittenUrl.equals(url)) {
+ connection.disconnect();
+ return getConnectionDirect(context, rewrittenUrl, headers, minNetworkTimeout);
+ }
+ }
+
return connection;
}
- private void detectRedirect(Context context, URL originalUrl, HttpURLConnection connection) throws Exception {
+ // Returns true when we should immediately retry with the redirect
+ private boolean detectRedirect(Context context, URL originalUrl, HttpURLConnection connection) throws Exception {
+ if(connection.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP || connection.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM) {
+ String redirectLocation = connection.getHeaderField("Location");
+ if(redirectLocation != null) {
+ detectRedirect(context, originalUrl.toExternalForm(), redirectLocation);
+ return true;
+ }
+ }
+
detectRedirect(context, originalUrl, connection.getURL());
+ return false;
}
private void detectRedirect(Context context, URL originalUrl, URL redirectedUrl) throws Exception {
detectRedirect(context, originalUrl.toExternalForm(), redirectedUrl.toExternalForm());