Chromium Code Reviews| 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 static std::string GetResponseHeaderLines( | |
|
rvargas (doing something else)
2011/05/19 19:30:36
nit: can you use an anonymous namespace instead?
ahendrickson
2011/05/19 22:29:34
Done.
| |
| 23 const net::HttpResponseHeaders& headers) { | |
| 24 std::string raw_headers = headers.raw_headers(); | |
| 25 const char* null_separated_headers = raw_headers.c_str(); | |
| 26 const char* header_line = null_separated_headers; | |
| 27 std::string cr_separated_headers; | |
| 28 while (header_line[0] != 0) { | |
| 29 cr_separated_headers += header_line; | |
| 30 cr_separated_headers += "\n"; | |
| 31 header_line += strlen(header_line) + 1; | |
|
rvargas (doing something else)
2011/05/19 19:30:36
It probably doesn't matter too much, but it looks
| |
| 32 } | |
| 33 return cr_separated_headers; | |
| 34 } | |
| 35 | |
| 22 namespace net { | 36 namespace net { |
| 23 | 37 |
| 24 HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection, | 38 HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection, |
| 25 const HttpRequestInfo* request, | 39 const HttpRequestInfo* request, |
| 26 GrowableIOBuffer* read_buffer, | 40 GrowableIOBuffer* read_buffer, |
| 27 const BoundNetLog& net_log) | 41 const BoundNetLog& net_log) |
| 28 : io_state_(STATE_NONE), | 42 : io_state_(STATE_NONE), |
| 29 request_(request), | 43 request_(request), |
| 30 request_headers_(NULL), | 44 request_headers_(NULL), |
| 31 request_body_(NULL), | 45 request_body_(NULL), |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 62 DCHECK(!user_callback_); | 76 DCHECK(!user_callback_); |
| 63 DCHECK(callback); | 77 DCHECK(callback); |
| 64 DCHECK(response); | 78 DCHECK(response); |
| 65 | 79 |
| 66 if (net_log_.IsLoggingAllEvents()) { | 80 if (net_log_.IsLoggingAllEvents()) { |
| 67 net_log_.AddEvent( | 81 net_log_.AddEvent( |
| 68 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, | 82 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 69 make_scoped_refptr(new NetLogHttpRequestParameter( | 83 make_scoped_refptr(new NetLogHttpRequestParameter( |
| 70 request_line, headers))); | 84 request_line, headers))); |
| 71 } | 85 } |
| 86 VLOG(20) << __FUNCTION__ << "()" | |
|
rvargas (doing something else)
2011/05/19 19:30:36
This looks odd. Could you use DVLOG instead?. Havi
ahendrickson
2011/05/19 22:29:34
Switched to DVLOG.
20 is the number we use for de
| |
| 87 << " request_line = \"" << request_line << "\"" | |
| 88 << " headers = \"" << headers.ToString() << "\""; | |
| 72 response_ = response; | 89 response_ = response; |
| 73 | 90 |
| 74 // Put the peer's IP address and port into the response. | 91 // Put the peer's IP address and port into the response. |
| 75 AddressList address; | 92 AddressList address; |
| 76 int result = connection_->socket()->GetPeerAddress(&address); | 93 int result = connection_->socket()->GetPeerAddress(&address); |
| 77 if (result != OK) | 94 if (result != OK) |
| 78 return result; | 95 return result; |
| 79 response_->socket_address = HostPortPair::FromAddrInfo(address.head()); | 96 response_->socket_address = HostPortPair::FromAddrInfo(address.head()); |
| 80 | 97 |
| 81 std::string request = request_line + headers.ToString(); | 98 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; | 629 std::string content_length_value2; |
| 613 while (headers->EnumerateHeader( | 630 while (headers->EnumerateHeader( |
| 614 &it, content_length_header, &content_length_value2)) { | 631 &it, content_length_header, &content_length_value2)) { |
| 615 if (content_length_value != content_length_value2) | 632 if (content_length_value != content_length_value2) |
| 616 return ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH; | 633 return ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH; |
| 617 } | 634 } |
| 618 } | 635 } |
| 619 | 636 |
| 620 response_->headers = headers; | 637 response_->headers = headers; |
| 621 response_->vary_data.Init(*request_, *response_->headers); | 638 response_->vary_data.Init(*request_, *response_->headers); |
| 639 VLOG(20) << __FUNCTION__ << "()" | |
|
rvargas (doing something else)
2011/05/19 19:30:36
same here (and other places)
ahendrickson
2011/05/19 22:29:34
Done.
| |
| 640 << " content_length = \"" | |
| 641 << response_->headers->GetContentLength() << "\n\"" | |
| 642 << " headers = \"" << GetResponseHeaderLines(*response_->headers) | |
| 643 << "\""; | |
| 622 return OK; | 644 return OK; |
| 623 } | 645 } |
| 624 | 646 |
| 625 void HttpStreamParser::CalculateResponseBodySize() { | 647 void HttpStreamParser::CalculateResponseBodySize() { |
| 626 // Figure how to determine EOF: | 648 // Figure how to determine EOF: |
| 627 | 649 |
| 628 // For certain responses, we know the content length is always 0. From | 650 // For certain responses, we know the content length is always 0. From |
| 629 // RFC 2616 Section 4.3 Message Body: | 651 // RFC 2616 Section 4.3 Message Body: |
| 630 // | 652 // |
| 631 // For response messages, whether or not a message-body is included with | 653 // 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( | 733 void HttpStreamParser::GetSSLCertRequestInfo( |
| 712 SSLCertRequestInfo* cert_request_info) { | 734 SSLCertRequestInfo* cert_request_info) { |
| 713 if (request_->url.SchemeIs("https") && connection_->socket()) { | 735 if (request_->url.SchemeIs("https") && connection_->socket()) { |
| 714 SSLClientSocket* ssl_socket = | 736 SSLClientSocket* ssl_socket = |
| 715 static_cast<SSLClientSocket*>(connection_->socket()); | 737 static_cast<SSLClientSocket*>(connection_->socket()); |
| 716 ssl_socket->GetSSLCertRequestInfo(cert_request_info); | 738 ssl_socket->GetSSLCertRequestInfo(cert_request_info); |
| 717 } | 739 } |
| 718 } | 740 } |
| 719 | 741 |
| 720 } // namespace net | 742 } // namespace net |
| OLD | NEW |