mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
Fix broken file upload in mobile-spec tests (CB-1290).
The explicit transfer-encoding: chunk that was added breaks in
fixed-length streaming mode. It is, however, still required to
work-around an OOM bug in HTTPS mode. The new logic works for both the
mobile-spec and the HTTPS large-file test that I used before.
Commit adding the header: 999c548e6e
This commit is contained in:
parent
f7ae7fe43a
commit
c3e17fb185
@ -146,9 +146,9 @@ public class FileTransfer extends Plugin {
|
||||
//------------------ CLIENT REQUEST
|
||||
// open a URL connection to the server
|
||||
URL url = new URL(target);
|
||||
|
||||
boolean useHttps = url.getProtocol().toLowerCase().equals("https");
|
||||
// Open a HTTP connection to the URL based on protocol
|
||||
if (url.getProtocol().toLowerCase().equals("https")) {
|
||||
if (useHttps) {
|
||||
// Using standard HTTPS connection. Will not allow self signed certificate
|
||||
if (!trustEveryone) {
|
||||
conn = (HttpsURLConnection) url.openConnection();
|
||||
@ -246,12 +246,17 @@ public class FileTransfer extends Plugin {
|
||||
Log.d(LOG_TAG, "Content Length: " + fixedLength);
|
||||
// setFixedLengthStreamingMode causes and OutOfMemoryException on pre-Froyo devices.
|
||||
// http://code.google.com/p/android/issues/detail?id=3164
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO && chunkedMode) {
|
||||
// It also causes OOM if HTTPS is used, even on newer devices.
|
||||
chunkedMode = chunkedMode && (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO || useHttps);
|
||||
|
||||
if (chunkedMode) {
|
||||
conn.setChunkedStreamingMode(maxBufferSize);
|
||||
// Although setChunkedStreamingMode sets this header, setting it explicitly here works
|
||||
// around an OutOfMemoryException when using https.
|
||||
conn.setRequestProperty("Transfer-Encoding", "chunked");
|
||||
} else {
|
||||
conn.setFixedLengthStreamingMode(fixedLength);
|
||||
}
|
||||
conn.setRequestProperty("Transfer-Encoding", "chunked");
|
||||
|
||||
dos = new DataOutputStream( conn.getOutputStream() );
|
||||
//We don't want to change encoding, we just want this to write for all Unicode.
|
||||
|
Loading…
Reference in New Issue
Block a user