| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/http/http_request_headers.h" | 10 #include "net/http/http_request_headers.h" |
| 11 #include "net/http/http_request_info.h" | 11 #include "net/http/http_request_info.h" |
| 12 #include "net/http/http_stream_parser.h" | 12 #include "net/http/http_stream_parser.h" |
| 13 #include "net/http/http_util.h" | 13 #include "net/http/http_util.h" |
| 14 #include "net/socket/client_socket_handle.h" | 14 #include "net/socket/client_socket_handle.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection, | 18 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection, |
| 19 HttpStreamParser* parser, |
| 19 bool using_proxy) | 20 bool using_proxy) |
| 20 : read_buf_(new GrowableIOBuffer()), | 21 : read_buf_(new GrowableIOBuffer()), |
| 22 parser_(parser), |
| 21 connection_(connection), | 23 connection_(connection), |
| 22 using_proxy_(using_proxy), | 24 using_proxy_(using_proxy), |
| 23 request_info_(NULL) { | 25 request_info_(NULL) { |
| 24 } | 26 } |
| 25 | 27 |
| 26 int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info, | 28 int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info, |
| 27 const BoundNetLog& net_log, | 29 const BoundNetLog& net_log, |
| 28 CompletionCallback* callback) { | 30 CompletionCallback* callback) { |
| 31 DCHECK(!parser_.get()); |
| 29 request_info_ = request_info; | 32 request_info_ = request_info; |
| 30 parser_.reset(new HttpStreamParser(connection_.get(), request_info, | 33 parser_.reset(new HttpStreamParser(connection_.get(), request_info, |
| 31 read_buf_, net_log)); | 34 read_buf_, net_log)); |
| 32 return OK; | 35 return OK; |
| 33 } | 36 } |
| 34 | 37 |
| 35 | 38 |
| 36 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers, | 39 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers, |
| 37 UploadDataStream* request_body, | 40 UploadDataStream* request_body, |
| 38 HttpResponseInfo* response, | 41 HttpResponseInfo* response, |
| 39 CompletionCallback* callback) { | 42 CompletionCallback* callback) { |
| 40 DCHECK(parser_.get()); | 43 DCHECK(parser_.get()); |
| 44 DCHECK(request_info_); |
| 41 const std::string path = using_proxy_ ? | 45 const std::string path = using_proxy_ ? |
| 42 HttpUtil::SpecForRequest(request_info_->url) : | 46 HttpUtil::SpecForRequest(request_info_->url) : |
| 43 HttpUtil::PathForRequest(request_info_->url); | 47 HttpUtil::PathForRequest(request_info_->url); |
| 44 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", | 48 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", |
| 45 request_info_->method.c_str(), | 49 request_info_->method.c_str(), |
| 46 path.c_str()); | 50 path.c_str()); |
| 47 return parser_->SendRequest(request_line_, headers, request_body, response, | 51 return parser_->SendRequest(request_line_, headers, request_body, response, |
| 48 callback); | 52 callback); |
| 49 } | 53 } |
| 50 | 54 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 68 } | 72 } |
| 69 | 73 |
| 70 void HttpBasicStream::Close(bool not_reusable) { | 74 void HttpBasicStream::Close(bool not_reusable) { |
| 71 parser_->Close(not_reusable); | 75 parser_->Close(not_reusable); |
| 72 } | 76 } |
| 73 | 77 |
| 74 HttpStream* HttpBasicStream::RenewStreamForAuth() { | 78 HttpStream* HttpBasicStream::RenewStreamForAuth() { |
| 75 DCHECK(IsResponseBodyComplete()); | 79 DCHECK(IsResponseBodyComplete()); |
| 76 DCHECK(!IsMoreDataBuffered()); | 80 DCHECK(!IsMoreDataBuffered()); |
| 77 parser_.reset(); | 81 parser_.reset(); |
| 78 return new HttpBasicStream(connection_.release(), using_proxy_); | 82 return new HttpBasicStream(connection_.release(), NULL, using_proxy_); |
| 79 } | 83 } |
| 80 | 84 |
| 81 bool HttpBasicStream::IsResponseBodyComplete() const { | 85 bool HttpBasicStream::IsResponseBodyComplete() const { |
| 82 return parser_->IsResponseBodyComplete(); | 86 return parser_->IsResponseBodyComplete(); |
| 83 } | 87 } |
| 84 | 88 |
| 85 bool HttpBasicStream::CanFindEndOfResponse() const { | 89 bool HttpBasicStream::CanFindEndOfResponse() const { |
| 86 return parser_->CanFindEndOfResponse(); | 90 return parser_->CanFindEndOfResponse(); |
| 87 } | 91 } |
| 88 | 92 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 101 void HttpBasicStream::GetSSLInfo(SSLInfo* ssl_info) { | 105 void HttpBasicStream::GetSSLInfo(SSLInfo* ssl_info) { |
| 102 parser_->GetSSLInfo(ssl_info); | 106 parser_->GetSSLInfo(ssl_info); |
| 103 } | 107 } |
| 104 | 108 |
| 105 void HttpBasicStream::GetSSLCertRequestInfo( | 109 void HttpBasicStream::GetSSLCertRequestInfo( |
| 106 SSLCertRequestInfo* cert_request_info) { | 110 SSLCertRequestInfo* cert_request_info) { |
| 107 parser_->GetSSLCertRequestInfo(cert_request_info); | 111 parser_->GetSSLCertRequestInfo(cert_request_info); |
| 108 } | 112 } |
| 109 | 113 |
| 110 } // namespace net | 114 } // namespace net |
| OLD | NEW |