| 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_stream_parser.h" | 5 #include "net/http/http_stream_parser.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 if (read_buf_->offset() == 0 && result != ERR_CONNECTION_CLOSED) | 785 if (read_buf_->offset() == 0 && result != ERR_CONNECTION_CLOSED) |
| 786 response_->response_time = base::Time::Now(); | 786 response_->response_time = base::Time::Now(); |
| 787 | 787 |
| 788 if (result == ERR_CONNECTION_CLOSED) { | 788 if (result == ERR_CONNECTION_CLOSED) { |
| 789 // The connection closed before we detected the end of the headers. | 789 // The connection closed before we detected the end of the headers. |
| 790 if (read_buf_->offset() == 0) { | 790 if (read_buf_->offset() == 0) { |
| 791 // The connection was closed before any data was sent. Likely an error | 791 // The connection was closed before any data was sent. Likely an error |
| 792 // rather than empty HTTP/0.9 response. | 792 // rather than empty HTTP/0.9 response. |
| 793 io_state_ = STATE_DONE; | 793 io_state_ = STATE_DONE; |
| 794 return ERR_EMPTY_RESPONSE; | 794 return ERR_EMPTY_RESPONSE; |
| 795 } else if (request_->url.SchemeIsSecure()) { | 795 } else if (request_->url.SchemeIsCryptographic()) { |
| 796 // The connection was closed in the middle of the headers. For HTTPS we | 796 // The connection was closed in the middle of the headers. For HTTPS we |
| 797 // don't parse partial headers. Return a different error code so that we | 797 // don't parse partial headers. Return a different error code so that we |
| 798 // know that we shouldn't attempt to retry the request. | 798 // know that we shouldn't attempt to retry the request. |
| 799 io_state_ = STATE_DONE; | 799 io_state_ = STATE_DONE; |
| 800 return ERR_RESPONSE_HEADERS_TRUNCATED; | 800 return ERR_RESPONSE_HEADERS_TRUNCATED; |
| 801 } | 801 } |
| 802 // Parse things as well as we can and let the caller decide what to do. | 802 // Parse things as well as we can and let the caller decide what to do. |
| 803 int end_offset; | 803 int end_offset; |
| 804 if (response_header_start_offset_ >= 0) { | 804 if (response_header_start_offset_ >= 0) { |
| 805 // The response looks to be a truncated set of HTTP headers. | 805 // The response looks to be a truncated set of HTTP headers. |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 | 1032 |
| 1033 void HttpStreamParser::SetConnectionReused() { | 1033 void HttpStreamParser::SetConnectionReused() { |
| 1034 connection_->set_reuse_type(ClientSocketHandle::REUSED_IDLE); | 1034 connection_->set_reuse_type(ClientSocketHandle::REUSED_IDLE); |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 bool HttpStreamParser::IsConnectionReusable() const { | 1037 bool HttpStreamParser::IsConnectionReusable() const { |
| 1038 return connection_->socket() && connection_->socket()->IsConnectedAndIdle(); | 1038 return connection_->socket() && connection_->socket()->IsConnectedAndIdle(); |
| 1039 } | 1039 } |
| 1040 | 1040 |
| 1041 void HttpStreamParser::GetSSLInfo(SSLInfo* ssl_info) { | 1041 void HttpStreamParser::GetSSLInfo(SSLInfo* ssl_info) { |
| 1042 if (request_->url.SchemeIsSecure() && connection_->socket()) { | 1042 if (request_->url.SchemeIsCryptographic() && connection_->socket()) { |
| 1043 SSLClientSocket* ssl_socket = | 1043 SSLClientSocket* ssl_socket = |
| 1044 static_cast<SSLClientSocket*>(connection_->socket()); | 1044 static_cast<SSLClientSocket*>(connection_->socket()); |
| 1045 ssl_socket->GetSSLInfo(ssl_info); | 1045 ssl_socket->GetSSLInfo(ssl_info); |
| 1046 } | 1046 } |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 void HttpStreamParser::GetSSLCertRequestInfo( | 1049 void HttpStreamParser::GetSSLCertRequestInfo( |
| 1050 SSLCertRequestInfo* cert_request_info) { | 1050 SSLCertRequestInfo* cert_request_info) { |
| 1051 if (request_->url.SchemeIsSecure() && connection_->socket()) { | 1051 if (request_->url.SchemeIsCryptographic() && connection_->socket()) { |
| 1052 SSLClientSocket* ssl_socket = | 1052 SSLClientSocket* ssl_socket = |
| 1053 static_cast<SSLClientSocket*>(connection_->socket()); | 1053 static_cast<SSLClientSocket*>(connection_->socket()); |
| 1054 ssl_socket->GetSSLCertRequestInfo(cert_request_info); | 1054 ssl_socket->GetSSLCertRequestInfo(cert_request_info); |
| 1055 } | 1055 } |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 int HttpStreamParser::EncodeChunk(const base::StringPiece& payload, | 1058 int HttpStreamParser::EncodeChunk(const base::StringPiece& payload, |
| 1059 char* output, | 1059 char* output, |
| 1060 size_t output_size) { | 1060 size_t output_size) { |
| 1061 if (output_size < payload.size() + kChunkHeaderFooterSize) | 1061 if (output_size < payload.size() + kChunkHeaderFooterSize) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1088 request_body->IsInMemory() && | 1088 request_body->IsInMemory() && |
| 1089 request_body->size() > 0) { | 1089 request_body->size() > 0) { |
| 1090 uint64 merged_size = request_headers.size() + request_body->size(); | 1090 uint64 merged_size = request_headers.size() + request_body->size(); |
| 1091 if (merged_size <= kMaxMergedHeaderAndBodySize) | 1091 if (merged_size <= kMaxMergedHeaderAndBodySize) |
| 1092 return true; | 1092 return true; |
| 1093 } | 1093 } |
| 1094 return false; | 1094 return false; |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 } // namespace net | 1097 } // namespace net |
| OLD | NEW |