• 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 ClientSocketHandle;
24 class GrowableIOBuffer;
25 class HttpStreamParser;
26 struct HttpRequestInfo;
27 class NetLogWithSource;
28 
29 class NET_EXPORT_PRIVATE HttpBasicState {
30  public:
31   HttpBasicState(std::unique_ptr<ClientSocketHandle> connection,
32                  bool using_proxy);
33 
34   HttpBasicState(const HttpBasicState&) = delete;
35   HttpBasicState& operator=(const HttpBasicState&) = delete;
36 
37   ~HttpBasicState();
38 
39   // Initialize() must be called before using any of the other methods.
40   void Initialize(const HttpRequestInfo* request_info,
41                   RequestPriority priority,
42                   const NetLogWithSource& net_log);
43 
parser()44   HttpStreamParser* parser() const { return parser_.get(); }
45 
using_proxy()46   bool using_proxy() const { return using_proxy_; }
47 
48   // Deletes |parser_| and sets it to NULL.
49   void DeleteParser();
50 
connection()51   ClientSocketHandle* connection() const { return connection_.get(); }
52 
53   std::unique_ptr<ClientSocketHandle> ReleaseConnection();
54 
55   scoped_refptr<GrowableIOBuffer> read_buf() const;
56 
57   // Generates a string of the form "METHOD PATH HTTP/1.1\r\n", based on the
58   // values of request_info_ and using_proxy_.
59   std::string GenerateRequestLine() const;
60 
traffic_annotation()61   MutableNetworkTrafficAnnotationTag traffic_annotation() {
62     return traffic_annotation_;
63   }
64 
65   // Returns true if the connection has been "reused" as defined by HttpStream -
66   // either actually reused, or has not been used yet, but has been idle for
67   // some time.
68   //
69   // TODO(mmenke): Consider renaming this concept, to avoid confusion with
70   // ClientSocketHandle::is_reused().
71   bool IsConnectionReused() const;
72 
73   // Retrieves any DNS aliases for the remote endpoint. Includes all known
74   // aliases, e.g. from A, AAAA, or HTTPS, not just from the address used for
75   // the connection, in no particular order.
76   const std::set<std::string>& GetDnsAliases() const;
77 
78  private:
79   scoped_refptr<GrowableIOBuffer> read_buf_;
80 
81   std::unique_ptr<ClientSocketHandle> connection_;
82 
83   std::unique_ptr<HttpStreamParser> parser_;
84 
85   const bool using_proxy_;
86 
87   GURL url_;
88   std::string request_method_;
89 
90   MutableNetworkTrafficAnnotationTag traffic_annotation_;
91 };
92 
93 }  // namespace net
94 
95 #endif  // NET_HTTP_HTTP_BASIC_STATE_H_
96