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