Merge pull request #1887 from mcginty/mms-3xx

allow url client to follow redirects before checking response code
This commit is contained in:
Moxie Marlinspike 2014-08-29 15:23:00 -07:00
commit 877f2a25a9
3 changed files with 8 additions and 4 deletions

View File

@ -180,6 +180,7 @@ public class MmsCommunication {
urlConnection = (HttpURLConnection) url.openConnection(); urlConnection = (HttpURLConnection) url.openConnection();
} }
urlConnection.setInstanceFollowRedirects(true);
urlConnection.setConnectTimeout(20*1000); urlConnection.setConnectTimeout(20*1000);
urlConnection.setReadTimeout(20*1000); urlConnection.setReadTimeout(20*1000);
urlConnection.setUseCaches(false); urlConnection.setUseCaches(false);

View File

@ -21,6 +21,7 @@ import android.net.Uri;
import android.util.Log; import android.util.Log;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.util.Arrays; import java.util.Arrays;
@ -45,7 +46,8 @@ public class MmsDownloadHelper extends MmsCommunication {
Log.w(TAG, "Connecting to " + url); Log.w(TAG, "Connecting to " + url);
client.connect(); client.connect();
int responseCode = client.getResponseCode(); final InputStream is = client.getInputStream();
final int responseCode = client.getResponseCode();
Log.w(TAG, "Response code: " + responseCode + "/" + client.getResponseMessage()); Log.w(TAG, "Response code: " + responseCode + "/" + client.getResponseMessage());
@ -53,7 +55,7 @@ public class MmsDownloadHelper extends MmsCommunication {
throw new IOException("non-200 response"); throw new IOException("non-200 response");
} }
return parseResponse(client.getInputStream()); return parseResponse(is);
} finally { } finally {
if (client != null) client.disconnect(); if (client != null) client.disconnect();
} }

View File

@ -66,7 +66,8 @@ public class MmsSendHelper extends MmsCommunication {
Log.w(TAG, "Payload sent"); 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()); Log.w(TAG, "Response code: " + responseCode + "/" + client.getResponseMessage());
@ -74,7 +75,7 @@ public class MmsSendHelper extends MmsCommunication {
throw new IOException("non-200 response"); throw new IOException("non-200 response");
} }
return parseResponse(client.getInputStream()); return parseResponse(is);
} finally { } finally {
if (client != null) client.disconnect(); if (client != null) client.disconnect();
} }