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_basic_stream.h"
      6 
      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"
     12 
     13 namespace net {
     14 
     15 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection,
     16                                  bool using_proxy)
     17     : state_(connection, using_proxy) {}
     18 
     19 HttpBasicStream::~HttpBasicStream() {}
     20 
     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);
     26   return OK;
     27 }
     28 
     29 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers,
     30                                  HttpResponseInfo* response,
     31                                  const CompletionCallback& callback) {
     32   DCHECK(parser());
     33   return parser()->SendRequest(
     34       state_.GenerateRequestLine(), headers, response, callback);
     35 }
     36 
     37 UploadProgress HttpBasicStream::GetUploadProgress() const {
     38   return parser()->GetUploadProgress();
     39 }
     40 
     41 int HttpBasicStream::ReadResponseHeaders(const CompletionCallback& callback) {
     42   return parser()->ReadResponseHeaders(callback);
     43 }
     44 
     45 const HttpResponseInfo* HttpBasicStream::GetResponseInfo() const {
     46   return parser()->GetResponseInfo();
     47 }
     48 
     49 int HttpBasicStream::ReadResponseBody(IOBuffer* buf,
     50                                       int buf_len,
     51                                       const CompletionCallback& callback) {
     52   return parser()->ReadResponseBody(buf, buf_len, callback);
     53 }
     54 
     55 void HttpBasicStream::Close(bool not_reusable) {
     56   parser()->Close(not_reusable);
     57 }
     58 
     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());
     68 }
     69 
     70 bool HttpBasicStream::IsResponseBodyComplete() const {
     71   return parser()->IsResponseBodyComplete();
     72 }
     73 
     74 bool HttpBasicStream::CanFindEndOfResponse() const {
     75   return parser()->CanFindEndOfResponse();
     76 }
     77 
     78 bool HttpBasicStream::IsConnectionReused() const {
     79   return parser()->IsConnectionReused();
     80 }
     81 
     82 void HttpBasicStream::SetConnectionReused() { parser()->SetConnectionReused(); }
     83 
     84 bool HttpBasicStream::IsConnectionReusable() const {
     85   return parser()->IsConnectionReusable();
     86 }
     87 
     88 int64 HttpBasicStream::GetTotalReceivedBytes() const {
     89   return parser()->received_bytes();
     90 }
     91 
     92 bool HttpBasicStream::GetLoadTimingInfo(
     93     LoadTimingInfo* load_timing_info) const {
     94   return state_.connection()->GetLoadTimingInfo(IsConnectionReused(),
     95                                                 load_timing_info);
     96 }
     97 
     98 void HttpBasicStream::GetSSLInfo(SSLInfo* ssl_info) {
     99   parser()->GetSSLInfo(ssl_info);
    100 }
    101 
    102 void HttpBasicStream::GetSSLCertRequestInfo(
    103     SSLCertRequestInfo* cert_request_info) {
    104   parser()->GetSSLCertRequestInfo(cert_request_info);
    105 }
    106 
    107 bool HttpBasicStream::IsSpdyHttpStream() const { return false; }
    108 
    109 void HttpBasicStream::Drain(HttpNetworkSession* session) {
    110   HttpResponseBodyDrainer* drainer = new HttpResponseBodyDrainer(this);
    111   drainer->Start(session);
    112   // |drainer| will delete itself.
    113 }
    114 
    115 void HttpBasicStream::SetPriority(RequestPriority priority) {
    116   // TODO(akalin): Plumb this through to |connection_|.
    117 }
    118 
    119 }  // namespace net
    120