From eb462f034584e83da60814ea1550a4cf157ae3d3 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Fri, 29 Aug 2014 10:36:17 -0500 Subject: [PATCH] force redirects, get inputstream first --- src/org/thoughtcrime/securesms/mms/MmsCommunication.java | 1 + src/org/thoughtcrime/securesms/mms/MmsDownloadHelper.java | 6 ++++-- src/org/thoughtcrime/securesms/mms/MmsSendHelper.java | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/org/thoughtcrime/securesms/mms/MmsCommunication.java b/src/org/thoughtcrime/securesms/mms/MmsCommunication.java index b629e383a1..1ca2ae9253 100644 --- a/src/org/thoughtcrime/securesms/mms/MmsCommunication.java +++ b/src/org/thoughtcrime/securesms/mms/MmsCommunication.java @@ -180,6 +180,7 @@ public class MmsCommunication { urlConnection = (HttpURLConnection) url.openConnection(); } + urlConnection.setInstanceFollowRedirects(true); urlConnection.setConnectTimeout(20*1000); urlConnection.setReadTimeout(20*1000); urlConnection.setUseCaches(false); diff --git a/src/org/thoughtcrime/securesms/mms/MmsDownloadHelper.java b/src/org/thoughtcrime/securesms/mms/MmsDownloadHelper.java index dbcdc0eb5e..c2ad7e9bf5 100644 --- a/src/org/thoughtcrime/securesms/mms/MmsDownloadHelper.java +++ b/src/org/thoughtcrime/securesms/mms/MmsDownloadHelper.java @@ -21,6 +21,7 @@ import android.net.Uri; import android.util.Log; import java.io.IOException; +import java.io.InputStream; import java.net.HttpURLConnection; import ws.com.google.android.mms.pdu.PduParser; @@ -44,7 +45,8 @@ public class MmsDownloadHelper extends MmsCommunication { Log.w(TAG, "Connecting to " + url); client.connect(); - int responseCode = client.getResponseCode(); + final InputStream is = client.getInputStream(); + final int responseCode = client.getResponseCode(); Log.w(TAG, "Response code: " + responseCode + "/" + client.getResponseMessage()); @@ -52,7 +54,7 @@ public class MmsDownloadHelper extends MmsCommunication { throw new IOException("non-200 response"); } - return parseResponse(client.getInputStream()); + return parseResponse(is); } finally { if (client != null) client.disconnect(); } diff --git a/src/org/thoughtcrime/securesms/mms/MmsSendHelper.java b/src/org/thoughtcrime/securesms/mms/MmsSendHelper.java index 397553c01a..eeb78ad8c1 100644 --- a/src/org/thoughtcrime/securesms/mms/MmsSendHelper.java +++ b/src/org/thoughtcrime/securesms/mms/MmsSendHelper.java @@ -66,7 +66,8 @@ public class MmsSendHelper extends MmsCommunication { Log.w(TAG, "Payload sent"); - int responseCode = client.getResponseCode(); + final InputStream is = client.getInputStream(); + final int responseCode = client.getResponseCode(); Log.w(TAG, "Response code: " + responseCode + "/" + client.getResponseMessage()); @@ -74,7 +75,7 @@ public class MmsSendHelper extends MmsCommunication { throw new IOException("non-200 response"); } - return parseResponse(client.getInputStream()); + return parseResponse(is); } finally { if (client != null) client.disconnect(); }