| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_basic_stream.h" | 5 #include "net/http/http_basic_stream.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | |
| 8 #include "base/metrics/histogram.h" | |
| 9 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 10 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
| 11 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 12 #include "net/http/http_request_headers.h" | 10 #include "net/http/http_request_headers.h" |
| 13 #include "net/http/http_request_info.h" | 11 #include "net/http/http_request_info.h" |
| 14 #include "net/http/http_response_body_drainer.h" | 12 #include "net/http/http_response_body_drainer.h" |
| 15 #include "net/http/http_stream_parser.h" | 13 #include "net/http/http_stream_parser.h" |
| 16 #include "net/http/http_util.h" | 14 #include "net/http/http_util.h" |
| 17 #include "net/socket/client_socket_handle.h" | 15 #include "net/socket/client_socket_handle.h" |
| 18 #include "net/socket/client_socket_pool_base.h" | |
| 19 | 16 |
| 20 namespace net { | 17 namespace net { |
| 21 | 18 |
| 22 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection, | 19 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection, |
| 23 HttpStreamParser* parser, | 20 HttpStreamParser* parser, |
| 24 bool using_proxy) | 21 bool using_proxy) |
| 25 : read_buf_(new GrowableIOBuffer()), | 22 : read_buf_(new GrowableIOBuffer()), |
| 26 parser_(parser), | 23 parser_(parser), |
| 27 connection_(connection), | 24 connection_(connection), |
| 28 using_proxy_(using_proxy), | 25 using_proxy_(using_proxy), |
| 29 request_info_(NULL), | 26 request_info_(NULL) { |
| 30 response_(NULL), | |
| 31 bytes_read_offset_(0) { | |
| 32 } | 27 } |
| 33 | 28 |
| 34 HttpBasicStream::~HttpBasicStream() {} | 29 HttpBasicStream::~HttpBasicStream() {} |
| 35 | 30 |
| 36 int HttpBasicStream::InitializeStream( | 31 int HttpBasicStream::InitializeStream( |
| 37 const HttpRequestInfo* request_info, | 32 const HttpRequestInfo* request_info, |
| 38 RequestPriority priority, | 33 RequestPriority priority, |
| 39 const BoundNetLog& net_log, | 34 const BoundNetLog& net_log, |
| 40 const CompletionCallback& callback) { | 35 const CompletionCallback& callback) { |
| 41 DCHECK(!parser_.get()); | 36 DCHECK(!parser_.get()); |
| 42 request_info_ = request_info; | 37 request_info_ = request_info; |
| 43 parser_.reset(new HttpStreamParser(connection_.get(), request_info, | 38 parser_.reset(new HttpStreamParser(connection_.get(), request_info, |
| 44 read_buf_, net_log)); | 39 read_buf_, net_log)); |
| 45 bytes_read_offset_ = connection_->socket()->NumBytesRead(); | |
| 46 return OK; | 40 return OK; |
| 47 } | 41 } |
| 48 | 42 |
| 49 | 43 |
| 50 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers, | 44 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers, |
| 51 HttpResponseInfo* response, | 45 HttpResponseInfo* response, |
| 52 const CompletionCallback& callback) { | 46 const CompletionCallback& callback) { |
| 53 DCHECK(parser_.get()); | 47 DCHECK(parser_.get()); |
| 54 DCHECK(request_info_); | 48 DCHECK(request_info_); |
| 55 const std::string path = using_proxy_ ? | 49 const std::string path = using_proxy_ ? |
| 56 HttpUtil::SpecForRequest(request_info_->url) : | 50 HttpUtil::SpecForRequest(request_info_->url) : |
| 57 HttpUtil::PathForRequest(request_info_->url); | 51 HttpUtil::PathForRequest(request_info_->url); |
| 58 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", | 52 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", |
| 59 request_info_->method.c_str(), | 53 request_info_->method.c_str(), |
| 60 path.c_str()); | 54 path.c_str()); |
| 61 response_ = response; | |
| 62 return parser_->SendRequest(request_line_, headers, response, callback); | 55 return parser_->SendRequest(request_line_, headers, response, callback); |
| 63 } | 56 } |
| 64 | 57 |
| 65 UploadProgress HttpBasicStream::GetUploadProgress() const { | 58 UploadProgress HttpBasicStream::GetUploadProgress() const { |
| 66 return parser_->GetUploadProgress(); | 59 return parser_->GetUploadProgress(); |
| 67 } | 60 } |
| 68 | 61 |
| 69 int HttpBasicStream::ReadResponseHeaders(const CompletionCallback& callback) { | 62 int HttpBasicStream::ReadResponseHeaders(const CompletionCallback& callback) { |
| 70 return parser_->ReadResponseHeaders(callback); | 63 return parser_->ReadResponseHeaders(callback); |
| 71 } | 64 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 114 |
| 122 void HttpBasicStream::GetSSLCertRequestInfo( | 115 void HttpBasicStream::GetSSLCertRequestInfo( |
| 123 SSLCertRequestInfo* cert_request_info) { | 116 SSLCertRequestInfo* cert_request_info) { |
| 124 parser_->GetSSLCertRequestInfo(cert_request_info); | 117 parser_->GetSSLCertRequestInfo(cert_request_info); |
| 125 } | 118 } |
| 126 | 119 |
| 127 bool HttpBasicStream::IsSpdyHttpStream() const { | 120 bool HttpBasicStream::IsSpdyHttpStream() const { |
| 128 return false; | 121 return false; |
| 129 } | 122 } |
| 130 | 123 |
| 131 void HttpBasicStream::LogNumRttVsBytesMetrics() const { | |
| 132 // Log rtt metrics here. | |
| 133 } | |
| 134 | |
| 135 void HttpBasicStream::Drain(HttpNetworkSession* session) { | 124 void HttpBasicStream::Drain(HttpNetworkSession* session) { |
| 136 HttpResponseBodyDrainer* drainer = new HttpResponseBodyDrainer(this); | 125 HttpResponseBodyDrainer* drainer = new HttpResponseBodyDrainer(this); |
| 137 drainer->Start(session); | 126 drainer->Start(session); |
| 138 // |drainer| will delete itself. | 127 // |drainer| will delete itself. |
| 139 } | 128 } |
| 140 | 129 |
| 141 } // namespace net | 130 } // namespace net |
| OLD | NEW |