| 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 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 if (read_buf_->offset() == 0 && result != ERR_CONNECTION_CLOSED) | 826 if (read_buf_->offset() == 0 && result != ERR_CONNECTION_CLOSED) |
| 827 response_->response_time = base::Time::Now(); | 827 response_->response_time = base::Time::Now(); |
| 828 | 828 |
| 829 if (result == ERR_CONNECTION_CLOSED) { | 829 if (result == ERR_CONNECTION_CLOSED) { |
| 830 // The connection closed before we detected the end of the headers. | 830 // The connection closed before we detected the end of the headers. |
| 831 if (read_buf_->offset() == 0) { | 831 if (read_buf_->offset() == 0) { |
| 832 // The connection was closed before any data was sent. Likely an error | 832 // The connection was closed before any data was sent. Likely an error |
| 833 // rather than empty HTTP/0.9 response. | 833 // rather than empty HTTP/0.9 response. |
| 834 io_state_ = STATE_DONE; | 834 io_state_ = STATE_DONE; |
| 835 return ERR_EMPTY_RESPONSE; | 835 return ERR_EMPTY_RESPONSE; |
| 836 } else if (request_->url.SchemeIsSecure()) { | 836 } else if (request_->url.SchemeIsCryptographic()) { |
| 837 // The connection was closed in the middle of the headers. For HTTPS we | 837 // The connection was closed in the middle of the headers. For HTTPS we |
| 838 // don't parse partial headers. Return a different error code so that we | 838 // don't parse partial headers. Return a different error code so that we |
| 839 // know that we shouldn't attempt to retry the request. | 839 // know that we shouldn't attempt to retry the request. |
| 840 io_state_ = STATE_DONE; | 840 io_state_ = STATE_DONE; |
| 841 return ERR_RESPONSE_HEADERS_TRUNCATED; | 841 return ERR_RESPONSE_HEADERS_TRUNCATED; |
| 842 } | 842 } |
| 843 // Parse things as well as we can and let the caller decide what to do. | 843 // Parse things as well as we can and let the caller decide what to do. |
| 844 int end_offset; | 844 int end_offset; |
| 845 if (response_header_start_offset_ >= 0) { | 845 if (response_header_start_offset_ >= 0) { |
| 846 // The response looks to be a truncated set of HTTP headers. | 846 // The response looks to be a truncated set of HTTP headers. |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 | 1073 |
| 1074 void HttpStreamParser::SetConnectionReused() { | 1074 void HttpStreamParser::SetConnectionReused() { |
| 1075 connection_->set_reuse_type(ClientSocketHandle::REUSED_IDLE); | 1075 connection_->set_reuse_type(ClientSocketHandle::REUSED_IDLE); |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 bool HttpStreamParser::IsConnectionReusable() const { | 1078 bool HttpStreamParser::IsConnectionReusable() const { |
| 1079 return connection_->socket() && connection_->socket()->IsConnectedAndIdle(); | 1079 return connection_->socket() && connection_->socket()->IsConnectedAndIdle(); |
| 1080 } | 1080 } |
| 1081 | 1081 |
| 1082 void HttpStreamParser::GetSSLInfo(SSLInfo* ssl_info) { | 1082 void HttpStreamParser::GetSSLInfo(SSLInfo* ssl_info) { |
| 1083 if (request_->url.SchemeIsSecure() && connection_->socket()) { | 1083 if (request_->url.SchemeIsCryptographic() && connection_->socket()) { |
| 1084 SSLClientSocket* ssl_socket = | 1084 SSLClientSocket* ssl_socket = |
| 1085 static_cast<SSLClientSocket*>(connection_->socket()); | 1085 static_cast<SSLClientSocket*>(connection_->socket()); |
| 1086 ssl_socket->GetSSLInfo(ssl_info); | 1086 ssl_socket->GetSSLInfo(ssl_info); |
| 1087 } | 1087 } |
| 1088 } | 1088 } |
| 1089 | 1089 |
| 1090 void HttpStreamParser::GetSSLCertRequestInfo( | 1090 void HttpStreamParser::GetSSLCertRequestInfo( |
| 1091 SSLCertRequestInfo* cert_request_info) { | 1091 SSLCertRequestInfo* cert_request_info) { |
| 1092 if (request_->url.SchemeIsSecure() && connection_->socket()) { | 1092 if (request_->url.SchemeIsCryptographic() && connection_->socket()) { |
| 1093 SSLClientSocket* ssl_socket = | 1093 SSLClientSocket* ssl_socket = |
| 1094 static_cast<SSLClientSocket*>(connection_->socket()); | 1094 static_cast<SSLClientSocket*>(connection_->socket()); |
| 1095 ssl_socket->GetSSLCertRequestInfo(cert_request_info); | 1095 ssl_socket->GetSSLCertRequestInfo(cert_request_info); |
| 1096 } | 1096 } |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 int HttpStreamParser::EncodeChunk(const base::StringPiece& payload, | 1099 int HttpStreamParser::EncodeChunk(const base::StringPiece& payload, |
| 1100 char* output, | 1100 char* output, |
| 1101 size_t output_size) { | 1101 size_t output_size) { |
| 1102 if (output_size < payload.size() + kChunkHeaderFooterSize) | 1102 if (output_size < payload.size() + kChunkHeaderFooterSize) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1129 request_body->IsInMemory() && | 1129 request_body->IsInMemory() && |
| 1130 request_body->size() > 0) { | 1130 request_body->size() > 0) { |
| 1131 uint64 merged_size = request_headers.size() + request_body->size(); | 1131 uint64 merged_size = request_headers.size() + request_body->size(); |
| 1132 if (merged_size <= kMaxMergedHeaderAndBodySize) | 1132 if (merged_size <= kMaxMergedHeaderAndBodySize) |
| 1133 return true; | 1133 return true; |
| 1134 } | 1134 } |
| 1135 return false; | 1135 return false; |
| 1136 } | 1136 } |
| 1137 | 1137 |
| 1138 } // namespace net | 1138 } // namespace net |
| OLD | NEW |