| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 // The close queue handles graceful closing of HTTP connections. When | 7 // The close queue handles graceful closing of HTTP connections. When |
| 8 // a connection is added to the queue it will enter a wait state | 8 // a connection is added to the queue it will enter a wait state |
| 9 // waiting for all data written and possibly socket shutdown from | 9 // waiting for all data written and possibly socket shutdown from |
| 10 // peer. | 10 // peer. |
| (...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 if (_connection._redirects == null || | 1343 if (_connection._redirects == null || |
| 1344 _connection._redirects.length < _connection.maxRedirects) { | 1344 _connection._redirects.length < _connection.maxRedirects) { |
| 1345 // Check the location header. | 1345 // Check the location header. |
| 1346 List<String> location = headers[HttpHeaders.LOCATION]; | 1346 List<String> location = headers[HttpHeaders.LOCATION]; |
| 1347 if (location == null || location.length > 1) { | 1347 if (location == null || location.length > 1) { |
| 1348 throw new RedirectException("Invalid redirect", | 1348 throw new RedirectException("Invalid redirect", |
| 1349 _connection._redirects); | 1349 _connection._redirects); |
| 1350 } | 1350 } |
| 1351 // Check for redirect loop | 1351 // Check for redirect loop |
| 1352 if (_connection._redirects != null) { | 1352 if (_connection._redirects != null) { |
| 1353 Uri redirectUrl = new Uri.fromString(location[0]); | 1353 Uri redirectUrl = Uri.parse(location[0]); |
| 1354 for (int i = 0; i < _connection._redirects.length; i++) { | 1354 for (int i = 0; i < _connection._redirects.length; i++) { |
| 1355 if (_connection._redirects[i].location.toString() == | 1355 if (_connection._redirects[i].location.toString() == |
| 1356 redirectUrl.toString()) { | 1356 redirectUrl.toString()) { |
| 1357 throw new RedirectLoopException(_connection._redirects); | 1357 throw new RedirectLoopException(_connection._redirects); |
| 1358 } | 1358 } |
| 1359 } | 1359 } |
| 1360 } | 1360 } |
| 1361 // Drain body and redirect. | 1361 // Drain body and redirect. |
| 1362 inputStream.onData = inputStream.read; | 1362 inputStream.onData = inputStream.read; |
| 1363 if (_statusCode == HttpStatus.SEE_OTHER && | 1363 if (_statusCode == HttpStatus.SEE_OTHER && |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 if (_redirects == null) { | 1695 if (_redirects == null) { |
| 1696 _redirects = new List<_RedirectInfo>(); | 1696 _redirects = new List<_RedirectInfo>(); |
| 1697 } | 1697 } |
| 1698 _redirects.add(redirect); | 1698 _redirects.add(redirect); |
| 1699 _doRetry(redirect); | 1699 _doRetry(redirect); |
| 1700 } | 1700 } |
| 1701 | 1701 |
| 1702 void redirect([String method, Uri url]) { | 1702 void redirect([String method, Uri url]) { |
| 1703 if (method == null) method = _method; | 1703 if (method == null) method = _method; |
| 1704 if (url == null) { | 1704 if (url == null) { |
| 1705 url = new Uri.fromString(_response.headers.value(HttpHeaders.LOCATION)); | 1705 url = Uri.parse(_response.headers.value(HttpHeaders.LOCATION)); |
| 1706 } | 1706 } |
| 1707 // Always set the content length to 0 for redirects. | 1707 // Always set the content length to 0 for redirects. |
| 1708 var mutable = _request._headers._mutable; | 1708 var mutable = _request._headers._mutable; |
| 1709 _request._headers._mutable = true; | 1709 _request._headers._mutable = true; |
| 1710 _request._headers.contentLength = 0; | 1710 _request._headers.contentLength = 0; |
| 1711 _request._headers._mutable = mutable; | 1711 _request._headers._mutable = mutable; |
| 1712 _request._bodyBytesWritten = 0; | 1712 _request._bodyBytesWritten = 0; |
| 1713 var redirect = new _RedirectInfo(_response.statusCode, method, url); | 1713 var redirect = new _RedirectInfo(_response.statusCode, method, url); |
| 1714 // The actual redirect is postponed until both response and | 1714 // The actual redirect is postponed until both response and |
| 1715 // request are done. | 1715 // request are done. |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2322 | 2322 |
| 2323 | 2323 |
| 2324 class _RedirectInfo implements RedirectInfo { | 2324 class _RedirectInfo implements RedirectInfo { |
| 2325 const _RedirectInfo(int this.statusCode, | 2325 const _RedirectInfo(int this.statusCode, |
| 2326 String this.method, | 2326 String this.method, |
| 2327 Uri this.location); | 2327 Uri this.location); |
| 2328 final int statusCode; | 2328 final int statusCode; |
| 2329 final String method; | 2329 final String method; |
| 2330 final Uri location; | 2330 final Uri location; |
| 2331 } | 2331 } |
| OLD | NEW |