• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 // A class that stores the common state between HttpBasicStream and
6 // WebSocketBasicHandshakeStream.
7 
8 #ifndef NET_HTTP_HTTP_BASIC_STATE_H_
9 #define NET_HTTP_HTTP_BASIC_STATE_H_
10 
11 #include <memory>
12 #include <set>
13 #include <string>
14 
15 #include "base/memory/scoped_refptr.h"
16 #include "net/base/net_export.h"
17 #include "net/base/request_priority.h"
18 #include "net/traffic_annotation/network_traffic_annotation.h"
19 #include "url/gurl.h"
20 
21 namespace net {
22 
23 class StreamSocketHandle;
24 class GrowableIOBuffer;
25 class IPEndPoint;
26 class HttpStreamParser;
27 struct HttpRequestInfo;
28 struct LoadTimingInfo;
29 class NetLogWithSource;
30 class SSLInfo;
31 
32 class NET_EXPORT_PRIVATE HttpBasicState {
33  public:
34   HttpBasicState(std::unique_ptr<StreamSocketHandle> connection,
35                  bool is_for_get_to_http_proxy);
36 
37   HttpBasicState(const HttpBasicState&) = delete;
38   HttpBasicState& operator=(const HttpBasicState&) = delete;
39 
40   ~HttpBasicState();
41 
42   // Initialize() must be called before using any of the other methods.
43   void Initialize(const HttpRequestInfo* request_info,
44                   RequestPriority priority,
45                   const NetLogWithSource& net_log);
46 
47   // Called when the owner of `this` is closed.
48   void Close(bool not_reusable);
49 
parser()50   HttpStreamParser* parser() const { return parser_.get(); }
51 
52   // Returns true if this request is a non-tunneled HTTP request via a proxy.
is_for_get_to_http_proxy()53   bool is_for_get_to_http_proxy() const { return is_for_get_to_http_proxy_; }
54 
connection()55   StreamSocketHandle* connection() const { return connection_.get(); }
56 
57   std::unique_ptr<StreamSocketHandle> ReleaseConnection();
58 
59   scoped_refptr<GrowableIOBuffer> read_buf() const;
60 
61   // Generates a string of the form "METHOD PATH HTTP/1.1\r\n", based on the
62   // values of request_info_ and is_for_get_to_http_proxy_.
63   std::string GenerateRequestLine() const;
64 
traffic_annotation()65   MutableNetworkTrafficAnnotationTag traffic_annotation() {
66     return traffic_annotation_;
67   }
68 
69   // Returns true if the connection has been "reused" as defined by HttpStream -
70   // either actually reused, or has not been used yet, but has been idle for
71   // some time.
72   //
73   // TODO(mmenke): Consider renaming this concept, to avoid confusion with
74   // ClientSocketHandle::is_reused().
75   bool IsConnectionReused() const;
76   void SetConnectionReused();
77 
78   // Returns true if the connection can be "reused" as defined by
79   // HttpStreamParser.
80   //
81   // TODO(crbug.com/346835898): Consider renaming this concept, to avoid
82   // confusion with above IsConnectionReused() and ClientSocketHandle.
83   bool CanReuseConnection() const;
84 
85   bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const;
86 
87   void GetSSLInfo(SSLInfo* ssl_info);
88 
89   int GetRemoteEndpoint(IPEndPoint* endpoint);
90 
91   // Retrieves any DNS aliases for the remote endpoint. Includes all known
92   // aliases, e.g. from A, AAAA, or HTTPS, not just from the address used for
93   // the connection, in no particular order.
94   const std::set<std::string>& GetDnsAliases() const;
95 
96  private:
97   scoped_refptr<GrowableIOBuffer> read_buf_;
98 
99   std::unique_ptr<StreamSocketHandle> connection_;
100 
101   std::unique_ptr<HttpStreamParser> parser_;
102 
103   const bool is_for_get_to_http_proxy_;
104 
105   MutableNetworkTrafficAnnotationTag traffic_annotation_;
106 };
107 
108 }  // namespace net
109 
110 #endif  // NET_HTTP_HTTP_BASIC_STATE_H_
111