summaryrefslogtreecommitdiffstats
path: root/netwerk/protocol/http/HttpTransactionShell.h
blob: 242e2a661bdee1a1eb6fab7fdfaee63b295bcf2b (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef HttpTransactionShell_h__
#define HttpTransactionShell_h__

#include <functional>

#include "TimingStruct.h"
#include "mozilla/Maybe.h"
#include "mozilla/UniquePtr.h"
#include "nsIClassOfService.h"
#include "nsIEarlyHintObserver.h"
#include "nsISupports.h"
#include "nsITransportSecurityInfo.h"
#include "nsInputStreamPump.h"

class nsIEventTraget;
class nsIInputStream;
class nsIInterfaceRequestor;
class nsIRequest;
class nsIRequestContext;
class nsITransportEventSink;

namespace mozilla::net {

enum HttpTrafficCategory : uint8_t;
class Http2PushedStreamWrapper;
class HttpTransactionParent;
class nsHttpConnectionInfo;
class nsHttpHeaderArray;
class nsHttpRequestHead;
class nsHttpTransaction;
class TransactionObserverResult;
union NetAddr;

//----------------------------------------------------------------------------
// Abstract base class for a HTTP transaction in the chrome process
//----------------------------------------------------------------------------

// 95e5a5b7-6aa2-4011-920a-0908b52f95d4
#define HTTPTRANSACTIONSHELL_IID                     \
  {                                                  \
    0x95e5a5b7, 0x6aa2, 0x4011, {                    \
      0x92, 0x0a, 0x09, 0x08, 0xb5, 0x2f, 0x95, 0xd4 \
    }                                                \
  }

class HttpTransactionShell : public nsISupports {
 public:
  NS_DECLARE_STATIC_IID_ACCESSOR(HTTPTRANSACTIONSHELL_IID)

  using TransactionObserverFunc =
      std::function<void(TransactionObserverResult&&)>;
  using OnPushCallback = std::function<nsresult(
      uint32_t, const nsACString&, const nsACString&, HttpTransactionShell*)>;

  //
  // called to initialize the transaction
  //
  // @param caps
  //        the transaction capabilities (see nsHttp.h)
  // @param connInfo
  //        the connection type for this transaction.
  // @param reqHeaders
  //        the request header struct
  // @param reqBody
  //        the request body (POST or PUT data stream)
  // @param reqBodyIncludesHeaders
  //        fun stuff to support NPAPI plugins.
  // @param target
  //        the dispatch target were notifications should be sent.
  // @param callbacks
  //        the notification callbacks to be given to PSM.
  // @param browserId
  //        indicate the id of the browser in which this transaction is being
  //        loaded.
  [[nodiscard]] nsresult virtual Init(
      uint32_t caps, nsHttpConnectionInfo* connInfo,
      nsHttpRequestHead* reqHeaders, nsIInputStream* reqBody,
      uint64_t reqContentLength, bool reqBodyIncludesHeaders,
      nsIEventTarget* consumerTarget, nsIInterfaceRequestor* callbacks,
      nsITransportEventSink* eventsink, uint64_t browserId,
      HttpTrafficCategory trafficCategory, nsIRequestContext* requestContext,
      ClassOfService classOfService, uint32_t initialRwin,
      bool responseTimeoutEnabled, uint64_t channelId,
      TransactionObserverFunc&& transactionObserver,
      OnPushCallback&& aOnPushCallback,
      HttpTransactionShell* aTransWithPushedStream,
      uint32_t aPushedStreamId) = 0;

  // @param aListener
  //        receives notifications.
  // @param pump
  //        the pump that will contain the response data. async wait on this
  //        input stream for data. On first notification, headers should be
  //        available (check transaction status).
  virtual nsresult AsyncRead(nsIStreamListener* listener,
                             nsIRequest** pump) = 0;

  // Called to take ownership of the response headers; the transaction
  // will drop any reference to the response headers after this call.
  virtual UniquePtr<nsHttpResponseHead> TakeResponseHead() = 0;

  // Called to take ownership of the trailer headers.
  // Returning null if there is no trailer.
  virtual UniquePtr<nsHttpHeaderArray> TakeResponseTrailers() = 0;

  virtual already_AddRefed<nsITransportSecurityInfo> SecurityInfo() = 0;
  virtual void SetSecurityCallbacks(nsIInterfaceRequestor* aCallbacks) = 0;

  virtual void GetNetworkAddresses(NetAddr& self, NetAddr& peer,
                                   bool& aResolvedByTRR,
                                   nsIRequest::TRRMode& aEffectiveTRRMode,
                                   TRRSkippedReason& aSkipReason,
                                   bool& aEchConfigUsed) = 0;

  // Functions for Timing interface
  virtual mozilla::TimeStamp GetDomainLookupStart() = 0;
  virtual mozilla::TimeStamp GetDomainLookupEnd() = 0;
  virtual mozilla::TimeStamp GetConnectStart() = 0;
  virtual mozilla::TimeStamp GetTcpConnectEnd() = 0;
  virtual mozilla::TimeStamp GetSecureConnectionStart() = 0;

  virtual mozilla::TimeStamp GetConnectEnd() = 0;
  virtual mozilla::TimeStamp GetRequestStart() = 0;
  virtual mozilla::TimeStamp GetResponseStart() = 0;
  virtual mozilla::TimeStamp GetResponseEnd() = 0;

  virtual void SetDomainLookupStart(mozilla::TimeStamp timeStamp,
                                    bool onlyIfNull = false) = 0;
  virtual void SetDomainLookupEnd(mozilla::TimeStamp timeStamp,
                                  bool onlyIfNull = false) = 0;

  virtual TimingStruct Timings() = 0;

  virtual mozilla::TimeStamp GetPendingTime() = 0;

  // Called to set/find out if the transaction generated a complete response.
  virtual bool ResponseIsComplete() = 0;
  virtual int64_t GetTransferSize() = 0;
  virtual int64_t GetRequestSize() = 0;
  virtual bool IsHttp3Used() = 0;

  // Called to notify that a requested DNS cache entry was refreshed.
  virtual void SetDNSWasRefreshed() = 0;

  virtual void DontReuseConnection() = 0;
  virtual bool HasStickyConnection() const = 0;

  virtual void SetH2WSConnRefTaken() = 0;

  virtual bool ProxyConnectFailed() = 0;
  virtual int32_t GetProxyConnectResponseCode() = 0;

  virtual bool DataSentToChildProcess() = 0;

  virtual nsHttpTransaction* AsHttpTransaction() = 0;
  virtual HttpTransactionParent* AsHttpTransactionParent() = 0;

  virtual bool TakeRestartedState() = 0;
  virtual uint32_t HTTPSSVCReceivedStage() = 0;

  virtual bool Http2Disabled() const = 0;
  virtual bool Http3Disabled() const = 0;
  virtual already_AddRefed<nsHttpConnectionInfo> GetConnInfo() const = 0;

  virtual bool GetSupportsHTTP3() = 0;

  virtual void SetIsForWebTransport(bool aIsForWebTransport) = 0;
};

NS_DEFINE_STATIC_IID_ACCESSOR(HttpTransactionShell, HTTPTRANSACTIONSHELL_IID)

#define NS_DECL_HTTPTRANSACTIONSHELL                                           \
  virtual nsresult Init(                                                       \
      uint32_t caps, nsHttpConnectionInfo* connInfo,                           \
      nsHttpRequestHead* reqHeaders, nsIInputStream* reqBody,                  \
      uint64_t reqContentLength, bool reqBodyIncludesHeaders,                  \
      nsIEventTarget* consumerTarget, nsIInterfaceRequestor* callbacks,        \
      nsITransportEventSink* eventsink, uint64_t browserId,                    \
      HttpTrafficCategory trafficCategory, nsIRequestContext* requestContext,  \
      ClassOfService classOfService, uint32_t initialRwin,                     \
      bool responseTimeoutEnabled, uint64_t channelId,                         \
      TransactionObserverFunc&& transactionObserver,                           \
      OnPushCallback&& aOnPushCallback,                                        \
      HttpTransactionShell* aTransWithPushedStream, uint32_t aPushedStreamId)  \
      override;                                                                \
  virtual nsresult AsyncRead(nsIStreamListener* listener, nsIRequest** pump)   \
      override;                                                                \
  virtual UniquePtr<nsHttpResponseHead> TakeResponseHead() override;           \
  virtual UniquePtr<nsHttpHeaderArray> TakeResponseTrailers() override;        \
  virtual already_AddRefed<nsITransportSecurityInfo> SecurityInfo() override;  \
  virtual void SetSecurityCallbacks(nsIInterfaceRequestor* aCallbacks)         \
      override;                                                                \
  virtual void GetNetworkAddresses(                                            \
      NetAddr& self, NetAddr& peer, bool& aResolvedByTRR,                      \
      nsIRequest::TRRMode& aEffectiveTRRMode, TRRSkippedReason& aSkipReason,   \
      bool& aEchConfigUsed) override;                                          \
  virtual mozilla::TimeStamp GetDomainLookupStart() override;                  \
  virtual mozilla::TimeStamp GetDomainLookupEnd() override;                    \
  virtual mozilla::TimeStamp GetConnectStart() override;                       \
  virtual mozilla::TimeStamp GetTcpConnectEnd() override;                      \
  virtual mozilla::TimeStamp GetSecureConnectionStart() override;              \
  virtual mozilla::TimeStamp GetConnectEnd() override;                         \
  virtual mozilla::TimeStamp GetRequestStart() override;                       \
  virtual mozilla::TimeStamp GetResponseStart() override;                      \
  virtual mozilla::TimeStamp GetResponseEnd() override;                        \
  virtual void SetDomainLookupStart(mozilla::TimeStamp timeStamp,              \
                                    bool onlyIfNull = false) override;         \
  virtual void SetDomainLookupEnd(mozilla::TimeStamp timeStamp,                \
                                  bool onlyIfNull = false) override;           \
  virtual TimingStruct Timings() override;                                     \
  virtual bool ResponseIsComplete() override;                                  \
  virtual int64_t GetTransferSize() override;                                  \
  virtual int64_t GetRequestSize() override;                                   \
  virtual bool IsHttp3Used() override;                                         \
  virtual void SetDNSWasRefreshed() override;                                  \
  virtual void DontReuseConnection() override;                                 \
  virtual bool HasStickyConnection() const override;                           \
  virtual void SetH2WSConnRefTaken() override;                                 \
  virtual bool ProxyConnectFailed() override;                                  \
  virtual int32_t GetProxyConnectResponseCode() override;                      \
  virtual bool DataSentToChildProcess() override;                              \
  virtual nsHttpTransaction* AsHttpTransaction() override;                     \
  virtual HttpTransactionParent* AsHttpTransactionParent() override;           \
  virtual bool TakeRestartedState() override;                                  \
  virtual uint32_t HTTPSSVCReceivedStage() override;                           \
  virtual bool Http2Disabled() const override;                                 \
  virtual bool Http3Disabled() const override;                                 \
  virtual already_AddRefed<nsHttpConnectionInfo> GetConnInfo() const override; \
  virtual bool GetSupportsHTTP3() override;                                    \
  virtual void SetIsForWebTransport(bool aIsForWebTransport) override;

}  // namespace mozilla::net

#endif  // HttpTransactionShell_h__