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_pipelined_stream.h"
7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h"
9 #include "net/base/net_errors.h"
10 #include "net/http/http_pipelined_connection_impl.h"
11 #include "net/http/http_request_headers.h"
12 #include "net/http/http_request_info.h"
13 #include "net/http/http_util.h"
17 HttpPipelinedStream::HttpPipelinedStream(HttpPipelinedConnectionImpl
* pipeline
,
19 : pipeline_(pipeline
),
20 pipeline_id_(pipeline_id
),
24 HttpPipelinedStream::~HttpPipelinedStream() {
25 pipeline_
->OnStreamDeleted(pipeline_id_
);
28 int HttpPipelinedStream::InitializeStream(
29 const HttpRequestInfo
* request_info
,
30 RequestPriority priority
,
31 const BoundNetLog
& net_log
,
32 const CompletionCallback
& callback
) {
33 request_info_
= request_info
;
34 pipeline_
->InitializeParser(pipeline_id_
, request_info
, net_log
);
39 int HttpPipelinedStream::SendRequest(const HttpRequestHeaders
& headers
,
40 HttpResponseInfo
* response
,
41 const CompletionCallback
& callback
) {
44 // TODO(simonjam): Proxy support will be needed here.
45 const std::string path
= HttpUtil::PathForRequest(request_info_
->url
);
46 std::string request_line_
= base::StringPrintf("%s %s HTTP/1.1\r\n",
47 request_info_
->method
.c_str(),
49 return pipeline_
->SendRequest(pipeline_id_
, request_line_
, headers
, response
,
53 UploadProgress
HttpPipelinedStream::GetUploadProgress() const {
54 return pipeline_
->GetUploadProgress(pipeline_id_
);
57 int HttpPipelinedStream::ReadResponseHeaders(
58 const CompletionCallback
& callback
) {
59 return pipeline_
->ReadResponseHeaders(pipeline_id_
, callback
);
62 const HttpResponseInfo
* HttpPipelinedStream::GetResponseInfo() const {
63 return pipeline_
->GetResponseInfo(pipeline_id_
);
66 int HttpPipelinedStream::ReadResponseBody(IOBuffer
* buf
, int buf_len
,
67 const CompletionCallback
& callback
) {
68 return pipeline_
->ReadResponseBody(pipeline_id_
, buf
, buf_len
, callback
);
71 void HttpPipelinedStream::Close(bool not_reusable
) {
72 pipeline_
->Close(pipeline_id_
, not_reusable
);
75 HttpStream
* HttpPipelinedStream::RenewStreamForAuth() {
76 if (pipeline_
->usable()) {
77 return pipeline_
->CreateNewStream();
82 bool HttpPipelinedStream::IsResponseBodyComplete() const {
83 return pipeline_
->IsResponseBodyComplete(pipeline_id_
);
86 bool HttpPipelinedStream::CanFindEndOfResponse() const {
87 return pipeline_
->CanFindEndOfResponse(pipeline_id_
);
90 bool HttpPipelinedStream::IsConnectionReused() const {
91 return pipeline_
->IsConnectionReused(pipeline_id_
);
94 void HttpPipelinedStream::SetConnectionReused() {
95 pipeline_
->SetConnectionReused(pipeline_id_
);
98 bool HttpPipelinedStream::IsConnectionReusable() const {
99 return pipeline_
->usable();
102 bool HttpPipelinedStream::GetLoadTimingInfo(
103 LoadTimingInfo
* load_timing_info
) const {
104 return pipeline_
->GetLoadTimingInfo(pipeline_id_
, load_timing_info
);
107 void HttpPipelinedStream::GetSSLInfo(SSLInfo
* ssl_info
) {
108 pipeline_
->GetSSLInfo(pipeline_id_
, ssl_info
);
111 void HttpPipelinedStream::GetSSLCertRequestInfo(
112 SSLCertRequestInfo
* cert_request_info
) {
113 pipeline_
->GetSSLCertRequestInfo(pipeline_id_
, cert_request_info
);
116 bool HttpPipelinedStream::IsSpdyHttpStream() const {
120 void HttpPipelinedStream::Drain(HttpNetworkSession
* session
) {
121 pipeline_
->Drain(this, session
);
124 const SSLConfig
& HttpPipelinedStream::used_ssl_config() const {
125 return pipeline_
->used_ssl_config();
128 const ProxyInfo
& HttpPipelinedStream::used_proxy_info() const {
129 return pipeline_
->used_proxy_info();
132 const BoundNetLog
& HttpPipelinedStream::net_log() const {
133 return pipeline_
->net_log();
136 bool HttpPipelinedStream::was_npn_negotiated() const {
137 return pipeline_
->was_npn_negotiated();
140 NextProto
HttpPipelinedStream::protocol_negotiated() const {
141 return pipeline_
->protocol_negotiated();