OLD | NEW |
(Empty) | |
| 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 #ifndef NET_QUIC_QUIC_HTTP_STREAM_H_ |
| 6 #define NET_QUIC_QUIC_HTTP_STREAM_H_ |
| 7 |
| 8 #include <list> |
| 9 |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "net/base/io_buffer.h" |
| 12 #include "net/http/http_stream.h" |
| 13 #include "net/quic/quic_reliable_client_stream.h" |
| 14 |
| 15 namespace net { |
| 16 |
| 17 // The QuicHttpStream is a QUIC-specific HttpStream subclass. It holds a |
| 18 // non-owning pointer to a QuicReliableClientStream which it uses to |
| 19 // send and receive data. |
| 20 class NET_EXPORT_PRIVATE QuicHttpStream : |
| 21 public QuicReliableClientStream::Delegate, |
| 22 public HttpStream { |
| 23 public: |
| 24 explicit QuicHttpStream(QuicReliableClientStream* stream); |
| 25 |
| 26 virtual ~QuicHttpStream(); |
| 27 |
| 28 // HttpStream implementation. |
| 29 virtual int InitializeStream(const HttpRequestInfo* request_info, |
| 30 const BoundNetLog& net_log, |
| 31 const CompletionCallback& callback) OVERRIDE; |
| 32 virtual int SendRequest(const HttpRequestHeaders& request_headers, |
| 33 HttpResponseInfo* response, |
| 34 const CompletionCallback& callback) OVERRIDE; |
| 35 virtual UploadProgress GetUploadProgress() const OVERRIDE; |
| 36 virtual int ReadResponseHeaders(const CompletionCallback& callback) OVERRIDE; |
| 37 virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE; |
| 38 virtual int ReadResponseBody(IOBuffer* buf, |
| 39 int buf_len, |
| 40 const CompletionCallback& callback) OVERRIDE; |
| 41 virtual void Close(bool not_reusable) OVERRIDE; |
| 42 virtual HttpStream* RenewStreamForAuth() OVERRIDE; |
| 43 virtual bool IsResponseBodyComplete() const OVERRIDE; |
| 44 virtual bool CanFindEndOfResponse() const OVERRIDE; |
| 45 virtual bool IsMoreDataBuffered() const OVERRIDE; |
| 46 virtual bool IsConnectionReused() const OVERRIDE; |
| 47 virtual void SetConnectionReused() OVERRIDE; |
| 48 virtual bool IsConnectionReusable() const OVERRIDE; |
| 49 virtual void GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; |
| 50 virtual void GetSSLCertRequestInfo( |
| 51 SSLCertRequestInfo* cert_request_info) OVERRIDE; |
| 52 virtual bool IsSpdyHttpStream() const OVERRIDE; |
| 53 virtual void LogNumRttVsBytesMetrics() const OVERRIDE {} |
| 54 virtual void Drain(HttpNetworkSession* session) OVERRIDE; |
| 55 |
| 56 // QuicReliableClientStream::Delegate implementation |
| 57 virtual int OnSendData() OVERRIDE; |
| 58 virtual int OnSendDataComplete(int status, bool* eof) OVERRIDE; |
| 59 virtual int OnDataReceived(const char* data, int length) OVERRIDE; |
| 60 virtual void OnClose(QuicErrorCode error) OVERRIDE; |
| 61 |
| 62 private: |
| 63 enum State { |
| 64 STATE_NONE, |
| 65 STATE_SEND_HEADERS, |
| 66 STATE_SEND_HEADERS_COMPLETE, |
| 67 STATE_READ_REQUEST_BODY, |
| 68 STATE_READ_REQUEST_BODY_COMPLETE, |
| 69 STATE_SEND_BODY, |
| 70 STATE_SEND_BODY_COMPLETE, |
| 71 STATE_OPEN, |
| 72 }; |
| 73 |
| 74 void OnIOComplete(int rv); |
| 75 void DoCallback(int rv); |
| 76 |
| 77 int DoLoop(int); |
| 78 int DoSendHeaders(); |
| 79 int DoSendHeadersComplete(int rv); |
| 80 int DoReadRequestBody(); |
| 81 int DoReadRequestBodyComplete(int rv); |
| 82 int DoSendBody(); |
| 83 int DoSendBodyComplete(int rv); |
| 84 int DoReadResponseHeaders(); |
| 85 int DoReadResponseHeadersComplete(int rv); |
| 86 |
| 87 int ParseResponseHeaders(); |
| 88 |
| 89 void BufferResponseBody(const char* data, int length); |
| 90 |
| 91 State io_state_; |
| 92 |
| 93 QuicReliableClientStream* stream_; // Non-owning. |
| 94 |
| 95 // The following three fields are all owned by the caller and must |
| 96 // outlive this object, according to the HttpStream contract. |
| 97 |
| 98 // The request to send. |
| 99 const HttpRequestInfo* request_info_; |
| 100 // The request body to send, if any, owned by the caller. |
| 101 UploadDataStream* request_body_stream_; |
| 102 // |response_info_| is the HTTP response data object which is filled in |
| 103 // when a the response headers are read. It is not owned by this stream. |
| 104 HttpResponseInfo* response_info_; |
| 105 |
| 106 bool response_headers_received_; |
| 107 |
| 108 // Serialized HTTP request. |
| 109 std::string request_; |
| 110 |
| 111 // Buffer into which response header data is read. |
| 112 scoped_refptr<GrowableIOBuffer> read_buf_; |
| 113 |
| 114 // We buffer the response body as it arrives asynchronously from the stream. |
| 115 // TODO(rch): This is infinite buffering, which is bad. |
| 116 std::list<scoped_refptr<IOBufferWithSize> > response_body_; |
| 117 |
| 118 // The caller's callback to be used for asynchronous operations. |
| 119 CompletionCallback callback_; |
| 120 |
| 121 // Caller provided buffer for the ReadResponseBody() response. |
| 122 scoped_refptr<IOBuffer> user_buffer_; |
| 123 int user_buffer_len_; |
| 124 |
| 125 // Temporary buffer used to read the request body from UploadDataStream. |
| 126 scoped_refptr<IOBufferWithSize> raw_request_body_buf_; |
| 127 // Wraps raw_request_body_buf_ to read the remaining data progressively. |
| 128 scoped_refptr<DrainableIOBuffer> request_body_buf_; |
| 129 |
| 130 base::WeakPtrFactory<QuicHttpStream> weak_factory_; |
| 131 }; |
| 132 |
| 133 } // namespace net |
| 134 |
| 135 #endif // NET_QUIC_QUIC_HTTP_STREAM_H_ |
OLD | NEW |