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 #include <string_view> 18 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 is_for_get_to_http_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 int GetRemoteEndpoint(IPEndPoint* endpoint) override; 89 90 void Drain(HttpNetworkSession* session) override; 91 92 void PopulateNetErrorDetails(NetErrorDetails* details) override; 93 94 void SetPriority(RequestPriority priority) override; 95 96 void SetRequestHeadersCallback(RequestHeadersCallback callback) override; 97 98 const std::set<std::string>& GetDnsAliases() const override; 99 100 std::string_view GetAcceptChViaAlps() const override; 101 102 private: parser()103 HttpStreamParser* parser() const { return state_.parser(); } 104 105 void OnHandshakeConfirmed(CompletionOnceCallback callback, int rv); 106 107 HttpBasicState state_; 108 base::TimeTicks confirm_handshake_end_; 109 RequestHeadersCallback request_headers_callback_; 110 // The request to send. 111 // Set to null before the response body is read. This is to allow |this| to 112 // be shared for reading and to possibly outlive request_info_'s owner. 113 // Setting to null happens after headers are completely read or upload data 114 // stream is uploaded, whichever is later. 115 raw_ptr<const HttpRequestInfo> request_info_; 116 }; 117 118 } // namespace net 119 120 #endif // NET_HTTP_HTTP_BASIC_STREAM_H_ 121