1 // Copyright 2012 The Chromium Authors 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_ 11 12 #include <stdint.h> 13 14 #include <memory> 15 #include <set> 16 #include <string> 17 18 #include "base/strings/string_piece.h" 19 #include "base/time/time.h" 20 #include "net/base/completion_once_callback.h" 21 #include "net/base/net_export.h" 22 #include "net/http/http_basic_state.h" 23 #include "net/http/http_stream.h" 24 25 namespace net { 26 27 class ClientSocketHandle; 28 class HttpResponseInfo; 29 struct HttpRequestInfo; 30 class HttpRequestHeaders; 31 class HttpStreamParser; 32 class IOBuffer; 33 class NetLogWithSource; 34 35 class NET_EXPORT_PRIVATE HttpBasicStream : public HttpStream { 36 public: 37 // Constructs a new HttpBasicStream. InitializeStream must be called to 38 // initialize it correctly. 39 HttpBasicStream(std::unique_ptr<ClientSocketHandle> connection, 40 bool using_proxy); 41 42 HttpBasicStream(const HttpBasicStream&) = delete; 43 HttpBasicStream& operator=(const HttpBasicStream&) = delete; 44 45 ~HttpBasicStream() override; 46 47 // HttpStream methods: 48 void RegisterRequest(const HttpRequestInfo* request_info) override; 49 50 int InitializeStream(bool can_send_early, 51 RequestPriority priority, 52 const NetLogWithSource& net_log, 53 CompletionOnceCallback callback) override; 54 55 int SendRequest(const HttpRequestHeaders& headers, 56 HttpResponseInfo* response, 57 CompletionOnceCallback callback) override; 58 59 int ReadResponseHeaders(CompletionOnceCallback callback) override; 60 61 int ReadResponseBody(IOBuffer* buf, 62 int buf_len, 63 CompletionOnceCallback callback) override; 64 65 void Close(bool not_reusable) override; 66 67 std::unique_ptr<HttpStream> RenewStreamForAuth() override; 68 69 bool IsResponseBodyComplete() const override; 70 71 bool IsConnectionReused() const override; 72 73 void SetConnectionReused() override; 74 75 bool CanReuseConnection() const override; 76 77 int64_t GetTotalReceivedBytes() const override; 78 79 int64_t GetTotalSentBytes() const override; 80 81 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override; 82 83 bool GetAlternativeService( 84 AlternativeService* alternative_service) const override; 85 86 void GetSSLInfo(SSLInfo* ssl_info) override; 87 88 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override; 89 90 int GetRemoteEndpoint(IPEndPoint* endpoint) override; 91 92 void Drain(HttpNetworkSession* session) override; 93 94 void PopulateNetErrorDetails(NetErrorDetails* details) override; 95 96 void SetPriority(RequestPriority priority) override; 97 98 void SetRequestHeadersCallback(RequestHeadersCallback callback) override; 99 100 const std::set<std::string>& GetDnsAliases() const override; 101 102 base::StringPiece GetAcceptChViaAlps() const override; 103 104 private: parser()105 HttpStreamParser* parser() const { return state_.parser(); } 106 107 void OnHandshakeConfirmed(CompletionOnceCallback callback, int rv); 108 109 HttpBasicState state_; 110 base::TimeTicks confirm_handshake_end_; 111 RequestHeadersCallback request_headers_callback_; 112 // The request to send. 113 // Set to null before the response body is read. This is to allow |this| to 114 // be shared for reading and to possibly outlive request_info_'s owner. 115 // Setting to null happens after headers are completely read or upload data 116 // stream is uploaded, whichever is later. 117 raw_ptr<const HttpRequestInfo> request_info_; 118 }; 119 120 } // namespace net 121 122 #endif // NET_HTTP_HTTP_BASIC_STREAM_H_ 123