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
3 // found in the LICENSE file.
5 #include "net/http/http_basic_stream.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "net/http/http_request_info.h"
9 #include "net/http/http_response_body_drainer.h"
10 #include "net/http/http_stream_parser.h"
11 #include "net/socket/client_socket_handle.h"
15 HttpBasicStream::HttpBasicStream(ClientSocketHandle
* connection
,
17 : state_(connection
, using_proxy
) {}
19 HttpBasicStream::~HttpBasicStream() {}
21 int HttpBasicStream::InitializeStream(const HttpRequestInfo
* request_info
,
22 RequestPriority priority
,
23 const BoundNetLog
& net_log
,
24 const CompletionCallback
& callback
) {
25 state_
.Initialize(request_info
, priority
, net_log
, callback
);
29 int HttpBasicStream::SendRequest(const HttpRequestHeaders
& headers
,
30 HttpResponseInfo
* response
,
31 const CompletionCallback
& callback
) {
33 return parser()->SendRequest(
34 state_
.GenerateRequestLine(), headers
, response
, callback
);
37 UploadProgress
HttpBasicStream::GetUploadProgress() const {
38 return parser()->GetUploadProgress();
41 int HttpBasicStream::ReadResponseHeaders(const CompletionCallback
& callback
) {
42 return parser()->ReadResponseHeaders(callback
);
45 const HttpResponseInfo
* HttpBasicStream::GetResponseInfo() const {
46 return parser()->GetResponseInfo();
49 int HttpBasicStream::ReadResponseBody(IOBuffer
* buf
,
51 const CompletionCallback
& callback
) {
52 return parser()->ReadResponseBody(buf
, buf_len
, callback
);
55 void HttpBasicStream::Close(bool not_reusable
) {
56 parser()->Close(not_reusable
);
59 HttpStream
* HttpBasicStream::RenewStreamForAuth() {
60 DCHECK(IsResponseBodyComplete());
61 DCHECK(!parser()->IsMoreDataBuffered());
62 // The HttpStreamParser object still has a pointer to the connection. Just to
63 // be extra-sure it doesn't touch the connection again, delete it here rather
64 // than leaving it until the destructor is called.
65 state_
.DeleteParser();
66 return new HttpBasicStream(state_
.ReleaseConnection().release(),
67 state_
.using_proxy());
70 bool HttpBasicStream::IsResponseBodyComplete() const {
71 return parser()->IsResponseBodyComplete();
74 bool HttpBasicStream::CanFindEndOfResponse() const {
75 return parser()->CanFindEndOfResponse();
78 bool HttpBasicStream::IsConnectionReused() const {
79 return parser()->IsConnectionReused();
82 void HttpBasicStream::SetConnectionReused() { parser()->SetConnectionReused(); }
84 bool HttpBasicStream::IsConnectionReusable() const {
85 return parser()->IsConnectionReusable();
88 int64
HttpBasicStream::GetTotalReceivedBytes() const {
90 return parser()->received_bytes();
94 bool HttpBasicStream::GetLoadTimingInfo(
95 LoadTimingInfo
* load_timing_info
) const {
96 return state_
.connection()->GetLoadTimingInfo(IsConnectionReused(),
100 void HttpBasicStream::GetSSLInfo(SSLInfo
* ssl_info
) {
101 parser()->GetSSLInfo(ssl_info
);
104 void HttpBasicStream::GetSSLCertRequestInfo(
105 SSLCertRequestInfo
* cert_request_info
) {
106 parser()->GetSSLCertRequestInfo(cert_request_info
);
109 bool HttpBasicStream::IsSpdyHttpStream() const { return false; }
111 void HttpBasicStream::Drain(HttpNetworkSession
* session
) {
112 HttpResponseBodyDrainer
* drainer
= new HttpResponseBodyDrainer(this);
113 drainer
->Start(session
);
114 // |drainer| will delete itself.
117 void HttpBasicStream::SetPriority(RequestPriority priority
) {
118 // TODO(akalin): Plumb this through to |connection_|.