| OLD | NEW |
| 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.urlconnection; | 5 package org.chromium.net.urlconnection; |
| 6 | 6 |
| 7 import android.util.Pair; | 7 import android.util.Pair; |
| 8 | 8 |
| 9 import org.chromium.base.Log; | 9 import org.chromium.base.Log; |
| 10 import org.chromium.net.ExtendedResponseInfo; | 10 import org.chromium.net.ExtendedResponseInfo; |
| 11 import org.chromium.net.ResponseInfo; | 11 import org.chromium.net.ResponseInfo; |
| 12 import org.chromium.net.UploadDataProvider; | |
| 13 import org.chromium.net.UrlRequest; | 12 import org.chromium.net.UrlRequest; |
| 14 import org.chromium.net.UrlRequestContext; | 13 import org.chromium.net.UrlRequestContext; |
| 15 import org.chromium.net.UrlRequestException; | 14 import org.chromium.net.UrlRequestException; |
| 16 import org.chromium.net.UrlRequestListener; | 15 import org.chromium.net.UrlRequestListener; |
| 17 | 16 |
| 18 import java.io.FileNotFoundException; | 17 import java.io.FileNotFoundException; |
| 19 import java.io.IOException; | 18 import java.io.IOException; |
| 20 import java.io.InputStream; | 19 import java.io.InputStream; |
| 21 import java.io.OutputStream; | 20 import java.io.OutputStream; |
| 22 import java.net.HttpURLConnection; | 21 import java.net.HttpURLConnection; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 | 250 |
| 252 /** | 251 /** |
| 253 * Starts the request if {@code connected} is false. | 252 * Starts the request if {@code connected} is false. |
| 254 */ | 253 */ |
| 255 private void startRequest() throws IOException { | 254 private void startRequest() throws IOException { |
| 256 if (connected) { | 255 if (connected) { |
| 257 return; | 256 return; |
| 258 } | 257 } |
| 259 if (doOutput) { | 258 if (doOutput) { |
| 260 if (mOutputStream != null) { | 259 if (mOutputStream != null) { |
| 261 mRequest.setUploadDataProvider( | 260 mRequest.setUploadDataProvider(mOutputStream.getUploadDataProvid
er(), mMessageLoop); |
| 262 (UploadDataProvider) mOutputStream, mMessageLoop); | |
| 263 if (getRequestProperty(CONTENT_LENGTH) == null && !isChunkedUplo
ad()) { | 261 if (getRequestProperty(CONTENT_LENGTH) == null && !isChunkedUplo
ad()) { |
| 264 addRequestProperty(CONTENT_LENGTH, | 262 addRequestProperty(CONTENT_LENGTH, |
| 265 Long.toString(((UploadDataProvider) mOutputStream).g
etLength())); | 263 Long.toString(mOutputStream.getUploadDataProvider().
getLength())); |
| 266 } | 264 } |
| 267 // Tells mOutputStream that startRequest() has been called, so | 265 // Tells mOutputStream that startRequest() has been called, so |
| 268 // the underlying implementation can prepare for reading if need
ed. | 266 // the underlying implementation can prepare for reading if need
ed. |
| 269 mOutputStream.setConnected(); | 267 mOutputStream.setConnected(); |
| 270 } else { | 268 } else { |
| 271 if (getRequestProperty(CONTENT_LENGTH) == null) { | 269 if (getRequestProperty(CONTENT_LENGTH) == null) { |
| 272 addRequestProperty(CONTENT_LENGTH, "0"); | 270 addRequestProperty(CONTENT_LENGTH, "0"); |
| 273 } | 271 } |
| 274 } | 272 } |
| 275 // Default Content-Type to application/x-www-form-urlencoded | 273 // Default Content-Type to application/x-www-form-urlencoded |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 private int findRequestProperty(String key) { | 409 private int findRequestProperty(String key) { |
| 412 for (int i = 0; i < mRequestHeaders.size(); i++) { | 410 for (int i = 0; i < mRequestHeaders.size(); i++) { |
| 413 Pair<String, String> entry = mRequestHeaders.get(i); | 411 Pair<String, String> entry = mRequestHeaders.get(i); |
| 414 if (entry.first.equalsIgnoreCase(key)) { | 412 if (entry.first.equalsIgnoreCase(key)) { |
| 415 return i; | 413 return i; |
| 416 } | 414 } |
| 417 } | 415 } |
| 418 return -1; | 416 return -1; |
| 419 } | 417 } |
| 420 | 418 |
| 421 private class CronetUrlRequestListener implements UrlRequestListener { | 419 private class CronetUrlRequestListener extends UrlRequestListener { |
| 422 public CronetUrlRequestListener() { | 420 public CronetUrlRequestListener() { |
| 423 } | 421 } |
| 424 | 422 |
| 425 @Override | 423 @Override |
| 426 public void onResponseStarted(UrlRequest request, ResponseInfo info) { | 424 public void onResponseStarted(UrlRequest request, ResponseInfo info) { |
| 427 mResponseInfo = info; | 425 mResponseInfo = info; |
| 428 // Quits the message loop since we have the headers now. | 426 // Quits the message loop since we have the headers now. |
| 429 mMessageLoop.quit(); | 427 mMessageLoop.quit(); |
| 430 } | 428 } |
| 431 | 429 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 } | 536 } |
| 539 | 537 |
| 540 /** | 538 /** |
| 541 * Returns whether the client has used {@link #setChunkedStreamingMode} to | 539 * Returns whether the client has used {@link #setChunkedStreamingMode} to |
| 542 * set chunked encoding for upload. | 540 * set chunked encoding for upload. |
| 543 */ | 541 */ |
| 544 private boolean isChunkedUpload() { | 542 private boolean isChunkedUpload() { |
| 545 return chunkLength > 0; | 543 return chunkLength > 0; |
| 546 } | 544 } |
| 547 } | 545 } |
| OLD | NEW |