[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 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_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 11 | #pragma once |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 12 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 13 | #include <string> |
| 14 | |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 15 | #include "base/basictypes.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 16 | #include "base/memory/scoped_ptr.h" |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 17 | #include "net/http/http_stream.h" |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 18 | |
| 19 | namespace net { |
| 20 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 21 | class BoundNetLog; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 22 | class ClientSocketHandle; |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 23 | class GrowableIOBuffer; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 24 | class HttpResponseInfo; |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 25 | struct HttpRequestInfo; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 26 | class HttpRequestHeaders; |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 27 | class HttpStreamParser; |
| 28 | class IOBuffer; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 29 | class UploadDataStream; |
| 30 | |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 31 | class HttpBasicStream : public HttpStream { |
| 32 | public: |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 33 | // Constructs a new HttpBasicStream. If |parser| is NULL, then |
| 34 | // InitializeStream should be called to initialize it correctly. If |
| 35 | // |parser| is non-null, then InitializeStream should not be called, |
| 36 | // as the stream is already initialized. |
| 37 | HttpBasicStream(ClientSocketHandle* connection, |
| 38 | HttpStreamParser* parser, |
| 39 | bool using_proxy); |
[email protected] | 6d22a97 | 2010-07-21 15:47:19 | [diff] [blame] | 40 | virtual ~HttpBasicStream(); |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 41 | |
| 42 | // HttpStream methods: |
[email protected] | c638a85a | 2010-07-29 18:41:40 | [diff] [blame] | 43 | virtual int InitializeStream(const HttpRequestInfo* request_info, |
| 44 | const BoundNetLog& net_log, |
[email protected] | f1f3f0f8 | 2011-10-01 20:38:10 | [diff] [blame] | 45 | OldCompletionCallback* callback) OVERRIDE; |
[email protected] | c638a85a | 2010-07-29 18:41:40 | [diff] [blame] | 46 | |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 47 | virtual int SendRequest(const HttpRequestHeaders& headers, |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 48 | UploadDataStream* request_body, |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 49 | HttpResponseInfo* response, |
[email protected] | f1f3f0f8 | 2011-10-01 20:38:10 | [diff] [blame] | 50 | OldCompletionCallback* callback) OVERRIDE; |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 51 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 52 | virtual uint64 GetUploadProgress() const OVERRIDE; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 53 | |
[email protected] | f1f3f0f8 | 2011-10-01 20:38:10 | [diff] [blame] | 54 | virtual int ReadResponseHeaders(OldCompletionCallback* callback) OVERRIDE; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 55 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 56 | virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 57 | |
| 58 | virtual int ReadResponseBody(IOBuffer* buf, int buf_len, |
[email protected] | f1f3f0f8 | 2011-10-01 20:38:10 | [diff] [blame] | 59 | OldCompletionCallback* callback) OVERRIDE; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 60 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 61 | virtual void Close(bool not_reusable) OVERRIDE; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 62 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 63 | virtual HttpStream* RenewStreamForAuth() OVERRIDE; |
[email protected] | 697ef4c | 2010-10-14 16:38:58 | [diff] [blame] | 64 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 65 | virtual bool IsResponseBodyComplete() const OVERRIDE; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 66 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 67 | virtual bool CanFindEndOfResponse() const OVERRIDE; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 68 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 69 | virtual bool IsMoreDataBuffered() const OVERRIDE; |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 70 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 71 | virtual bool IsConnectionReused() const OVERRIDE; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 72 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 73 | virtual void SetConnectionReused() OVERRIDE; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 74 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 75 | virtual bool IsConnectionReusable() const OVERRIDE; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 76 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 77 | virtual void GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 78 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 79 | virtual void GetSSLCertRequestInfo( |
| 80 | SSLCertRequestInfo* cert_request_info) OVERRIDE; |
| 81 | |
| 82 | virtual bool IsSpdyHttpStream() const OVERRIDE; |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 83 | |
[email protected] | 5e6efa5 | 2011-06-27 17:26:41 | [diff] [blame] | 84 | virtual void LogNumRttVsBytesMetrics() const OVERRIDE; |
| 85 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame^] | 86 | virtual void Drain(HttpNetworkSession* session) OVERRIDE; |
| 87 | |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 88 | private: |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 89 | scoped_refptr<GrowableIOBuffer> read_buf_; |
| 90 | |
| 91 | scoped_ptr<HttpStreamParser> parser_; |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 92 | |
[email protected] | 4d4a516 | 2010-09-21 22:44:04 | [diff] [blame] | 93 | scoped_ptr<ClientSocketHandle> connection_; |
[email protected] | c638a85a | 2010-07-29 18:41:40 | [diff] [blame] | 94 | |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 95 | bool using_proxy_; |
| 96 | |
| 97 | std::string request_line_; |
| 98 | |
| 99 | const HttpRequestInfo* request_info_; |
| 100 | |
[email protected] | 5e6efa5 | 2011-06-27 17:26:41 | [diff] [blame] | 101 | const HttpResponseInfo* response_; |
| 102 | |
| 103 | int64 bytes_read_offset_; |
| 104 | |
[email protected] | 8d5a34e | 2009-06-11 21:21:36 | [diff] [blame] | 105 | DISALLOW_COPY_AND_ASSIGN(HttpBasicStream); |
| 106 | }; |
| 107 | |
| 108 | } // namespace net |
| 109 | |
| 110 | #endif // NET_HTTP_HTTP_BASIC_STREAM_H_ |