File: http_basic_state.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (109 lines) | stat: -rw-r--r-- 3,392 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// A class that stores the common state between HttpBasicStream and
// WebSocketBasicHandshakeStream.

#ifndef NET_HTTP_HTTP_BASIC_STATE_H_
#define NET_HTTP_HTTP_BASIC_STATE_H_

#include <memory>
#include <set>
#include <string>

#include "base/memory/scoped_refptr.h"
#include "net/base/net_export.h"
#include "net/base/request_priority.h"
#include "net/traffic_annotation/network_traffic_annotation.h"

namespace net {

class StreamSocketHandle;
class GrowableIOBuffer;
class IPEndPoint;
class HttpStreamParser;
struct HttpRequestInfo;
struct LoadTimingInfo;
class NetLogWithSource;
class SSLInfo;

class NET_EXPORT_PRIVATE HttpBasicState {
 public:
  HttpBasicState(std::unique_ptr<StreamSocketHandle> connection,
                 bool is_for_get_to_http_proxy);

  HttpBasicState(const HttpBasicState&) = delete;
  HttpBasicState& operator=(const HttpBasicState&) = delete;

  ~HttpBasicState();

  // Initialize() must be called before using any of the other methods.
  void Initialize(const HttpRequestInfo* request_info,
                  RequestPriority priority,
                  const NetLogWithSource& net_log);

  // Called when the owner of `this` is closed.
  void Close(bool not_reusable);

  HttpStreamParser* parser() const { return parser_.get(); }

  // Returns true if this request is a non-tunneled HTTP request via a proxy.
  bool is_for_get_to_http_proxy() const { return is_for_get_to_http_proxy_; }

  StreamSocketHandle* connection() const { return connection_.get(); }

  std::unique_ptr<StreamSocketHandle> ReleaseConnection();

  scoped_refptr<GrowableIOBuffer> read_buf() const;

  // Generates a string of the form "METHOD PATH HTTP/1.1\r\n", based on the
  // values of request_info_ and is_for_get_to_http_proxy_.
  std::string GenerateRequestLine() const;

  MutableNetworkTrafficAnnotationTag traffic_annotation() {
    return traffic_annotation_;
  }

  // Returns true if the connection has been "reused" as defined by HttpStream -
  // either actually reused, or has not been used yet, but has been idle for
  // some time.
  //
  // TODO(mmenke): Consider renaming this concept, to avoid confusion with
  // ClientSocketHandle::is_reused().
  bool IsConnectionReused() const;
  void SetConnectionReused();

  // Returns true if the connection can be "reused" as defined by
  // HttpStreamParser.
  //
  // TODO(crbug.com/346835898): Consider renaming this concept, to avoid
  // confusion with above IsConnectionReused() and ClientSocketHandle.
  bool CanReuseConnection() const;

  bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const;

  void GetSSLInfo(SSLInfo* ssl_info);

  int GetRemoteEndpoint(IPEndPoint* endpoint);

  // Retrieves any DNS aliases for the remote endpoint. Includes all known
  // aliases, e.g. from A, AAAA, or HTTPS, not just from the address used for
  // the connection, in no particular order.
  const std::set<std::string>& GetDnsAliases() const;

 private:
  scoped_refptr<GrowableIOBuffer> read_buf_;

  std::unique_ptr<StreamSocketHandle> connection_;

  std::unique_ptr<HttpStreamParser> parser_;

  const bool is_for_get_to_http_proxy_;

  MutableNetworkTrafficAnnotationTag traffic_annotation_;
};

}  // namespace net

#endif  // NET_HTTP_HTTP_BASIC_STATE_H_