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