| 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.CronetEngine; | 10 import org.chromium.net.CronetEngine; |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 public void onReadCompleted( | 432 public void onReadCompleted( |
| 433 UrlRequest request, UrlResponseInfo info, ByteBuffer byteBuffer)
{ | 433 UrlRequest request, UrlResponseInfo info, ByteBuffer byteBuffer)
{ |
| 434 mResponseInfo = info; | 434 mResponseInfo = info; |
| 435 mMessageLoop.quit(); | 435 mMessageLoop.quit(); |
| 436 } | 436 } |
| 437 | 437 |
| 438 @Override | 438 @Override |
| 439 public void onReceivedRedirect( | 439 public void onReceivedRedirect( |
| 440 UrlRequest request, UrlResponseInfo info, String newLocationUrl)
{ | 440 UrlRequest request, UrlResponseInfo info, String newLocationUrl)
{ |
| 441 mOnRedirectCalled = true; | 441 mOnRedirectCalled = true; |
| 442 if (instanceFollowRedirects) { | 442 try { |
| 443 try { | 443 URL newUrl = new URL(newLocationUrl); |
| 444 url = new URL(newLocationUrl); | 444 boolean sameProtocol = newUrl.getProtocol().equals(url.getProtoc
ol()); |
| 445 } catch (MalformedURLException e) { | 445 if (instanceFollowRedirects) { |
| 446 // Ignored. | 446 // Update the url variable even if the redirect will not be |
| 447 // followed due to different protocols. |
| 448 url = newUrl; |
| 447 } | 449 } |
| 448 mRequest.followRedirect(); | 450 if (instanceFollowRedirects && sameProtocol) { |
| 449 } else { | 451 mRequest.followRedirect(); |
| 450 mResponseInfo = info; | 452 return; |
| 451 mRequest.cancel(); | 453 } |
| 452 setResponseDataCompleted(); | 454 } catch (MalformedURLException e) { |
| 455 // Ignored. Just cancel the request and not follow the redirect. |
| 453 } | 456 } |
| 457 mResponseInfo = info; |
| 458 mRequest.cancel(); |
| 459 setResponseDataCompleted(); |
| 454 } | 460 } |
| 455 | 461 |
| 456 @Override | 462 @Override |
| 457 public void onSucceeded(UrlRequest request, UrlResponseInfo info) { | 463 public void onSucceeded(UrlRequest request, UrlResponseInfo info) { |
| 458 mResponseInfo = info; | 464 mResponseInfo = info; |
| 459 setResponseDataCompleted(); | 465 setResponseDataCompleted(); |
| 460 } | 466 } |
| 461 | 467 |
| 462 @Override | 468 @Override |
| 463 public void onFailed( | 469 public void onFailed( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 } | 542 } |
| 537 | 543 |
| 538 /** | 544 /** |
| 539 * Returns whether the client has used {@link #setChunkedStreamingMode} to | 545 * Returns whether the client has used {@link #setChunkedStreamingMode} to |
| 540 * set chunked encoding for upload. | 546 * set chunked encoding for upload. |
| 541 */ | 547 */ |
| 542 private boolean isChunkedUpload() { | 548 private boolean isChunkedUpload() { |
| 543 return chunkLength > 0; | 549 return chunkLength > 0; |
| 544 } | 550 } |
| 545 } | 551 } |
| OLD | NEW |