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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 if (read_buf_->offset() == 0 && result != ERR_CONNECTION_CLOSED) | 537 if (read_buf_->offset() == 0 && result != ERR_CONNECTION_CLOSED) |
538 response_->response_time = base::Time::Now(); | 538 response_->response_time = base::Time::Now(); |
539 | 539 |
540 if (result == ERR_CONNECTION_CLOSED) { | 540 if (result == ERR_CONNECTION_CLOSED) { |
541 // The connection closed before we detected the end of the headers. | 541 // The connection closed before we detected the end of the headers. |
542 if (read_buf_->offset() == 0) { | 542 if (read_buf_->offset() == 0) { |
543 // The connection was closed before any data was sent. Likely an error | 543 // The connection was closed before any data was sent. Likely an error |
544 // rather than empty HTTP/0.9 response. | 544 // rather than empty HTTP/0.9 response. |
545 io_state_ = STATE_DONE; | 545 io_state_ = STATE_DONE; |
546 return ERR_EMPTY_RESPONSE; | 546 return ERR_EMPTY_RESPONSE; |
547 } else if (request_->url.SchemeIs("https")) { | 547 } else if (request_->url.SchemeIsSecure()) { |
548 // The connection was closed in the middle of the headers. For HTTPS we | 548 // The connection was closed in the middle of the headers. For HTTPS we |
549 // don't parse partial headers. Return a different error code so that we | 549 // don't parse partial headers. Return a different error code so that we |
550 // know that we shouldn't attempt to retry the request. | 550 // know that we shouldn't attempt to retry the request. |
551 io_state_ = STATE_DONE; | 551 io_state_ = STATE_DONE; |
552 return ERR_HEADERS_TRUNCATED; | 552 return ERR_RESPONSE_HEADERS_TRUNCATED; |
553 } | 553 } |
554 // Parse things as well as we can and let the caller decide what to do. | 554 // Parse things as well as we can and let the caller decide what to do. |
555 int end_offset; | 555 int end_offset; |
556 if (response_header_start_offset_ >= 0) { | 556 if (response_header_start_offset_ >= 0) { |
557 io_state_ = STATE_READ_BODY_COMPLETE; | 557 io_state_ = STATE_READ_BODY_COMPLETE; |
558 end_offset = read_buf_->offset(); | 558 end_offset = read_buf_->offset(); |
559 } else { | 559 } else { |
560 io_state_ = STATE_BODY_PENDING; | 560 io_state_ = STATE_BODY_PENDING; |
561 end_offset = 0; | 561 end_offset = 0; |
562 } | 562 } |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 | 890 |
891 void HttpStreamParser::SetConnectionReused() { | 891 void HttpStreamParser::SetConnectionReused() { |
892 connection_->set_is_reused(true); | 892 connection_->set_is_reused(true); |
893 } | 893 } |
894 | 894 |
895 bool HttpStreamParser::IsConnectionReusable() const { | 895 bool HttpStreamParser::IsConnectionReusable() const { |
896 return connection_->socket() && connection_->socket()->IsConnectedAndIdle(); | 896 return connection_->socket() && connection_->socket()->IsConnectedAndIdle(); |
897 } | 897 } |
898 | 898 |
899 void HttpStreamParser::GetSSLInfo(SSLInfo* ssl_info) { | 899 void HttpStreamParser::GetSSLInfo(SSLInfo* ssl_info) { |
900 if (request_->url.SchemeIs("https") && connection_->socket()) { | 900 if (request_->url.SchemeIsSecure() && connection_->socket()) { |
901 SSLClientSocket* ssl_socket = | 901 SSLClientSocket* ssl_socket = |
902 static_cast<SSLClientSocket*>(connection_->socket()); | 902 static_cast<SSLClientSocket*>(connection_->socket()); |
903 ssl_socket->GetSSLInfo(ssl_info); | 903 ssl_socket->GetSSLInfo(ssl_info); |
904 } | 904 } |
905 } | 905 } |
906 | 906 |
907 void HttpStreamParser::GetSSLCertRequestInfo( | 907 void HttpStreamParser::GetSSLCertRequestInfo( |
908 SSLCertRequestInfo* cert_request_info) { | 908 SSLCertRequestInfo* cert_request_info) { |
909 if (request_->url.SchemeIs("https") && connection_->socket()) { | 909 if (request_->url.SchemeIsSecure() && connection_->socket()) { |
910 SSLClientSocket* ssl_socket = | 910 SSLClientSocket* ssl_socket = |
911 static_cast<SSLClientSocket*>(connection_->socket()); | 911 static_cast<SSLClientSocket*>(connection_->socket()); |
912 ssl_socket->GetSSLCertRequestInfo(cert_request_info); | 912 ssl_socket->GetSSLCertRequestInfo(cert_request_info); |
913 } | 913 } |
914 } | 914 } |
915 | 915 |
916 int HttpStreamParser::EncodeChunk(const base::StringPiece& payload, | 916 int HttpStreamParser::EncodeChunk(const base::StringPiece& payload, |
917 char* output, | 917 char* output, |
918 size_t output_size) { | 918 size_t output_size) { |
919 if (output_size < payload.size() + kChunkHeaderFooterSize) | 919 if (output_size < payload.size() + kChunkHeaderFooterSize) |
(...skipping 26 matching lines...) Expand all Loading... |
946 request_body->IsInMemory() && | 946 request_body->IsInMemory() && |
947 request_body->size() > 0) { | 947 request_body->size() > 0) { |
948 size_t merged_size = request_headers.size() + request_body->size(); | 948 size_t merged_size = request_headers.size() + request_body->size(); |
949 if (merged_size <= kMaxMergedHeaderAndBodySize) | 949 if (merged_size <= kMaxMergedHeaderAndBodySize) |
950 return true; | 950 return true; |
951 } | 951 } |
952 return false; | 952 return false; |
953 } | 953 } |
954 | 954 |
955 } // namespace net | 955 } // namespace net |
OLD | NEW |