| Index: components/cronet/android/java/src/org/chromium/net/HttpUrlConnectionUrlRequest.java
|
| diff --git a/components/cronet/android/java/src/org/chromium/net/HttpUrlConnectionUrlRequest.java b/components/cronet/android/java/src/org/chromium/net/HttpUrlConnectionUrlRequest.java
|
| index e815812d1eb277068ec492a47b1d65bafee46a7d..33c940cbd682e0ffdc81efd686edb98845f25a76 100644
|
| --- a/components/cronet/android/java/src/org/chromium/net/HttpUrlConnectionUrlRequest.java
|
| +++ b/components/cronet/android/java/src/org/chromium/net/HttpUrlConnectionUrlRequest.java
|
| @@ -14,10 +14,12 @@ import java.io.IOException;
|
| import java.io.InputStream;
|
| import java.io.OutputStream;
|
| import java.net.HttpURLConnection;
|
| +import java.net.ProtocolException;
|
| import java.net.URL;
|
| import java.nio.ByteBuffer;
|
| import java.nio.channels.ReadableByteChannel;
|
| import java.nio.channels.WritableByteChannel;
|
| +import java.util.List;
|
| import java.util.Map;
|
| import java.util.Map.Entry;
|
| import java.util.concurrent.ExecutorService;
|
| @@ -55,6 +57,8 @@ class HttpUrlConnectionUrlRequest implements HttpUrlRequest {
|
|
|
| private int mContentLength;
|
|
|
| + private int mUploadContentLength;
|
| +
|
| private long mContentLengthLimit;
|
|
|
| private boolean mCancelIfContentLengthOverLimit;
|
| @@ -79,6 +83,8 @@ class HttpUrlConnectionUrlRequest implements HttpUrlRequest {
|
|
|
| private boolean mCanceled;
|
|
|
| + private String mMethod;
|
| +
|
| private InputStream mResponseStream;
|
|
|
| private final Object mLock;
|
| @@ -162,11 +168,27 @@ class HttpUrlConnectionUrlRequest implements HttpUrlRequest {
|
| public void setUploadChannel(String contentType,
|
| ReadableByteChannel channel, long contentLength) {
|
| validateNotStarted();
|
| + if (contentLength > Integer.MAX_VALUE) {
|
| + throw new IllegalArgumentException(
|
| + "Upload contentLength is too big.");
|
| + }
|
| + mUploadContentLength = (int)contentLength;
|
| mPostContentType = contentType;
|
| mPostDataChannel = channel;
|
| mPostData = null;
|
| }
|
|
|
| +
|
| + @Override
|
| + public void setHttpMethod(String method) {
|
| + validateNotStarted();
|
| + if (!("PUT".equals(method) || "POST".equals(method))) {
|
| + throw new IllegalArgumentException(
|
| + "Only PUT and POST are allowed.");
|
| + }
|
| + mMethod = method;
|
| + }
|
| +
|
| @Override
|
| public void start() {
|
| getExecutor().execute(new Runnable() {
|
| @@ -188,6 +210,16 @@ class HttpUrlConnectionUrlRequest implements HttpUrlRequest {
|
|
|
| URL url = new URL(mUrl);
|
| mConnection = (HttpURLConnection)url.openConnection();
|
| + // If configured, use the provided http verb.
|
| + if (mMethod != null) {
|
| + try {
|
| + mConnection.setRequestMethod(mMethod);
|
| + } catch (ProtocolException e) {
|
| + // Since request hasn't started earlier, it
|
| + // must be an illegal HTTP verb.
|
| + throw new IllegalArgumentException(e);
|
| + }
|
| + }
|
| mConnection.setConnectTimeout(CONNECT_TIMEOUT);
|
| mConnection.setReadTimeout(READ_TIMEOUT);
|
| mConnection.setInstanceFollowRedirects(true);
|
| @@ -290,7 +322,7 @@ class HttpUrlConnectionUrlRequest implements HttpUrlRequest {
|
| uploadStream = mConnection.getOutputStream();
|
| uploadStream.write(mPostData);
|
| } else {
|
| - mConnection.setChunkedStreamingMode(MAX_CHUNK_SIZE);
|
| + mConnection.setFixedLengthStreamingMode(mUploadContentLength);
|
| uploadStream = mConnection.getOutputStream();
|
| byte[] bytes = new byte[MAX_CHUNK_SIZE];
|
| ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
|
| @@ -450,7 +482,14 @@ class HttpUrlConnectionUrlRequest implements HttpUrlRequest {
|
| if (mConnection == null) {
|
| throw new IllegalStateException("Response headers not available");
|
| }
|
| - return mConnection.getHeaderField(name);
|
| + Map<String, List<String>> headerFields = mConnection.getHeaderFields();
|
| + if (headerFields != null) {
|
| + List<String> headerValues = headerFields.get(name);
|
| + if (headerValues != null) {
|
| + return TextUtils.join(", ", headerValues);
|
| + }
|
| + }
|
| + return null;
|
| }
|
|
|
| private void validateNotStarted() {
|
|
|