diff options
Diffstat (limited to 'net/http/http_stream.h')
-rw-r--r-- | net/http/http_stream.h | 81 |
1 files changed, 52 insertions, 29 deletions
diff --git a/net/http/http_stream.h b/net/http/http_stream.h index 361edb0..d0b9dc9 100644 --- a/net/http/http_stream.h +++ b/net/http/http_stream.h @@ -6,50 +6,73 @@ // keeps the client agnostic of the actual underlying transport layer. This // provides an abstraction for both a basic http stream as well as http // pipelining implementations. -// -// NOTE(willchan): This interface is a work in progress. It will most likely -// change, since for a pipelining implementation, the stream needs to contain -// the http parsing code. For symmetry, the writing methods will probably -// contain the code for constructing http requests. #ifndef NET_HTTP_HTTP_STREAM_H_ #define NET_HTTP_HTTP_STREAM_H_ +#include <string> + #include "base/basictypes.h" -#include "net/base/completion_callback.h" +#include "net/socket/client_socket_handle.h" namespace net { +class HttpRequestInfo; +class HttpResponseInfo; class IOBuffer; +class UploadDataStream; class HttpStream { public: HttpStream() {} virtual ~HttpStream() {} - // Reads data, up to buf_len bytes, from the socket. The number of bytes - // read is returned, or an error is returned upon failure. Zero is returned - // to indicate end-of-file. ERR_IO_PENDING is returned if the operation - // could not be completed synchronously, in which case the result will be - // passed to the callback when available. If the operation is not completed - // immediately, the socket acquires a reference to the provided buffer until - // the callback is invoked or the socket is destroyed. - virtual int Read(IOBuffer* buf, - int buf_len, - CompletionCallback* callback) = 0; - - // Writes data, up to buf_len bytes, to the socket. Note: only part of the - // data may be written! The number of bytes written is returned, or an error - // is returned upon failure. ERR_IO_PENDING is returned if the operation - // could not be completed synchronously, in which case the result will be - // passed to the callback when available. If the operation is not completed - // immediately, the socket acquires a reference to the provided buffer until - // the callback is invoked or the socket is destroyed. - // Implementations of this method should not modify the contents of the actual - // buffer that is written to the socket. - virtual int Write(IOBuffer* buf, - int buf_len, - CompletionCallback* callback) = 0; + // Writes the headers and uploads body data to the underlying socket. + // ERR_IO_PENDING is returned if the operation could not be completed + // synchronously, in which case the result will be passed to the callback + // when available. Returns OK on success. The HttpStream takes ownership + // of the request_body. + virtual int SendRequest(const HttpRequestInfo* request, + const std::string& request_headers, + UploadDataStream* request_body, + CompletionCallback* callback) = 0; + + // Queries the UploadDataStream for its progress (bytes sent). + virtual uint64 GetUploadProgress() const = 0; + + // Reads from the underlying socket until the response headers have been + // completely received. ERR_IO_PENDING is returned if the operation could + // not be completed synchronously, in which case the result will be passed + // to the callback when available. Returns OK on success. The response + // headers are available in the HttpResponseInfo returned by GetResponseInfo + virtual int ReadResponseHeaders(CompletionCallback* callback) = 0; + + // Provides access to HttpResponseInfo (owned by HttpStream). + virtual HttpResponseInfo* GetResponseInfo() const = 0; + + // Reads response body data, up to |buf_len| bytes. The number of bytes read + // is returned, or an error is returned upon failure. ERR_CONNECTION_CLOSED + // is returned to indicate end-of-connection. ERR_IO_PENDING is returned if + // the operation could not be completed synchronously, in which case the + // result will be passed to the callback when available. If the operation is + // not completed immediately, the socket acquires a reference to the provided + // buffer until the callback is invoked or the socket is destroyed. + virtual int ReadResponseBody(IOBuffer* buf, int buf_len, + CompletionCallback* callback) = 0; + + // Indicates if the response body has been completely read. + virtual bool IsResponseBodyComplete() const = 0; + + // Indicates that the end of the response is detectable. This means that + // the response headers indicate either chunked encoding or content length. + // If neither is sent, the server must close the connection for us to detect + // the end of the response. + virtual bool CanFindEndOfResponse() const = 0; + + // After the response headers have been read and after the response body + // is complete, this function indicates if more data (either erroneous or + // as part of the next pipelined response) has been read from the socket. + virtual bool IsMoreDataBuffered() const = 0; private: DISALLOW_COPY_AND_ASSIGN(HttpStream); |