| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // HttpStream is an interface for reading and writing data to an HttpStream that | 5 // HttpStream is an interface for reading and writing data to an HttpStream that |
| 6 // keeps the client agnostic of the actual underlying transport layer. This | 6 // keeps the client agnostic of the actual underlying transport layer. This |
| 7 // provides an abstraction for both a basic http stream as well as http | 7 // provides an abstraction for both a basic http stream as well as http |
| 8 // pipelining implementations. The HttpStream subtype is expected to manage the | 8 // pipelining implementations. The HttpStream subtype is expected to manage the |
| 9 // underlying transport appropriately. For example, a non-pipelined HttpStream | 9 // underlying transport appropriately. For example, a non-pipelined HttpStream |
| 10 // would return the transport socket to the pool for reuse. SPDY streams on the | 10 // would return the transport socket to the pool for reuse. SPDY streams on the |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 class NET_EXPORT_PRIVATE HttpStream { | 35 class NET_EXPORT_PRIVATE HttpStream { |
| 36 public: | 36 public: |
| 37 HttpStream() {} | 37 HttpStream() {} |
| 38 virtual ~HttpStream() {} | 38 virtual ~HttpStream() {} |
| 39 | 39 |
| 40 // Initialize stream. Must be called before calling SendRequest(). | 40 // Initialize stream. Must be called before calling SendRequest(). |
| 41 // Returns a net error code, possibly ERR_IO_PENDING. | 41 // Returns a net error code, possibly ERR_IO_PENDING. |
| 42 virtual int InitializeStream(const HttpRequestInfo* request_info, | 42 virtual int InitializeStream(const HttpRequestInfo* request_info, |
| 43 const BoundNetLog& net_log, | 43 const BoundNetLog& net_log, |
| 44 OldCompletionCallback* callback) = 0; | 44 const CompletionCallback& callback) = 0; |
| 45 | 45 |
| 46 // Writes the headers and uploads body data to the underlying socket. | 46 // Writes the headers and uploads body data to the underlying socket. |
| 47 // ERR_IO_PENDING is returned if the operation could not be completed | 47 // ERR_IO_PENDING is returned if the operation could not be completed |
| 48 // synchronously, in which case the result will be passed to the callback | 48 // synchronously, in which case the result will be passed to the callback |
| 49 // when available. Returns OK on success. The HttpStream takes ownership | 49 // when available. Returns OK on success. The HttpStream takes ownership |
| 50 // of the request_body. | 50 // of the request_body. |
| 51 virtual int SendRequest(const HttpRequestHeaders& request_headers, | 51 virtual int SendRequest(const HttpRequestHeaders& request_headers, |
| 52 UploadDataStream* request_body, | 52 UploadDataStream* request_body, |
| 53 HttpResponseInfo* response, | 53 HttpResponseInfo* response, |
| 54 OldCompletionCallback* callback) = 0; | 54 const CompletionCallback& callback) = 0; |
| 55 | 55 |
| 56 // Queries the UploadDataStream for its progress (bytes sent). | 56 // Queries the UploadDataStream for its progress (bytes sent). |
| 57 virtual uint64 GetUploadProgress() const = 0; | 57 virtual uint64 GetUploadProgress() const = 0; |
| 58 | 58 |
| 59 // Reads from the underlying socket until the response headers have been | 59 // Reads from the underlying socket until the response headers have been |
| 60 // completely received. ERR_IO_PENDING is returned if the operation could | 60 // completely received. ERR_IO_PENDING is returned if the operation could |
| 61 // not be completed synchronously, in which case the result will be passed | 61 // not be completed synchronously, in which case the result will be passed |
| 62 // to the callback when available. Returns OK on success. The response | 62 // to the callback when available. Returns OK on success. The response |
| 63 // headers are available in the HttpResponseInfo returned by GetResponseInfo | 63 // headers are available in the HttpResponseInfo returned by GetResponseInfo |
| 64 virtual int ReadResponseHeaders(OldCompletionCallback* callback) = 0; | 64 virtual int ReadResponseHeaders(const CompletionCallback& callback) = 0; |
| 65 | 65 |
| 66 // Provides access to HttpResponseInfo (owned by HttpStream). | 66 // Provides access to HttpResponseInfo (owned by HttpStream). |
| 67 virtual const HttpResponseInfo* GetResponseInfo() const = 0; | 67 virtual const HttpResponseInfo* GetResponseInfo() const = 0; |
| 68 | 68 |
| 69 // Reads response body data, up to |buf_len| bytes. |buf_len| should be a | 69 // Reads response body data, up to |buf_len| bytes. |buf_len| should be a |
| 70 // reasonable size (<2MB). The number of bytes read is returned, or an | 70 // reasonable size (<2MB). The number of bytes read is returned, or an |
| 71 // error is returned upon failure. 0 indicates that the request has been | 71 // error is returned upon failure. 0 indicates that the request has been |
| 72 // fully satisfied and there is no more data to read. | 72 // fully satisfied and there is no more data to read. |
| 73 // ERR_CONNECTION_CLOSED is returned when the connection has been closed | 73 // ERR_CONNECTION_CLOSED is returned when the connection has been closed |
| 74 // prematurely. ERR_IO_PENDING is returned if the operation could not be | 74 // prematurely. ERR_IO_PENDING is returned if the operation could not be |
| 75 // completed synchronously, in which case the result will be passed to the | 75 // completed synchronously, in which case the result will be passed to the |
| 76 // callback when available. If the operation is not completed immediately, | 76 // callback when available. If the operation is not completed immediately, |
| 77 // the socket acquires a reference to the provided buffer until the callback | 77 // the socket acquires a reference to the provided buffer until the callback |
| 78 // is invoked or the socket is destroyed. | 78 // is invoked or the socket is destroyed. |
| 79 virtual int ReadResponseBody(IOBuffer* buf, int buf_len, | 79 virtual int ReadResponseBody(IOBuffer* buf, int buf_len, |
| 80 OldCompletionCallback* callback) = 0; | 80 const CompletionCallback& callback) = 0; |
| 81 | 81 |
| 82 // Closes the stream. | 82 // Closes the stream. |
| 83 // |not_reusable| indicates if the stream can be used for further requests. | 83 // |not_reusable| indicates if the stream can be used for further requests. |
| 84 // In the case of HTTP, where we re-use the byte-stream (e.g. the connection) | 84 // In the case of HTTP, where we re-use the byte-stream (e.g. the connection) |
| 85 // this means we need to close the connection; in the case of SPDY, where the | 85 // this means we need to close the connection; in the case of SPDY, where the |
| 86 // underlying stream is never reused, it has no effect. | 86 // underlying stream is never reused, it has no effect. |
| 87 // TODO(mbelshe): We should figure out how to fold the not_reusable flag | 87 // TODO(mbelshe): We should figure out how to fold the not_reusable flag |
| 88 // into the stream implementation itself so that the caller | 88 // into the stream implementation itself so that the caller |
| 89 // does not need to pass it at all. We might also be able to | 89 // does not need to pass it at all. We might also be able to |
| 90 // eliminate the SetConnectionReused() below. | 90 // eliminate the SetConnectionReused() below. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // draining is complete. | 146 // draining is complete. |
| 147 virtual void Drain(HttpNetworkSession* session) = 0; | 147 virtual void Drain(HttpNetworkSession* session) = 0; |
| 148 | 148 |
| 149 private: | 149 private: |
| 150 DISALLOW_COPY_AND_ASSIGN(HttpStream); | 150 DISALLOW_COPY_AND_ASSIGN(HttpStream); |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 } // namespace net | 153 } // namespace net |
| 154 | 154 |
| 155 #endif // NET_HTTP_HTTP_STREAM_H_ | 155 #endif // NET_HTTP_HTTP_STREAM_H_ |
| OLD | NEW |