Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: net/http/http_network_transaction.cc

Issue 119346: Introduce HttpStream and HttpBasicStream. (Closed)
Patch Set: Add comments to HttpBasicStream. Switch declaration order of Read/Write. Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_network_transaction.h ('k') | net/http/http_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/field_trial.h" 9 #include "base/field_trial.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/trace_event.h" 11 #include "base/trace_event.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "net/base/client_socket_factory.h" 13 #include "net/base/client_socket_factory.h"
14 #include "net/base/connection_type_histograms.h" 14 #include "net/base/connection_type_histograms.h"
15 #include "net/base/dns_resolution_observer.h" 15 #include "net/base/dns_resolution_observer.h"
16 #include "net/base/host_resolver.h" 16 #include "net/base/host_resolver.h"
17 #include "net/base/io_buffer.h" 17 #include "net/base/io_buffer.h"
18 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
19 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
20 #include "net/base/net_util.h" 20 #include "net/base/net_util.h"
21 #include "net/base/ssl_client_socket.h" 21 #include "net/base/ssl_client_socket.h"
22 #include "net/base/upload_data_stream.h" 22 #include "net/base/upload_data_stream.h"
23 #include "net/http/http_auth.h" 23 #include "net/http/http_auth.h"
24 #include "net/http/http_auth_handler.h" 24 #include "net/http/http_auth_handler.h"
25 #include "net/http/http_basic_stream.h"
25 #include "net/http/http_chunked_decoder.h" 26 #include "net/http/http_chunked_decoder.h"
26 #include "net/http/http_network_session.h" 27 #include "net/http/http_network_session.h"
27 #include "net/http/http_request_info.h" 28 #include "net/http/http_request_info.h"
28 #include "net/http/http_response_headers.h" 29 #include "net/http/http_response_headers.h"
29 #include "net/http/http_util.h" 30 #include "net/http/http_util.h"
30 31
31 using base::Time; 32 using base::Time;
32 33
33 namespace net { 34 namespace net {
34 35
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 // needed. 576 // needed.
576 LogTCPConnectedMetrics(); 577 LogTCPConnectedMetrics();
577 if (using_ssl_ && !using_tunnel_) { 578 if (using_ssl_ && !using_tunnel_) {
578 next_state_ = STATE_SSL_CONNECT; 579 next_state_ = STATE_SSL_CONNECT;
579 } else { 580 } else {
580 next_state_ = STATE_WRITE_HEADERS; 581 next_state_ = STATE_WRITE_HEADERS;
581 if (using_tunnel_) 582 if (using_tunnel_)
582 establishing_tunnel_ = true; 583 establishing_tunnel_ = true;
583 } 584 }
584 } 585 }
586 http_stream_.reset(new HttpBasicStream(&connection_));
585 return OK; 587 return OK;
586 } 588 }
587 589
588 int HttpNetworkTransaction::DoSSLConnect() { 590 int HttpNetworkTransaction::DoSSLConnect() {
589 next_state_ = STATE_SSL_CONNECT_COMPLETE; 591 next_state_ = STATE_SSL_CONNECT_COMPLETE;
590 592
591 // Add a SSL socket on top of our existing transport socket. 593 // Add a SSL socket on top of our existing transport socket.
592 ClientSocket* s = connection_.release_socket(); 594 ClientSocket* s = connection_.release_socket();
593 s = socket_factory_->CreateSSLClientSocket( 595 s = socket_factory_->CreateSSLClientSocket(
594 s, request_->url.HostNoBrackets(), ssl_config_); 596 s, request_->url.HostNoBrackets(), ssl_config_);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 // out the first bytes of the request headers. 652 // out the first bytes of the request headers.
651 if (request_headers_bytes_sent_ == 0) { 653 if (request_headers_bytes_sent_ == 0) {
652 response_.request_time = Time::Now(); 654 response_.request_time = Time::Now();
653 } 655 }
654 656
655 request_headers_->SetDataOffset(request_headers_bytes_sent_); 657 request_headers_->SetDataOffset(request_headers_bytes_sent_);
656 int buf_len = static_cast<int>(request_headers_->headers_.size() - 658 int buf_len = static_cast<int>(request_headers_->headers_.size() -
657 request_headers_bytes_sent_); 659 request_headers_bytes_sent_);
658 DCHECK_GT(buf_len, 0); 660 DCHECK_GT(buf_len, 0);
659 661
660 return connection_.socket()->Write(request_headers_, buf_len, &io_callback_); 662 return http_stream_->Write(request_headers_, buf_len, &io_callback_);
661 } 663 }
662 664
663 int HttpNetworkTransaction::DoWriteHeadersComplete(int result) { 665 int HttpNetworkTransaction::DoWriteHeadersComplete(int result) {
664 if (result < 0) 666 if (result < 0)
665 return HandleIOError(result); 667 return HandleIOError(result);
666 668
667 request_headers_bytes_sent_ += result; 669 request_headers_bytes_sent_ += result;
668 if (request_headers_bytes_sent_ < request_headers_->headers_.size()) { 670 if (request_headers_bytes_sent_ < request_headers_->headers_.size()) {
669 next_state_ = STATE_WRITE_HEADERS; 671 next_state_ = STATE_WRITE_HEADERS;
670 } else if (!establishing_tunnel_ && request_body_stream_.get() && 672 } else if (!establishing_tunnel_ && request_body_stream_.get() &&
671 request_body_stream_->size()) { 673 request_body_stream_->size()) {
672 next_state_ = STATE_WRITE_BODY; 674 next_state_ = STATE_WRITE_BODY;
673 } else { 675 } else {
674 next_state_ = STATE_READ_HEADERS; 676 next_state_ = STATE_READ_HEADERS;
675 } 677 }
676 return OK; 678 return OK;
677 } 679 }
678 680
679 int HttpNetworkTransaction::DoWriteBody() { 681 int HttpNetworkTransaction::DoWriteBody() {
680 next_state_ = STATE_WRITE_BODY_COMPLETE; 682 next_state_ = STATE_WRITE_BODY_COMPLETE;
681 683
682 DCHECK(request_body_stream_.get()); 684 DCHECK(request_body_stream_.get());
683 DCHECK(request_body_stream_->size()); 685 DCHECK(request_body_stream_->size());
684 686
685 int buf_len = static_cast<int>(request_body_stream_->buf_len()); 687 int buf_len = static_cast<int>(request_body_stream_->buf_len());
686 688
687 return connection_.socket()->Write(request_body_stream_->buf(), buf_len, 689 return http_stream_->Write(request_body_stream_->buf(), buf_len,
688 &io_callback_); 690 &io_callback_);
689 } 691 }
690 692
691 int HttpNetworkTransaction::DoWriteBodyComplete(int result) { 693 int HttpNetworkTransaction::DoWriteBodyComplete(int result) {
692 if (result < 0) 694 if (result < 0)
693 return HandleIOError(result); 695 return HandleIOError(result);
694 696
695 request_body_stream_->DidConsume(result); 697 request_body_stream_->DidConsume(result);
696 698
697 if (request_body_stream_->position() < request_body_stream_->size()) { 699 if (request_body_stream_->position() < request_body_stream_->size()) {
698 next_state_ = STATE_WRITE_BODY; 700 next_state_ = STATE_WRITE_BODY;
699 } else { 701 } else {
700 next_state_ = STATE_READ_HEADERS; 702 next_state_ = STATE_READ_HEADERS;
701 } 703 }
702 return OK; 704 return OK;
703 } 705 }
704 706
705 int HttpNetworkTransaction::DoReadHeaders() { 707 int HttpNetworkTransaction::DoReadHeaders() {
706 next_state_ = STATE_READ_HEADERS_COMPLETE; 708 next_state_ = STATE_READ_HEADERS_COMPLETE;
707 709
708 // Grow the read buffer if necessary. 710 // Grow the read buffer if necessary.
709 if (header_buf_len_ == header_buf_capacity_) { 711 if (header_buf_len_ == header_buf_capacity_) {
710 header_buf_capacity_ += kHeaderBufInitialSize; 712 header_buf_capacity_ += kHeaderBufInitialSize;
711 header_buf_->Realloc(header_buf_capacity_); 713 header_buf_->Realloc(header_buf_capacity_);
712 } 714 }
713 715
714 int buf_len = header_buf_capacity_ - header_buf_len_; 716 int buf_len = header_buf_capacity_ - header_buf_len_;
715 header_buf_->set_data(header_buf_len_); 717 header_buf_->set_data(header_buf_len_);
716 718
717 return connection_.socket()->Read(header_buf_, buf_len, &io_callback_); 719 return http_stream_->Read(header_buf_, buf_len, &io_callback_);
718 } 720 }
719 721
720 int HttpNetworkTransaction::HandleConnectionClosedBeforeEndOfHeaders() { 722 int HttpNetworkTransaction::HandleConnectionClosedBeforeEndOfHeaders() {
721 if (establishing_tunnel_) { 723 if (establishing_tunnel_) {
722 // The connection was closed before the tunnel could be established. 724 // The connection was closed before the tunnel could be established.
723 return ERR_TUNNEL_CONNECTION_FAILED; 725 return ERR_TUNNEL_CONNECTION_FAILED;
724 } 726 }
725 727
726 if (has_found_status_line_start()) { 728 if (has_found_status_line_start()) {
727 // Assume EOF is end-of-headers. 729 // Assume EOF is end-of-headers.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 if (header_buf_body_offset_ == header_buf_len_) { 840 if (header_buf_body_offset_ == header_buf_len_) {
839 header_buf_->Reset(); 841 header_buf_->Reset();
840 header_buf_capacity_ = 0; 842 header_buf_capacity_ = 0;
841 header_buf_len_ = 0; 843 header_buf_len_ = 0;
842 header_buf_body_offset_ = -1; 844 header_buf_body_offset_ = -1;
843 } 845 }
844 return n; 846 return n;
845 } 847 }
846 848
847 reading_body_from_socket_ = true; 849 reading_body_from_socket_ = true;
848 return connection_.socket()->Read(read_buf_, read_buf_len_, &io_callback_); 850 return http_stream_->Read(read_buf_, read_buf_len_, &io_callback_);
849 } 851 }
850 852
851 int HttpNetworkTransaction::DoReadBodyComplete(int result) { 853 int HttpNetworkTransaction::DoReadBodyComplete(int result) {
852 // We are done with the Read call. 854 // We are done with the Read call.
853 DCHECK(!establishing_tunnel_) << 855 DCHECK(!establishing_tunnel_) <<
854 "We should never read a response body of a tunnel."; 856 "We should never read a response body of a tunnel.";
855 857
856 bool unfiltered_eof = (result == 0 && reading_body_from_socket_); 858 bool unfiltered_eof = (result == 0 && reading_body_from_socket_);
857 reading_body_from_socket_ = false; 859 reading_body_from_socket_ = false;
858 860
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 host_and_port = proxy_info_.proxy_server().host_and_port(); 1627 host_and_port = proxy_info_.proxy_server().host_and_port();
1626 } else { 1628 } else {
1627 DCHECK(target == HttpAuth::AUTH_SERVER); 1629 DCHECK(target == HttpAuth::AUTH_SERVER);
1628 host_and_port = GetHostAndPort(request_->url); 1630 host_and_port = GetHostAndPort(request_->url);
1629 } 1631 }
1630 auth_info->host_and_port = ASCIIToWide(host_and_port); 1632 auth_info->host_and_port = ASCIIToWide(host_and_port);
1631 response_.auth_challenge = auth_info; 1633 response_.auth_challenge = auth_info;
1632 } 1634 }
1633 1635
1634 } // namespace net 1636 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.h ('k') | net/http/http_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698