Merge pull request #1446 from mfietz/issue/1445-relative-location
Handle redirects with relative URL correctly
This commit is contained in:
commit
c940589bbd
|
@ -15,6 +15,7 @@ import java.net.CookiePolicy;
|
|||
import java.net.HttpURLConnection;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -71,6 +72,17 @@ public class AntennapodHttpClient {
|
|||
if(response.code() == HttpURLConnection.HTTP_MOVED_PERM ||
|
||||
response.code() == StatusLine.HTTP_PERM_REDIRECT) {
|
||||
String location = response.header("Location");
|
||||
if(location.startsWith("/")) { // URL is not absolute, but relative
|
||||
URL url = request.url();
|
||||
location = url.getProtocol() + "://" + url.getHost() + location;
|
||||
} else if(!location.startsWith("http://") && !location.startsWith("https://")) {
|
||||
// Reference is relative to current path
|
||||
URL url = request.url();
|
||||
String path = url.getPath();
|
||||
String newPath = path.substring(0, path.lastIndexOf("/") + 1) + location;
|
||||
location = url.getProtocol() + "://" + url.getHost() + newPath;
|
||||
}
|
||||
Log.d(TAG, "New location: " + location);
|
||||
try {
|
||||
DBWriter.updateFeedDownloadURL(request.urlString(), location).get();
|
||||
} catch (Exception e) {
|
||||
|
|
Loading…
Reference in New Issue