From 0d8bdf6d23843874d0f61ebbca6acc9ffdd3ae13 Mon Sep 17 00:00:00 2001 From: Paul Ortyl Date: Sun, 10 Mar 2013 20:13:58 +0100 Subject: fix regression (issue #96): fix broken URLs in redirection instead of failing --- .../service/download/APRedirectHandler.java | 55 ++++++++++++++++++++++ .../service/download/HttpDownloader.java | 15 +++--- 2 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 src/de/danoeh/antennapod/service/download/APRedirectHandler.java (limited to 'src/de') diff --git a/src/de/danoeh/antennapod/service/download/APRedirectHandler.java b/src/de/danoeh/antennapod/service/download/APRedirectHandler.java new file mode 100644 index 000000000..9416ef9d7 --- /dev/null +++ b/src/de/danoeh/antennapod/service/download/APRedirectHandler.java @@ -0,0 +1,55 @@ +package de.danoeh.antennapod.service.download; + +import java.net.URI; + +import org.apache.http.Header; +import org.apache.http.HttpResponse; +import org.apache.http.impl.client.DefaultRedirectHandler; +import org.apache.http.protocol.HttpContext; + +import de.danoeh.antennapod.AppConfig; +import android.util.Log; + +public class APRedirectHandler extends DefaultRedirectHandler { + // Identifier for logger + private static final String TAG = "APRedirectHandler"; + // Header field, which has to be potentially fixed + private static final String LOC = "Location"; + // Regular expressions for character strings, which should not appear in URLs + private static final String CHi[] = { "\\{", "\\}", "\\|", "\\\\", "\\^", "~", "\\[", "\\]", "\\`"}; + private static final String CHo[] = { "%7B", "%7D", "%7C", "%5C", "%5E", "%7E", "%5B", "%5D", "%60"}; + + /** + * Workaround for broken URLs in redirection. + * Proper solution involves LaxRedirectStrategy() which is not available in + * current API yet. + */ + @Override + public URI getLocationURI(HttpResponse response, HttpContext context) + throws org.apache.http.ProtocolException { + + Header h[] = response.getHeaders(LOC); + if (h.length>0) { + String s = h[0].getValue(); + + // Fix broken URL + for(int i=0; i