Home | History | Annotate | Download | only in http
      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.
      4 
      5 #include "net/http/http_pipelined_stream.h"
      6 
      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"
     14 
     15 namespace net {
     16 
     17 HttpPipelinedStream::HttpPipelinedStream(HttpPipelinedConnectionImpl* pipeline,
     18                                          int pipeline_id)
     19     : pipeline_(pipeline),
     20       pipeline_id_(pipeline_id),
     21       request_info_(NULL) {
     22 }
     23 
     24 HttpPipelinedStream::~HttpPipelinedStream() {
     25   pipeline_->OnStreamDeleted(pipeline_id_);
     26 }
     27 
     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);
     35   return OK;
     36 }
     37 
     38 
     39 int HttpPipelinedStream::SendRequest(const HttpRequestHeaders& headers,
     40                                      HttpResponseInfo* response,
     41                                      const CompletionCallback& callback) {
     42   CHECK(pipeline_id_);
     43   CHECK(request_info_);
     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(),
     48                                                  path.c_str());
     49   return pipeline_->SendRequest(pipeline_id_, request_line_, headers, response,
     50                                 callback);
     51 }
     52 
     53 UploadProgress HttpPipelinedStream::GetUploadProgress() const {
     54   return pipeline_->GetUploadProgress(pipeline_id_);
     55 }
     56 
     57 int HttpPipelinedStream::ReadResponseHeaders(
     58     const CompletionCallback& callback) {
     59   return pipeline_->ReadResponseHeaders(pipeline_id_, callback);
     60 }
     61 
     62 const HttpResponseInfo* HttpPipelinedStream::GetResponseInfo() const {
     63   return pipeline_->GetResponseInfo(pipeline_id_);
     64 }
     65 
     66 int HttpPipelinedStream::ReadResponseBody(IOBuffer* buf, int buf_len,
     67                                           const CompletionCallback& callback) {
     68   return pipeline_->ReadResponseBody(pipeline_id_, buf, buf_len, callback);
     69 }
     70 
     71 void HttpPipelinedStream::Close(bool not_reusable) {
     72   pipeline_->Close(pipeline_id_, not_reusable);
     73 }
     74 
     75 HttpStream* HttpPipelinedStream::RenewStreamForAuth() {
     76   if (pipeline_->usable()) {
     77     return pipeline_->CreateNewStream();
     78   }
     79   return NULL;
     80 }
     81 
     82 bool HttpPipelinedStream::IsResponseBodyComplete() const {
     83   return pipeline_->IsResponseBodyComplete(pipeline_id_);
     84 }
     85 
     86 bool HttpPipelinedStream::CanFindEndOfResponse() const {
     87   return pipeline_->CanFindEndOfResponse(pipeline_id_);
     88 }
     89 
     90 bool HttpPipelinedStream::IsConnectionReused() const {
     91   return pipeline_->IsConnectionReused(pipeline_id_);
     92 }
     93 
     94 void HttpPipelinedStream::SetConnectionReused() {
     95   pipeline_->SetConnectionReused(pipeline_id_);
     96 }
     97 
     98 bool HttpPipelinedStream::IsConnectionReusable() const {
     99   return pipeline_->usable();
    100 }
    101 
    102 int64 HttpPipelinedStream::GetTotalReceivedBytes() const {
    103   return pipeline_->GetTotalReceivedBytes(pipeline_id_);
    104 }
    105 
    106 bool HttpPipelinedStream::GetLoadTimingInfo(
    107     LoadTimingInfo* load_timing_info) const {
    108   return pipeline_->GetLoadTimingInfo(pipeline_id_, load_timing_info);
    109 }
    110 
    111 void HttpPipelinedStream::GetSSLInfo(SSLInfo* ssl_info) {
    112   pipeline_->GetSSLInfo(pipeline_id_, ssl_info);
    113 }
    114 
    115 void HttpPipelinedStream::GetSSLCertRequestInfo(
    116     SSLCertRequestInfo* cert_request_info) {
    117   pipeline_->GetSSLCertRequestInfo(pipeline_id_, cert_request_info);
    118 }
    119 
    120 bool HttpPipelinedStream::IsSpdyHttpStream() const {
    121   return false;
    122 }
    123 
    124 void HttpPipelinedStream::Drain(HttpNetworkSession* session) {
    125   pipeline_->Drain(this, session);
    126 }
    127 
    128 void HttpPipelinedStream::SetPriority(RequestPriority priority) {
    129   // TODO(akalin): Plumb this through to |pipeline_| and its
    130   // underlying ClientSocketHandle.
    131 }
    132 
    133 const SSLConfig& HttpPipelinedStream::used_ssl_config() const {
    134   return pipeline_->used_ssl_config();
    135 }
    136 
    137 const ProxyInfo& HttpPipelinedStream::used_proxy_info() const {
    138   return pipeline_->used_proxy_info();
    139 }
    140 
    141 const BoundNetLog& HttpPipelinedStream::net_log() const {
    142   return pipeline_->net_log();
    143 }
    144 
    145 bool HttpPipelinedStream::was_npn_negotiated() const {
    146   return pipeline_->was_npn_negotiated();
    147 }
    148 
    149 NextProto HttpPipelinedStream::protocol_negotiated() const {
    150   return pipeline_->protocol_negotiated();
    151 }
    152 
    153 }  // namespace net
    154