http_basic_stream.h 3.7 KB

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