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 // HttpBasicStream is a simple implementation of HttpStream.  It assumes it is
      6 // not sharing a sharing with any other HttpStreams, therefore it just reads and
      7 // writes directly to the Http Stream.
      8 
      9 #ifndef NET_HTTP_HTTP_BASIC_STREAM_H_
     10 #define NET_HTTP_HTTP_BASIC_STREAM_H_
     11 
     12 #include <string>
     13 
     14 #include "base/basictypes.h"
     15 #include "net/http/http_stream.h"
     16 
     17 namespace net {
     18 
     19 class BoundNetLog;
     20 class ClientSocketHandle;
     21 class GrowableIOBuffer;
     22 class HttpResponseInfo;
     23 struct HttpRequestInfo;
     24 class HttpRequestHeaders;
     25 class HttpStreamParser;
     26 class IOBuffer;
     27 
     28 class HttpBasicStream : public HttpStream {
     29  public:
     30   // Constructs a new HttpBasicStream.  If |parser| is NULL, then
     31   // InitializeStream should be called to initialize it correctly.  If
     32   // |parser| is non-null, then InitializeStream should not be called,
     33   // as the stream is already initialized.
     34   HttpBasicStream(ClientSocketHandle* connection,
     35                   HttpStreamParser* parser,
     36                   bool using_proxy);
     37   virtual ~HttpBasicStream();
     38 
     39   // HttpStream methods:
     40   virtual int InitializeStream(const HttpRequestInfo* request_info,
     41                                RequestPriority priority,
     42                                const BoundNetLog& net_log,
     43                                const CompletionCallback& callback) OVERRIDE;
     44 
     45   virtual int SendRequest(const HttpRequestHeaders& headers,
     46                           HttpResponseInfo* response,
     47                           const CompletionCallback& callback) OVERRIDE;
     48 
     49   virtual UploadProgress GetUploadProgress() const OVERRIDE;
     50 
     51   virtual int ReadResponseHeaders(const CompletionCallback& callback) OVERRIDE;
     52 
     53   virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE;
     54 
     55   virtual int ReadResponseBody(IOBuffer* buf, int buf_len,
     56                                const CompletionCallback& callback) OVERRIDE;
     57 
     58   virtual void Close(bool not_reusable) OVERRIDE;
     59 
     60   virtual HttpStream* RenewStreamForAuth() OVERRIDE;
     61 
     62   virtual bool IsResponseBodyComplete() const OVERRIDE;
     63 
     64   virtual bool CanFindEndOfResponse() const OVERRIDE;
     65 
     66   virtual bool IsConnectionReused() const OVERRIDE;
     67 
     68   virtual void SetConnectionReused() OVERRIDE;
     69 
     70   virtual bool IsConnectionReusable() const OVERRIDE;
     71 
     72   virtual bool GetLoadTimingInfo(
     73       LoadTimingInfo* load_timing_info) const OVERRIDE;
     74 
     75   virtual void GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
     76 
     77   virtual void GetSSLCertRequestInfo(
     78       SSLCertRequestInfo* cert_request_info) OVERRIDE;
     79 
     80   virtual bool IsSpdyHttpStream() const OVERRIDE;
     81 
     82   virtual void Drain(HttpNetworkSession* session) OVERRIDE;
     83 
     84  private:
     85   scoped_refptr<GrowableIOBuffer> read_buf_;
     86 
     87   scoped_ptr<HttpStreamParser> parser_;
     88 
     89   scoped_ptr<ClientSocketHandle> connection_;
     90 
     91   bool using_proxy_;
     92 
     93   std::string request_line_;
     94 
     95   const HttpRequestInfo* request_info_;
     96 
     97   DISALLOW_COPY_AND_ASSIGN(HttpBasicStream);
     98 };
     99 
    100 }  // namespace net
    101 
    102 #endif  // NET_HTTP_HTTP_BASIC_STREAM_H_
    103