| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| 11 #include "net/base/auth.h" | 11 #include "net/base/auth.h" |
| 12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 13 #include "net/base/ssl_cert_request_info.h" | 13 #include "net/base/ssl_cert_request_info.h" |
| 14 #include "net/http/http_net_log_params.h" | 14 #include "net/http/http_net_log_params.h" |
| 15 #include "net/http/http_request_headers.h" | 15 #include "net/http/http_request_headers.h" |
| 16 #include "net/http/http_request_info.h" | 16 #include "net/http/http_request_info.h" |
| 17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
| 18 #include "net/http/http_util.h" | 18 #include "net/http/http_util.h" |
| 19 #include "net/socket/ssl_client_socket.h" | 19 #include "net/socket/ssl_client_socket.h" |
| 20 #include "net/socket/client_socket_handle.h" | 20 #include "net/socket/client_socket_handle.h" |
| 21 | 21 |
| 22 namespace { |
| 23 |
| 24 std::string GetResponseHeaderLines(const net::HttpResponseHeaders& headers) { |
| 25 std::string raw_headers = headers.raw_headers(); |
| 26 const char* null_separated_headers = raw_headers.c_str(); |
| 27 const char* header_line = null_separated_headers; |
| 28 std::string cr_separated_headers; |
| 29 while (header_line[0] != 0) { |
| 30 cr_separated_headers += header_line; |
| 31 cr_separated_headers += "\n"; |
| 32 header_line += strlen(header_line) + 1; |
| 33 } |
| 34 return cr_separated_headers; |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
| 22 namespace net { | 39 namespace net { |
| 23 | 40 |
| 24 HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection, | 41 HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection, |
| 25 const HttpRequestInfo* request, | 42 const HttpRequestInfo* request, |
| 26 GrowableIOBuffer* read_buffer, | 43 GrowableIOBuffer* read_buffer, |
| 27 const BoundNetLog& net_log) | 44 const BoundNetLog& net_log) |
| 28 : io_state_(STATE_NONE), | 45 : io_state_(STATE_NONE), |
| 29 request_(request), | 46 request_(request), |
| 30 request_headers_(NULL), | 47 request_headers_(NULL), |
| 31 request_body_(NULL), | 48 request_body_(NULL), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 62 DCHECK(!user_callback_); | 79 DCHECK(!user_callback_); |
| 63 DCHECK(callback); | 80 DCHECK(callback); |
| 64 DCHECK(response); | 81 DCHECK(response); |
| 65 | 82 |
| 66 if (net_log_.IsLoggingAllEvents()) { | 83 if (net_log_.IsLoggingAllEvents()) { |
| 67 net_log_.AddEvent( | 84 net_log_.AddEvent( |
| 68 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, | 85 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 69 make_scoped_refptr(new NetLogHttpRequestParameter( | 86 make_scoped_refptr(new NetLogHttpRequestParameter( |
| 70 request_line, headers))); | 87 request_line, headers))); |
| 71 } | 88 } |
| 89 DVLOG(20) << __FUNCTION__ << "()" |
| 90 << " request_line = \"" << request_line << "\"" |
| 91 << " headers = \"" << headers.ToString() << "\""; |
| 72 response_ = response; | 92 response_ = response; |
| 73 | 93 |
| 74 // Put the peer's IP address and port into the response. | 94 // Put the peer's IP address and port into the response. |
| 75 AddressList address; | 95 AddressList address; |
| 76 int result = connection_->socket()->GetPeerAddress(&address); | 96 int result = connection_->socket()->GetPeerAddress(&address); |
| 77 if (result != OK) | 97 if (result != OK) |
| 78 return result; | 98 return result; |
| 79 response_->socket_address = HostPortPair::FromAddrInfo(address.head()); | 99 response_->socket_address = HostPortPair::FromAddrInfo(address.head()); |
| 80 | 100 |
| 81 std::string request = request_line + headers.ToString(); | 101 std::string request = request_line + headers.ToString(); |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 std::string content_length_value2; | 632 std::string content_length_value2; |
| 613 while (headers->EnumerateHeader( | 633 while (headers->EnumerateHeader( |
| 614 &it, content_length_header, &content_length_value2)) { | 634 &it, content_length_header, &content_length_value2)) { |
| 615 if (content_length_value != content_length_value2) | 635 if (content_length_value != content_length_value2) |
| 616 return ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH; | 636 return ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH; |
| 617 } | 637 } |
| 618 } | 638 } |
| 619 | 639 |
| 620 response_->headers = headers; | 640 response_->headers = headers; |
| 621 response_->vary_data.Init(*request_, *response_->headers); | 641 response_->vary_data.Init(*request_, *response_->headers); |
| 642 DVLOG(20) << __FUNCTION__ << "()" |
| 643 << " content_length = \"" |
| 644 << response_->headers->GetContentLength() << "\n\"" |
| 645 << " headers = \"" << GetResponseHeaderLines(*response_->headers) |
| 646 << "\""; |
| 622 return OK; | 647 return OK; |
| 623 } | 648 } |
| 624 | 649 |
| 625 void HttpStreamParser::CalculateResponseBodySize() { | 650 void HttpStreamParser::CalculateResponseBodySize() { |
| 626 // Figure how to determine EOF: | 651 // Figure how to determine EOF: |
| 627 | 652 |
| 628 // For certain responses, we know the content length is always 0. From | 653 // For certain responses, we know the content length is always 0. From |
| 629 // RFC 2616 Section 4.3 Message Body: | 654 // RFC 2616 Section 4.3 Message Body: |
| 630 // | 655 // |
| 631 // For response messages, whether or not a message-body is included with | 656 // For response messages, whether or not a message-body is included with |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 void HttpStreamParser::GetSSLCertRequestInfo( | 736 void HttpStreamParser::GetSSLCertRequestInfo( |
| 712 SSLCertRequestInfo* cert_request_info) { | 737 SSLCertRequestInfo* cert_request_info) { |
| 713 if (request_->url.SchemeIs("https") && connection_->socket()) { | 738 if (request_->url.SchemeIs("https") && connection_->socket()) { |
| 714 SSLClientSocket* ssl_socket = | 739 SSLClientSocket* ssl_socket = |
| 715 static_cast<SSLClientSocket*>(connection_->socket()); | 740 static_cast<SSLClientSocket*>(connection_->socket()); |
| 716 ssl_socket->GetSSLCertRequestInfo(cert_request_info); | 741 ssl_socket->GetSSLCertRequestInfo(cert_request_info); |
| 717 } | 742 } |
| 718 } | 743 } |
| 719 | 744 |
| 720 } // namespace net | 745 } // namespace net |
| OLD | NEW |