OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // The close queue handles graceful closing of HTTP connections. When | 5 // The close queue handles graceful closing of HTTP connections. When |
6 // a connection is added to the queue it will enter a wait state | 6 // a connection is added to the queue it will enter a wait state |
7 // waiting for all data written and possibly socket shutdown from | 7 // waiting for all data written and possibly socket shutdown from |
8 // peer. | 8 // peer. |
9 class _CloseQueue { | 9 class _CloseQueue { |
10 _CloseQueue() : _q = new Set<_HttpConnectionBase>(); | 10 _CloseQueue() : _q = new Set<_HttpConnectionBase>(); |
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 extends _HttpRequestResponseBase implements HttpClientResponse { | 1279 extends _HttpRequestResponseBase implements HttpClientResponse { |
1280 _HttpClientResponse(_HttpClientConnection connection) | 1280 _HttpClientResponse(_HttpClientConnection connection) |
1281 : super(connection) { | 1281 : super(connection) { |
1282 _connection = connection; | 1282 _connection = connection; |
1283 } | 1283 } |
1284 | 1284 |
1285 int get statusCode => _statusCode; | 1285 int get statusCode => _statusCode; |
1286 String get reasonPhrase => _reasonPhrase; | 1286 String get reasonPhrase => _reasonPhrase; |
1287 | 1287 |
1288 bool get isRedirect { | 1288 bool get isRedirect { |
1289 return statusCode == HttpStatus.MOVED_PERMANENTLY || | 1289 var method = _connection._request._method; |
1290 statusCode == HttpStatus.FOUND || | 1290 if (method == "GET" || method == "HEAD") { |
1291 statusCode == HttpStatus.SEE_OTHER || | 1291 return statusCode == HttpStatus.MOVED_PERMANENTLY || |
1292 statusCode == HttpStatus.TEMPORARY_REDIRECT; | 1292 statusCode == HttpStatus.FOUND || |
| 1293 statusCode == HttpStatus.SEE_OTHER || |
| 1294 statusCode == HttpStatus.TEMPORARY_REDIRECT; |
| 1295 } else if (method == "POST") { |
| 1296 return statusCode == HttpStatus.SEE_OTHER; |
| 1297 } |
| 1298 return false; |
1293 } | 1299 } |
1294 | 1300 |
1295 List<Cookie> get cookies { | 1301 List<Cookie> get cookies { |
1296 if (_cookies != null) return _cookies; | 1302 if (_cookies != null) return _cookies; |
1297 _cookies = new List<Cookie>(); | 1303 _cookies = new List<Cookie>(); |
1298 List<String> values = _headers["set-cookie"]; | 1304 List<String> values = _headers["set-cookie"]; |
1299 if (values != null) { | 1305 if (values != null) { |
1300 values.forEach((value) { | 1306 values.forEach((value) { |
1301 _cookies.add(new Cookie.fromSetCookieValue(value)); | 1307 _cookies.add(new Cookie.fromSetCookieValue(value)); |
1302 }); | 1308 }); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1339 Uri redirectUrl = new Uri.fromString(location[0]); | 1345 Uri redirectUrl = new Uri.fromString(location[0]); |
1340 for (int i = 0; i < _connection._redirects.length; i++) { | 1346 for (int i = 0; i < _connection._redirects.length; i++) { |
1341 if (_connection._redirects[i].location.toString() == | 1347 if (_connection._redirects[i].location.toString() == |
1342 redirectUrl.toString()) { | 1348 redirectUrl.toString()) { |
1343 throw new RedirectLoopException(_connection._redirects); | 1349 throw new RedirectLoopException(_connection._redirects); |
1344 } | 1350 } |
1345 } | 1351 } |
1346 } | 1352 } |
1347 // Drain body and redirect. | 1353 // Drain body and redirect. |
1348 inputStream.onData = inputStream.read; | 1354 inputStream.onData = inputStream.read; |
1349 _connection.redirect(); | 1355 if (_statusCode == HttpStatus.SEE_OTHER && |
| 1356 _connection._method == "POST") { |
| 1357 _connection.redirect("GET"); |
| 1358 } else { |
| 1359 _connection.redirect(); |
| 1360 } |
1350 } else { | 1361 } else { |
1351 throw new RedirectLimitExceededException(_connection._redirects); | 1362 throw new RedirectLimitExceededException(_connection._redirects); |
1352 } | 1363 } |
1353 } else if (statusCode == HttpStatus.UNAUTHORIZED) { | 1364 } else if (statusCode == HttpStatus.UNAUTHORIZED) { |
1354 _handleUnauthorized(); | 1365 _handleUnauthorized(); |
1355 } else if (_connection._onResponse != null) { | 1366 } else if (_connection._onResponse != null) { |
1356 _connection._onResponse(this); | 1367 _connection._onResponse(this); |
1357 } | 1368 } |
1358 } | 1369 } |
1359 | 1370 |
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2278 | 2289 |
2279 | 2290 |
2280 class _RedirectInfo implements RedirectInfo { | 2291 class _RedirectInfo implements RedirectInfo { |
2281 const _RedirectInfo(int this.statusCode, | 2292 const _RedirectInfo(int this.statusCode, |
2282 String this.method, | 2293 String this.method, |
2283 Uri this.location); | 2294 Uri this.location); |
2284 final int statusCode; | 2295 final int statusCode; |
2285 final String method; | 2296 final String method; |
2286 final Uri location; | 2297 final Uri location; |
2287 } | 2298 } |
OLD | NEW |