From 22205d92f2c31246c19c7d6ded5b75c189fabf87 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Wed, 2 Dec 2015 16:24:55 +0000 Subject: Workaround for HttpURLConnection.getFollowRedirects() on M HttpURLConnection.setFollowRedirects() has no effect on M due to a bug. This should be safe / a no-op on other releases. Bug: https://code.google.com/p/android/issues/detail?id=194495 Change-Id: Ie97861eba0560b63504662baa908f6a5856f68aa --- src/main/java/com/android/volley/toolbox/HurlStack.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/android/volley/toolbox/HurlStack.java b/src/main/java/com/android/volley/toolbox/HurlStack.java index 1be202e..c53d5e0 100644 --- a/src/main/java/com/android/volley/toolbox/HurlStack.java +++ b/src/main/java/com/android/volley/toolbox/HurlStack.java @@ -166,7 +166,14 @@ public class HurlStack implements HttpStack { * Create an {@link HttpURLConnection} for the specified {@code url}. */ protected HttpURLConnection createConnection(URL url) throws IOException { - return (HttpURLConnection) url.openConnection(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + + // Workaround for the M release HttpURLConnection not observing the + // HttpURLConnection.setFollowRedirects() property. + // https://code.google.com/p/android/issues/detail?id=194495 + connection.setInstanceFollowRedirects(HttpURLConnection.getFollowRedirects()); + + return connection; } /** -- cgit v1.2.3