OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 case ERR_CONNECTION_CLOSED: | 1436 case ERR_CONNECTION_CLOSED: |
1437 case ERR_CONNECTION_ABORTED: | 1437 case ERR_CONNECTION_ABORTED: |
1438 // There can be a race between the socket pool checking checking whether a | 1438 // There can be a race between the socket pool checking checking whether a |
1439 // socket is still connected, receiving the FIN, and sending/reading data | 1439 // socket is still connected, receiving the FIN, and sending/reading data |
1440 // on a reused socket. If we receive the FIN between the connectedness | 1440 // on a reused socket. If we receive the FIN between the connectedness |
1441 // check and writing/reading from the socket, we may first learn the socket | 1441 // check and writing/reading from the socket, we may first learn the socket |
1442 // is disconnected when we get a ERR_SOCKET_NOT_CONNECTED. This will most | 1442 // is disconnected when we get a ERR_SOCKET_NOT_CONNECTED. This will most |
1443 // likely happen when trying to retrieve its IP address. | 1443 // likely happen when trying to retrieve its IP address. |
1444 // See http://crbug.com/105824 for more details. | 1444 // See http://crbug.com/105824 for more details. |
1445 case ERR_SOCKET_NOT_CONNECTED: | 1445 case ERR_SOCKET_NOT_CONNECTED: |
1446 if (ShouldResendRequest(error)) { | 1446 // If a socket is closed on its initial request, HttpStreamParser returns |
| 1447 // ERR_EMPTY_RESPONSE. This may still be close/reuse race if the socket was |
| 1448 // preconnected but failed to be used before the server timed it out. |
| 1449 case ERR_EMPTY_RESPONSE: |
| 1450 if (ShouldResendRequest()) { |
1447 net_log_.AddEventWithNetErrorCode( | 1451 net_log_.AddEventWithNetErrorCode( |
1448 NetLog::TYPE_HTTP_TRANSACTION_RESTART_AFTER_ERROR, error); | 1452 NetLog::TYPE_HTTP_TRANSACTION_RESTART_AFTER_ERROR, error); |
1449 ResetConnectionAndRequestForResend(); | 1453 ResetConnectionAndRequestForResend(); |
1450 error = OK; | 1454 error = OK; |
1451 } | 1455 } |
1452 break; | 1456 break; |
1453 case ERR_PIPELINE_EVICTION: | 1457 case ERR_PIPELINE_EVICTION: |
1454 if (!session_->force_http_pipelining()) { | 1458 if (!session_->force_http_pipelining()) { |
1455 net_log_.AddEventWithNetErrorCode( | 1459 net_log_.AddEventWithNetErrorCode( |
1456 NetLog::TYPE_HTTP_TRANSACTION_RESTART_AFTER_ERROR, error); | 1460 NetLog::TYPE_HTTP_TRANSACTION_RESTART_AFTER_ERROR, error); |
(...skipping 30 matching lines...) Expand all Loading... |
1487 headers_valid_ = false; | 1491 headers_valid_ = false; |
1488 request_headers_.Clear(); | 1492 request_headers_.Clear(); |
1489 response_ = HttpResponseInfo(); | 1493 response_ = HttpResponseInfo(); |
1490 establishing_tunnel_ = false; | 1494 establishing_tunnel_ = false; |
1491 } | 1495 } |
1492 | 1496 |
1493 HttpResponseHeaders* HttpNetworkTransaction::GetResponseHeaders() const { | 1497 HttpResponseHeaders* HttpNetworkTransaction::GetResponseHeaders() const { |
1494 return response_.headers.get(); | 1498 return response_.headers.get(); |
1495 } | 1499 } |
1496 | 1500 |
1497 bool HttpNetworkTransaction::ShouldResendRequest(int error) const { | 1501 bool HttpNetworkTransaction::ShouldResendRequest() const { |
1498 bool connection_is_proven = stream_->IsConnectionReused(); | 1502 bool connection_is_proven = stream_->IsConnectionReused(); |
1499 bool has_received_headers = GetResponseHeaders() != NULL; | 1503 bool has_received_headers = GetResponseHeaders() != NULL; |
1500 | 1504 |
1501 // NOTE: we resend a request only if we reused a keep-alive connection. | 1505 // NOTE: we resend a request only if we reused a keep-alive connection. |
1502 // This automatically prevents an infinite resend loop because we'll run | 1506 // This automatically prevents an infinite resend loop because we'll run |
1503 // out of the cached keep-alive connections eventually. | 1507 // out of the cached keep-alive connections eventually. |
1504 if (connection_is_proven && !has_received_headers) | 1508 if (connection_is_proven && !has_received_headers) |
1505 return true; | 1509 return true; |
1506 return false; | 1510 return false; |
1507 } | 1511 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, | 1621 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
1618 state); | 1622 state); |
1619 break; | 1623 break; |
1620 } | 1624 } |
1621 return description; | 1625 return description; |
1622 } | 1626 } |
1623 | 1627 |
1624 #undef STATE_CASE | 1628 #undef STATE_CASE |
1625 | 1629 |
1626 } // namespace net | 1630 } // namespace net |
OLD | NEW |