Chromium Code Reviews| 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; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.text.TextUtils; | 8 import android.text.TextUtils; |
| 9 | 9 |
| 10 import org.apache.http.HttpStatus; | 10 import org.apache.http.HttpStatus; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 | 214 |
| 215 mHttpStatusCode = mConnection.getResponseCode(); | 215 mHttpStatusCode = mConnection.getResponseCode(); |
| 216 mContentType = mConnection.getContentType(); | 216 mContentType = mConnection.getContentType(); |
| 217 mContentLength = mConnection.getContentLength(); | 217 mContentLength = mConnection.getContentLength(); |
| 218 if (mContentLengthLimit > 0 && mContentLength > mContentLengthLimit | 218 if (mContentLengthLimit > 0 && mContentLength > mContentLengthLimit |
| 219 && mCancelIfContentLengthOverLimit) { | 219 && mCancelIfContentLengthOverLimit) { |
| 220 onContentLengthOverLimit(); | 220 onContentLengthOverLimit(); |
| 221 return; | 221 return; |
| 222 } | 222 } |
| 223 | 223 |
| 224 mListener.onResponseStarted(this); | |
| 225 | |
| 226 | |
|
mmenke
2014/05/09 16:41:40
nit: Remove extra blank line.
mef
2014/05/09 18:49:16
Done.
| |
| 224 mResponseStream = isError(mHttpStatusCode) ? mConnection | 227 mResponseStream = isError(mHttpStatusCode) ? mConnection |
| 225 .getErrorStream() | 228 .getErrorStream() |
| 226 : stream; | 229 : stream; |
| 227 | 230 |
| 228 if (mResponseStream != null | 231 if (mResponseStream != null |
| 229 && "gzip".equals(mConnection.getContentEncoding())) { | 232 && "gzip".equals(mConnection.getContentEncoding())) { |
| 230 mResponseStream = new GZIPInputStream(mResponseStream); | 233 mResponseStream = new GZIPInputStream(mResponseStream); |
| 231 mContentLength = -1; | 234 mContentLength = -1; |
| 232 } | 235 } |
| 233 | 236 |
| 234 if (mOffset != 0) { | 237 if (mOffset != 0) { |
| 235 // The server may ignore the request for a byte range. | 238 // The server may ignore the request for a byte range. |
| 236 if (mHttpStatusCode == HttpStatus.SC_OK) { | 239 if (mHttpStatusCode == HttpStatus.SC_OK) { |
| 237 if (mContentLength != -1) { | 240 if (mContentLength != -1) { |
| 238 mContentLength -= mOffset; | 241 mContentLength -= mOffset; |
| 239 } | 242 } |
| 240 mSkippingToOffset = true; | 243 mSkippingToOffset = true; |
| 241 } else { | 244 } else { |
| 242 mSize = mOffset; | 245 mSize = mOffset; |
| 243 } | 246 } |
| 244 } | 247 } |
| 245 | 248 |
| 246 if (mResponseStream != null) { | 249 if (mResponseStream != null) { |
| 247 readingResponse = true; | 250 readingResponse = true; |
| 248 readResponseAsync(); | 251 readResponseAsync(); |
| 249 } | 252 } |
| 250 } catch (IOException e) { | 253 } catch (IOException e) { |
| 251 mException = e; | 254 mException = e; |
| 252 } finally { | 255 } finally { |
| 256 if (mPostDataChannel != null) { | |
| 257 try { | |
| 258 mPostDataChannel.close(); | |
| 259 } catch (IOException e) { | |
| 260 // Ignore | |
| 261 } | |
| 262 } | |
| 263 | |
| 253 // Don't call onRequestComplete yet if we are reading the response | 264 // Don't call onRequestComplete yet if we are reading the response |
| 254 // on a separate thread | 265 // on a separate thread |
| 255 if (!readingResponse) { | 266 if (!readingResponse) { |
| 256 mListener.onRequestComplete(this); | 267 mListener.onRequestComplete(this); |
| 257 } | 268 } |
| 258 } | 269 } |
| 259 } | 270 } |
| 260 | 271 |
| 261 private void uploadData() throws IOException { | 272 private void uploadData() throws IOException { |
| 262 mConnection.setDoOutput(true); | 273 mConnection.setDoOutput(true); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 @Override | 429 @Override |
| 419 public long getContentLength() { | 430 public long getContentLength() { |
| 420 return mContentLength; | 431 return mContentLength; |
| 421 } | 432 } |
| 422 | 433 |
| 423 @Override | 434 @Override |
| 424 public String getContentType() { | 435 public String getContentType() { |
| 425 return mContentType; | 436 return mContentType; |
| 426 } | 437 } |
| 427 | 438 |
| 439 | |
| 440 @Override | |
| 441 public String getHeader(String name) { | |
| 442 if (mConnection == null) { | |
| 443 throw new IllegalStateException("Response headers not available"); | |
| 444 } | |
| 445 return mConnection.getHeaderField(name); | |
| 446 } | |
| 447 | |
| 428 private void validateNotStarted() { | 448 private void validateNotStarted() { |
| 429 if (mStarted) { | 449 if (mStarted) { |
| 430 throw new IllegalStateException("Request already started"); | 450 throw new IllegalStateException("Request already started"); |
| 431 } | 451 } |
| 432 } | 452 } |
| 433 } | 453 } |
| OLD | NEW |