blob: 312b927851b3d9f1f6d122c1e5e5ed973f0d9810 [file] [log] [blame]
[email protected]5f9205f2012-06-14 19:55:231// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]0877e3d2009-10-17 22:29:572// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/http/http_basic_stream.h"
6
bnc3faa41e2016-08-18 14:16:187#include <utility>
danakj1fd259a02016-04-16 03:17:098
[email protected]b94f92d2010-10-27 16:45:209#include "net/http/http_request_info.h"
[email protected]5a60c8b2011-10-19 20:14:2910#include "net/http/http_response_body_drainer.h"
[email protected]277d5942010-08-11 21:02:3511#include "net/http/http_stream_parser.h"
[email protected]4d4a5162010-09-21 22:44:0412#include "net/socket/client_socket_handle.h"
[email protected]277d5942010-08-11 21:02:3513
[email protected]0877e3d2009-10-17 22:29:5714namespace net {
15
bnc3faa41e2016-08-18 14:16:1816HttpBasicStream::HttpBasicStream(std::unique_ptr<ClientSocketHandle> connection,
mmenkea7da6da2016-09-01 21:56:5217 bool using_proxy,
18 bool http_09_on_non_default_ports_enabled)
19 : state_(std::move(connection),
20 using_proxy,
21 http_09_on_non_default_ports_enabled) {}
[email protected]0877e3d2009-10-17 22:29:5722
[email protected]d100e44f2011-01-26 22:47:1123HttpBasicStream::~HttpBasicStream() {}
24
[email protected]f7c21732013-10-27 09:38:5825int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info,
26 RequestPriority priority,
tfarina42834112016-09-22 13:38:2027 const NetLogWithSource& net_log,
[email protected]f7c21732013-10-27 09:38:5828 const CompletionCallback& callback) {
29 state_.Initialize(request_info, priority, net_log, callback);
[email protected]c638a85a2010-07-29 18:41:4030 return OK;
31}
32
[email protected]b94f92d2010-10-27 16:45:2033int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers,
[email protected]a7e41312009-12-16 23:18:1434 HttpResponseInfo* response,
[email protected]49639fa2011-12-20 23:22:4135 const CompletionCallback& callback) {
[email protected]f7c21732013-10-27 09:38:5836 DCHECK(parser());
37 return parser()->SendRequest(
38 state_.GenerateRequestLine(), headers, response, callback);
[email protected]0877e3d2009-10-17 22:29:5739}
40
[email protected]49639fa2011-12-20 23:22:4141int HttpBasicStream::ReadResponseHeaders(const CompletionCallback& callback) {
[email protected]f7c21732013-10-27 09:38:5842 return parser()->ReadResponseHeaders(callback);
[email protected]0877e3d2009-10-17 22:29:5743}
44
[email protected]f7c21732013-10-27 09:38:5845int HttpBasicStream::ReadResponseBody(IOBuffer* buf,
46 int buf_len,
[email protected]49639fa2011-12-20 23:22:4147 const CompletionCallback& callback) {
[email protected]f7c21732013-10-27 09:38:5848 return parser()->ReadResponseBody(buf, buf_len, callback);
[email protected]0877e3d2009-10-17 22:29:5749}
50
[email protected]8e6441ca2010-08-19 05:56:3851void HttpBasicStream::Close(bool not_reusable) {
xunjielie3683982017-01-10 12:14:4852 // parser() is null if |this| is created by an orphaned
53 // HttpStreamFactoryImpl::Job in which case InitializeStream() will not have
54 // been called.
55 if (parser())
56 parser()->Close(not_reusable);
[email protected]8e6441ca2010-08-19 05:56:3857}
58
[email protected]697ef4c2010-10-14 16:38:5859HttpStream* HttpBasicStream::RenewStreamForAuth() {
60 DCHECK(IsResponseBodyComplete());
[email protected]f7c21732013-10-27 09:38:5861 DCHECK(!parser()->IsMoreDataBuffered());
[email protected]b0c35142013-11-02 03:37:0662 // 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.
[email protected]f7c21732013-10-27 09:38:5865 state_.DeleteParser();
mmenkea7da6da2016-09-01 21:56:5266 return new HttpBasicStream(state_.ReleaseConnection(), state_.using_proxy(),
67 state_.http_09_on_non_default_ports_enabled());
[email protected]697ef4c2010-10-14 16:38:5868}
69
[email protected]0877e3d2009-10-17 22:29:5770bool HttpBasicStream::IsResponseBodyComplete() const {
[email protected]f7c21732013-10-27 09:38:5871 return parser()->IsResponseBodyComplete();
[email protected]0877e3d2009-10-17 22:29:5772}
73
[email protected]8e6441ca2010-08-19 05:56:3874bool HttpBasicStream::IsConnectionReused() const {
[email protected]f7c21732013-10-27 09:38:5875 return parser()->IsConnectionReused();
[email protected]8e6441ca2010-08-19 05:56:3876}
77
[email protected]f7c21732013-10-27 09:38:5878void HttpBasicStream::SetConnectionReused() { parser()->SetConnectionReused(); }
[email protected]8e6441ca2010-08-19 05:56:3879
mmenkebd84c392015-09-02 14:12:3480bool HttpBasicStream::CanReuseConnection() const {
81 return parser()->CanReuseConnection();
[email protected]2d0a4f92011-05-05 16:38:4682}
83
sclittle4de1bab92015-09-22 21:28:2484int64_t HttpBasicStream::GetTotalReceivedBytes() const {
[email protected]b8015c42013-12-24 15:18:1985 if (parser())
86 return parser()->received_bytes();
87 return 0;
[email protected]bc92bc972013-12-13 08:32:5988}
89
sclittlebe1ccf62015-09-02 19:40:3690int64_t HttpBasicStream::GetTotalSentBytes() const {
91 if (parser())
92 return parser()->sent_bytes();
93 return 0;
94}
95
[email protected]b258e0792013-01-12 07:11:5996bool HttpBasicStream::GetLoadTimingInfo(
97 LoadTimingInfo* load_timing_info) const {
[email protected]f7c21732013-10-27 09:38:5898 return state_.connection()->GetLoadTimingInfo(IsConnectionReused(),
99 load_timing_info);
[email protected]b258e0792013-01-12 07:11:59100}
101
[email protected]8e6441ca2010-08-19 05:56:38102void HttpBasicStream::GetSSLInfo(SSLInfo* ssl_info) {
[email protected]f7c21732013-10-27 09:38:58103 parser()->GetSSLInfo(ssl_info);
[email protected]8e6441ca2010-08-19 05:56:38104}
105
106void HttpBasicStream::GetSSLCertRequestInfo(
107 SSLCertRequestInfo* cert_request_info) {
[email protected]f7c21732013-10-27 09:38:58108 parser()->GetSSLCertRequestInfo(cert_request_info);
[email protected]8e6441ca2010-08-19 05:56:38109}
110
ttuttled9dbc652015-09-29 20:00:59111bool HttpBasicStream::GetRemoteEndpoint(IPEndPoint* endpoint) {
112 if (!state_.connection() || !state_.connection()->socket())
113 return false;
114
115 return state_.connection()->socket()->GetPeerAddress(endpoint) == OK;
116}
117
nharper78e6d2b2016-09-21 05:42:35118Error HttpBasicStream::GetTokenBindingSignature(crypto::ECPrivateKey* key,
119 TokenBindingType tb_type,
120 std::vector<uint8_t>* out) {
121 return parser()->GetTokenBindingSignature(key, tb_type, out);
nharperb7441ef2016-01-25 23:54:14122}
123
[email protected]5a60c8b2011-10-19 20:14:29124void HttpBasicStream::Drain(HttpNetworkSession* session) {
125 HttpResponseBodyDrainer* drainer = new HttpResponseBodyDrainer(this);
126 drainer->Start(session);
127 // |drainer| will delete itself.
128}
129
zhongyi2ed4a6a2016-02-26 19:45:42130void HttpBasicStream::PopulateNetErrorDetails(NetErrorDetails* details) {
mmenke8210acc2016-07-11 16:34:52131 // TODO(mmenke): Consumers don't actually care about HTTP version, but seems
132 // like the right version should be reported, if headers were received.
133 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP1_1;
zhongyica364fbb2015-12-12 03:39:12134 return;
135}
136
[email protected]e86839fd2013-08-14 18:29:03137void HttpBasicStream::SetPriority(RequestPriority priority) {
138 // TODO(akalin): Plumb this through to |connection_|.
139}
140
[email protected]0877e3d2009-10-17 22:29:57141} // namespace net