Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/ChromiumUrlRequest.java

Issue 640593004: Fix a pair of Cronet upload bugs and add tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Placate git Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import android.util.Log; 7 import android.util.Log;
8 8
9 import org.apache.http.conn.ConnectTimeoutException; 9 import org.apache.http.conn.ConnectTimeoutException;
10 import org.chromium.base.CalledByNative; 10 import org.chromium.base.CalledByNative;
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 synchronized (mLock) { 312 synchronized (mLock) {
313 if (mCanceled) { 313 if (mCanceled) {
314 return; 314 return;
315 } 315 }
316 316
317 validateNotStarted(); 317 validateNotStarted();
318 validateNotRecycled(); 318 validateNotRecycled();
319 319
320 mStarted = true; 320 mStarted = true;
321 321
322 String method = mMethod;
323 if (method == null &&
324 ((mUploadData != null && mUploadData.length > 0) ||
325 mUploadChannel != null || mChunkedUpload)) {
326 // Default to POST if there is data to upload but no method was
327 // specified.
328 method = "POST";
329 }
330
331 if (method != null) {
332 nativeSetMethod(mUrlRequestAdapter, method);
333 }
334
335 if (mHeaders != null && !mHeaders.isEmpty()) { 322 if (mHeaders != null && !mHeaders.isEmpty()) {
336 for (Entry<String, String> entry : mHeaders.entrySet()) { 323 for (Entry<String, String> entry : mHeaders.entrySet()) {
337 nativeAddHeader(mUrlRequestAdapter, entry.getKey(), 324 nativeAddHeader(mUrlRequestAdapter, entry.getKey(),
338 entry.getValue()); 325 entry.getValue());
339 } 326 }
340 } 327 }
341 328
342 if (mAdditionalHeaders != null) { 329 if (mAdditionalHeaders != null) {
343 for (Entry<String, String> entry : 330 for (Entry<String, String> entry :
344 mAdditionalHeaders.entrySet()) { 331 mAdditionalHeaders.entrySet()) {
345 nativeAddHeader(mUrlRequestAdapter, entry.getKey(), 332 nativeAddHeader(mUrlRequestAdapter, entry.getKey(),
346 entry.getValue()); 333 entry.getValue());
347 } 334 }
348 } 335 }
349 336
350 if (mUploadData != null && mUploadData.length > 0) { 337 if (mUploadData != null && mUploadData.length > 0) {
351 nativeSetUploadData(mUrlRequestAdapter, mUploadContentType, 338 nativeSetUploadData(mUrlRequestAdapter, mUploadContentType,
352 mUploadData); 339 mUploadData);
353 } else if (mUploadChannel != null) { 340 } else if (mUploadChannel != null) {
354 nativeSetUploadChannel(mUrlRequestAdapter, mUploadContentType, 341 nativeSetUploadChannel(mUrlRequestAdapter, mUploadContentType,
355 mUploadContentLength); 342 mUploadContentLength);
356 } else if (mChunkedUpload) { 343 } else if (mChunkedUpload) {
357 nativeEnableChunkedUpload(mUrlRequestAdapter, 344 nativeEnableChunkedUpload(mUrlRequestAdapter,
358 mUploadContentType); 345 mUploadContentType);
359 } 346 }
360 347
348 // Note: The above functions to set the upload body also set the
349 // method to POST, behind the scenes, so if mMethod is null but
350 // there's an upload body, the method will default to POST.
351 if (mMethod != null) {
mef 2014/10/17 20:47:27 good catch!
mmenke 2014/10/17 21:27:15 Only caught it when I was writing tests for it. T
352 nativeSetMethod(mUrlRequestAdapter, mMethod);
353 }
354
361 nativeStart(mUrlRequestAdapter); 355 nativeStart(mUrlRequestAdapter);
362 } 356 }
363 } 357 }
364 358
365 @Override 359 @Override
366 public void cancel() { 360 public void cancel() {
367 synchronized (mLock) { 361 synchronized (mLock) {
368 if (mCanceled) { 362 if (mCanceled) {
369 return; 363 return;
370 } 364 }
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 693
700 private native void nativeGetAllHeaders(long urlRequestAdapter, 694 private native void nativeGetAllHeaders(long urlRequestAdapter,
701 ResponseHeadersMap headers); 695 ResponseHeadersMap headers);
702 696
703 private native String nativeGetNegotiatedProtocol(long urlRequestAdapter); 697 private native String nativeGetNegotiatedProtocol(long urlRequestAdapter);
704 698
705 // Explicit class to work around JNI-generator generics confusion. 699 // Explicit class to work around JNI-generator generics confusion.
706 private class ResponseHeadersMap extends HashMap<String, List<String>> { 700 private class ResponseHeadersMap extends HashMap<String, List<String>> {
707 } 701 }
708 } 702 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698