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" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 DCHECK(!user_callback_); | 62 DCHECK(!user_callback_); |
| 63 DCHECK(callback); | 63 DCHECK(callback); |
| 64 DCHECK(response); | 64 DCHECK(response); |
| 65 | 65 |
| 66 if (net_log_.IsLoggingAllEvents()) { | 66 if (net_log_.IsLoggingAllEvents()) { |
| 67 net_log_.AddEvent( | 67 net_log_.AddEvent( |
| 68 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, | 68 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 69 make_scoped_refptr(new NetLogHttpRequestParameter( | 69 make_scoped_refptr(new NetLogHttpRequestParameter( |
| 70 request_line, headers))); | 70 request_line, headers))); |
| 71 } | 71 } |
| 72 VLOG(20) << __FUNCTION__ << "()" | |
| 73 << " request_line = \"" << request_line << "\"" | |
| 74 << " headers = \"" << headers.ToString() << "\""; | |
|
Randy Smith (Not in Mondays)
2011/05/03 21:30:41
I'd be inclined to separate out pure logging chang
ahendrickson
2011/05/04 15:08:25
I find myself putting these things in every time I
| |
| 72 response_ = response; | 75 response_ = response; |
| 73 | 76 |
| 74 // Put the peer's IP address and port into the response. | 77 // Put the peer's IP address and port into the response. |
| 75 AddressList address; | 78 AddressList address; |
| 76 int result = connection_->socket()->GetPeerAddress(&address); | 79 int result = connection_->socket()->GetPeerAddress(&address); |
| 77 if (result != OK) | 80 if (result != OK) |
| 78 return result; | 81 return result; |
| 79 response_->socket_address = HostPortPair::FromAddrInfo(address.head()); | 82 response_->socket_address = HostPortPair::FromAddrInfo(address.head()); |
| 80 | 83 |
| 81 std::string request = request_line + headers.ToString(); | 84 std::string request = request_line + headers.ToString(); |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 read_buf_unused_offset_ = 0; | 552 read_buf_unused_offset_ = 0; |
| 550 } else { | 553 } else { |
| 551 io_state_ = STATE_BODY_PENDING; | 554 io_state_ = STATE_BODY_PENDING; |
| 552 user_read_buf_ = NULL; | 555 user_read_buf_ = NULL; |
| 553 user_read_buf_len_ = 0; | 556 user_read_buf_len_ = 0; |
| 554 } | 557 } |
| 555 | 558 |
| 556 return result; | 559 return result; |
| 557 } | 560 } |
| 558 | 561 |
| 562 static std::string GetResponseHeaderLines(const HttpResponseHeaders& headers) { | |
| 563 std::string raw_headers = headers.raw_headers(); | |
| 564 const char* null_separated_headers = raw_headers.c_str(); | |
| 565 const char* header_line = null_separated_headers; | |
| 566 std::string cr_separated_headers; | |
| 567 while (header_line[0] != 0) { | |
| 568 cr_separated_headers += header_line; | |
| 569 cr_separated_headers += "\n"; | |
| 570 header_line += strlen(header_line) + 1; | |
| 571 } | |
| 572 return cr_separated_headers; | |
| 573 } | |
| 574 | |
| 559 int HttpStreamParser::ParseResponseHeaders() { | 575 int HttpStreamParser::ParseResponseHeaders() { |
| 560 int end_offset = -1; | 576 int end_offset = -1; |
| 561 | 577 |
| 562 // Look for the start of the status line, if it hasn't been found yet. | 578 // Look for the start of the status line, if it hasn't been found yet. |
| 563 if (response_header_start_offset_ < 0) { | 579 if (response_header_start_offset_ < 0) { |
| 564 response_header_start_offset_ = HttpUtil::LocateStartOfStatusLine( | 580 response_header_start_offset_ = HttpUtil::LocateStartOfStatusLine( |
| 565 read_buf_->StartOfBuffer() + read_buf_unused_offset_, | 581 read_buf_->StartOfBuffer() + read_buf_unused_offset_, |
| 566 read_buf_->offset() - read_buf_unused_offset_); | 582 read_buf_->offset() - read_buf_unused_offset_); |
| 567 } | 583 } |
| 568 | 584 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 std::string content_length_value2; | 628 std::string content_length_value2; |
| 613 while (headers->EnumerateHeader( | 629 while (headers->EnumerateHeader( |
| 614 &it, content_length_header, &content_length_value2)) { | 630 &it, content_length_header, &content_length_value2)) { |
| 615 if (content_length_value != content_length_value2) | 631 if (content_length_value != content_length_value2) |
| 616 return ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH; | 632 return ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH; |
| 617 } | 633 } |
| 618 } | 634 } |
| 619 | 635 |
| 620 response_->headers = headers; | 636 response_->headers = headers; |
| 621 response_->vary_data.Init(*request_, *response_->headers); | 637 response_->vary_data.Init(*request_, *response_->headers); |
| 638 VLOG(20) << __FUNCTION__ << "()" | |
| 639 << " content_length = \"" | |
| 640 << response_->headers->GetContentLength() << "\n\"" | |
| 641 << " headers = \"" << GetResponseHeaderLines(*response_->headers) | |
| 642 << "\""; | |
| 622 return OK; | 643 return OK; |
| 623 } | 644 } |
| 624 | 645 |
| 625 void HttpStreamParser::CalculateResponseBodySize() { | 646 void HttpStreamParser::CalculateResponseBodySize() { |
| 626 // Figure how to determine EOF: | 647 // Figure how to determine EOF: |
| 627 | 648 |
| 628 // For certain responses, we know the content length is always 0. From | 649 // For certain responses, we know the content length is always 0. From |
| 629 // RFC 2616 Section 4.3 Message Body: | 650 // RFC 2616 Section 4.3 Message Body: |
| 630 // | 651 // |
| 631 // For response messages, whether or not a message-body is included with | 652 // 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( | 732 void HttpStreamParser::GetSSLCertRequestInfo( |
| 712 SSLCertRequestInfo* cert_request_info) { | 733 SSLCertRequestInfo* cert_request_info) { |
| 713 if (request_->url.SchemeIs("https") && connection_->socket()) { | 734 if (request_->url.SchemeIs("https") && connection_->socket()) { |
| 714 SSLClientSocket* ssl_socket = | 735 SSLClientSocket* ssl_socket = |
| 715 static_cast<SSLClientSocket*>(connection_->socket()); | 736 static_cast<SSLClientSocket*>(connection_->socket()); |
| 716 ssl_socket->GetSSLCertRequestInfo(cert_request_info); | 737 ssl_socket->GetSSLCertRequestInfo(cert_request_info); |
| 717 } | 738 } |
| 718 } | 739 } |
| 719 | 740 |
| 720 } // namespace net | 741 } // namespace net |
| OLD | NEW |