1
#pragma once
2

            
3
#include <cstdint>
4
#include <limits>
5
#include <memory>
6

            
7
#include "envoy/access_log/access_log.h"
8
#include "envoy/buffer/buffer.h"
9
#include "envoy/common/matchers.h"
10
#include "envoy/common/optref.h"
11
#include "envoy/common/pure.h"
12
#include "envoy/grpc/status.h"
13
#include "envoy/http/codec_runtime_overrides.h"
14
#include "envoy/http/header_formatter.h"
15
#include "envoy/http/header_map.h"
16
#include "envoy/http/metadata_interface.h"
17
#include "envoy/http/protocol.h"
18
#include "envoy/http/stream_reset_handler.h"
19
#include "envoy/network/address.h"
20
#include "envoy/stream_info/stream_info.h"
21

            
22
#include "source/common/http/status.h"
23

            
24
namespace Envoy {
25
namespace Http {
26

            
27
enum class CodecType { HTTP1, HTTP2, HTTP3 };
28

            
29
namespace Http1 {
30
struct CodecStats;
31
}
32

            
33
namespace Http2 {
34
struct CodecStats;
35
}
36

            
37
namespace Http3 {
38
struct CodecStats;
39
}
40

            
41
class Stream;
42
class RequestDecoder;
43

            
44
class RequestDecoderHandle {
45
public:
46
100046
  virtual ~RequestDecoderHandle() = default;
47

            
48
  /**
49
   * @return a reference to the underlying decoder if it is still valid.
50
   */
51
  virtual OptRef<RequestDecoder> get() PURE;
52
};
53
using RequestDecoderHandlePtr = std::unique_ptr<RequestDecoderHandle>;
54

            
55
/**
56
 * Error codes used to convey the reason for a GOAWAY.
57
 */
58
enum class GoAwayErrorCode {
59
  NoError,
60
  Other,
61
};
62

            
63
/**
64
 * Stream encoder options specific to HTTP/1.
65
 */
66
class Http1StreamEncoderOptions {
67
public:
68
85113
  virtual ~Http1StreamEncoderOptions() = default;
69

            
70
  /**
71
   * Force disable chunk encoding, even if there is no known content length. This effectively forces
72
   * HTTP/1.0 behavior in which the connection will need to be closed to indicate end of stream.
73
   */
74
  virtual void disableChunkEncoding() PURE;
75
};
76

            
77
using Http1StreamEncoderOptionsOptRef =
78
    absl::optional<std::reference_wrapper<Http1StreamEncoderOptions>>;
79

            
80
/**
81
 * Encodes an HTTP stream. This interface contains methods common to both the request and response
82
 * path.
83
 * TODO(mattklein123): Consider removing the StreamEncoder interface entirely and just duplicating
84
 * the methods in both the request/response path for simplicity.
85
 */
86
class StreamEncoder {
87
public:
88
367073
  virtual ~StreamEncoder() = default;
89

            
90
  /**
91
   * Encode a data frame.
92
   * @param data supplies the data to encode. The data may be moved by the encoder.
93
   * @param end_stream supplies whether this is the last data frame.
94
   */
95
  virtual void encodeData(Buffer::Instance& data, bool end_stream) PURE;
96

            
97
  /**
98
   * @return Stream& the backing stream.
99
   */
100
  virtual Stream& getStream() PURE;
101

            
102
  /**
103
   * Encode metadata.
104
   * @param metadata_map_vector is the vector of metadata maps to encode.
105
   */
106
  virtual void encodeMetadata(const MetadataMapVector& metadata_map_vector) PURE;
107

            
108
  /**
109
   * Return the HTTP/1 stream encoder options if applicable. If the stream is not HTTP/1 returns
110
   * absl::nullopt.
111
   */
112
  virtual Http1StreamEncoderOptionsOptRef http1StreamEncoderOptions() PURE;
113
};
114

            
115
/**
116
 * Stream encoder used for sending a request (client to server). Virtual inheritance is required
117
 * due to a parallel implementation split between the shared base class and the derived class.
118
 */
119
class RequestEncoder : public virtual StreamEncoder {
120
public:
121
  /**
122
   * Encode headers, optionally indicating end of stream.
123
   * @param headers supplies the header map to encode. Must have required HTTP headers.
124
   * @param end_stream supplies whether this is a header only request.
125
   * @return Status indicating whether encoding succeeded. Encoding will fail if request
126
   * headers are missing required HTTP headers (method, path for non-CONNECT, host for CONNECT).
127
   */
128
  virtual Status encodeHeaders(const RequestHeaderMap& headers, bool end_stream) PURE;
129

            
130
  /**
131
   * Encode trailers. This implicitly ends the stream.
132
   * @param trailers supplies the trailers to encode.
133
   */
134
  virtual void encodeTrailers(const RequestTrailerMap& trailers) PURE;
135

            
136
  /**
137
   * Enable TCP Tunneling.
138
   */
139
  virtual void enableTcpTunneling() PURE;
140
};
141

            
142
/**
143
 * Stream encoder used for sending a response (server to client). Virtual inheritance is required
144
 * due to a parallel implementation split between the shared base class and the derived class.
145
 */
146
class ResponseEncoder : public virtual StreamEncoder {
147
public:
148
  /**
149
   * Encode supported 1xx headers.
150
   * Currently 100-Continue, 102-Processing, 103-Early-Data, and 104-Upload-Resumption-Supported
151
   * headers are supported.
152
   * @param headers supplies the 1xx header map to encode.
153
   */
154
  virtual void encode1xxHeaders(const ResponseHeaderMap& headers) PURE;
155

            
156
  /**
157
   * Encode headers, optionally indicating end of stream. Response headers must
158
   * have a valid :status set.
159
   * @param headers supplies the header map to encode.
160
   * @param end_stream supplies whether this is a header only response.
161
   */
162
  virtual void encodeHeaders(const ResponseHeaderMap& headers, bool end_stream) PURE;
163

            
164
  /**
165
   * Encode trailers. This implicitly ends the stream.
166
   * @param trailers supplies the trailers to encode.
167
   */
168
  virtual void encodeTrailers(const ResponseTrailerMap& trailers) PURE;
169

            
170
  /**
171
   * Indicates whether invalid HTTP messaging should be handled with a stream error or a connection
172
   * error.
173
   */
174
  virtual bool streamErrorOnInvalidHttpMessage() const PURE;
175

            
176
  /**
177
   * Set a new request decoder for this ResponseEncoder. This is helpful in the case of an internal
178
   * redirect, in which a new request decoder is created in the context of the same downstream
179
   * request.
180
   * @param decoder new request decoder.
181
   */
182
  virtual void setRequestDecoder(RequestDecoder& decoder) PURE;
183

            
184
  /**
185
   * Set headers, trailers, and stream info for deferred logging. This allows HCM to hand off
186
   * stream-level details to the codec for logging after the stream may be destroyed (e.g. on
187
   * receiving the final ack packet from the client). Note that headers and trailers are const
188
   * as they will not be modified after this point.
189
   * @param request_header_map Request headers for this stream.
190
   * @param response_header_map Response headers for this stream.
191
   * @param response_trailer_map Response trailers for this stream.
192
   * @param stream_info Stream info for this stream.
193
   */
194
  virtual void
195
  setDeferredLoggingHeadersAndTrailers(Http::RequestHeaderMapConstSharedPtr request_header_map,
196
                                       Http::ResponseHeaderMapConstSharedPtr response_header_map,
197
                                       Http::ResponseTrailerMapConstSharedPtr response_trailer_map,
198
                                       StreamInfo::StreamInfo& stream_info) PURE;
199
};
200

            
201
class ResponseDecoder;
202

            
203
/**
204
 * A handle to a ResponseDecoder. This handle can be used to check if the underlying decoder is
205
 * still valid and to get a reference to it.
206
 */
207
class ResponseDecoderHandle {
208
public:
209
81130
  virtual ~ResponseDecoderHandle() = default;
210

            
211
  /**
212
   * @return a reference to the underlying decoder if it is still valid.
213
   */
214
  virtual OptRef<ResponseDecoder> get() PURE;
215
};
216
using ResponseDecoderHandlePtr = std::unique_ptr<ResponseDecoderHandle>;
217

            
218
/**
219
 * Decodes an HTTP stream. These are callbacks fired into a sink. This interface contains methods
220
 * common to both the request and response path.
221
 * TODO(mattklein123): Consider removing the StreamDecoder interface entirely and just duplicating
222
 * the methods in both the request/response path for simplicity.
223
 */
224
class StreamDecoder {
225
public:
226
415379
  virtual ~StreamDecoder() = default;
227

            
228
  /**
229
   * Called with a decoded data frame.
230
   * @param data supplies the decoded data.
231
   * @param end_stream supplies whether this is the last data frame.
232
   */
233
  virtual void decodeData(Buffer::Instance& data, bool end_stream) PURE;
234

            
235
  /**
236
   * Called with decoded METADATA.
237
   * @param decoded METADATA.
238
   */
239
  virtual void decodeMetadata(MetadataMapPtr&& metadata_map) PURE;
240
};
241

            
242
/**
243
 * Stream decoder used for receiving a request (client to server). Virtual inheritance is required
244
 * due to a parallel implementation split between the shared base class and the derived class.
245
 */
246
class RequestDecoder : public virtual StreamDecoder {
247
public:
248
  /**
249
   * Called with decoded headers, optionally indicating end of stream.
250
   * @param headers supplies the decoded headers map.
251
   * @param end_stream supplies whether this is a header only request.
252
   */
253
  virtual void decodeHeaders(RequestHeaderMapSharedPtr&& headers, bool end_stream) PURE;
254

            
255
  /**
256
   * Called with a decoded trailers frame. This implicitly ends the stream.
257
   * @param trailers supplies the decoded trailers.
258
   */
259
  virtual void decodeTrailers(RequestTrailerMapPtr&& trailers) PURE;
260

            
261
  /**
262
   * Called if the codec needs to send a protocol error.
263
   * @param code supplies the HTTP error code to send.
264
   * @param body supplies an optional body to send with the local reply.
265
   * @param modify_headers supplies a way to edit headers before they are sent downstream.
266
   * @param grpc_status an optional gRPC status for gRPC requests
267
   * @param details details about the source of the error, for debug purposes
268
   */
269
  virtual void sendLocalReply(Code code, absl::string_view body,
270
                              const std::function<void(ResponseHeaderMap& headers)>& modify_headers,
271
                              const absl::optional<Grpc::Status::GrpcStatus> grpc_status,
272
                              absl::string_view details) PURE;
273

            
274
  /**
275
   * @return StreamInfo::StreamInfo& the stream_info for this stream.
276
   */
277
  virtual StreamInfo::StreamInfo& streamInfo() PURE;
278

            
279
  /**
280
   * @return List of shared pointers to access loggers for this stream.
281
   */
282
  virtual AccessLog::InstanceSharedPtrVector accessLogHandlers() PURE;
283

            
284
  /**
285
   * @return A handle to the request decoder. Caller can check the request decoder's liveness via
286
   * the handle.
287
   */
288
  virtual RequestDecoderHandlePtr getRequestDecoderHandle() PURE;
289
};
290

            
291
/**
292
 * Stream decoder used for receiving a response (server to client). Virtual inheritance is required
293
 * due to a parallel implementation split between the shared base class and the derived class.
294
 */
295
class ResponseDecoder : public virtual StreamDecoder {
296
public:
297
  /**
298
   * Called with decoded 1xx headers.
299
   * Currently 100-Continue, 102-Processing, 103-Early-Data, and 104-Upload-Resumption-Supported
300
   * headers are supported.
301
   * @param headers supplies the decoded 1xx headers map.
302
   */
303
  virtual void decode1xxHeaders(ResponseHeaderMapPtr&& headers) PURE;
304

            
305
  /**
306
   * Called with decoded headers, optionally indicating end of stream.
307
   * @param headers supplies the decoded headers map.
308
   * @param end_stream supplies whether this is a header only response.
309
   */
310
  virtual void decodeHeaders(ResponseHeaderMapPtr&& headers, bool end_stream) PURE;
311

            
312
  /**
313
   * Called with a decoded trailers frame. This implicitly ends the stream.
314
   * @param trailers supplies the decoded trailers.
315
   */
316
  virtual void decodeTrailers(ResponseTrailerMapPtr&& trailers) PURE;
317

            
318
  /**
319
   * Dump the response decoder to the specified ostream.
320
   *
321
   * @param os the ostream to dump state to
322
   * @param indent_level the depth, for pretty-printing.
323
   *
324

            
325
   * This function is called on Envoy fatal errors so should avoid memory allocation.
326
   */
327
  virtual void dumpState(std::ostream& os, int indent_level = 0) const PURE;
328

            
329
  /**
330
   * @return A handle to the response decoder. Caller can check the response decoder's liveness via
331
   * the handle.
332
   */
333
  virtual ResponseDecoderHandlePtr createResponseDecoderHandle() PURE;
334
};
335

            
336
/**
337
 * Callbacks that fire against a stream.
338
 */
339
class StreamCallbacks {
340
public:
341
459302
  virtual ~StreamCallbacks() = default;
342

            
343
  /**
344
   * Fires when a stream has been remote reset.
345
   * @param reason supplies the reset reason.
346
   * @param transport_failure_reason supplies underlying transport failure reason.
347
   */
348
  virtual void onResetStream(StreamResetReason reason,
349
                             absl::string_view transport_failure_reason) PURE;
350

            
351
  /**
352
   * Fires when a stream, or the connection the stream is sending to, goes over its high watermark.
353
   */
354
  virtual void onAboveWriteBufferHighWatermark() PURE;
355

            
356
  /**
357
   * Fires when a stream, or the connection the stream is sending to, goes from over its high
358
   * watermark to under its low watermark.
359
   */
360
  virtual void onBelowWriteBufferLowWatermark() PURE;
361
};
362

            
363
/**
364
 * Codec event callbacks for a given HTTP Stream.
365
 * This can be used to tightly couple an entity with a streams low-level events.
366
 */
367
class CodecEventCallbacks {
368
public:
369
94810
  virtual ~CodecEventCallbacks() = default;
370
  /**
371
   * Called when the the underlying codec finishes encoding.
372
   */
373
  virtual void onCodecEncodeComplete() PURE;
374

            
375
  /**
376
   * Called when the underlying codec has a low level reset.
377
   * e.g. Envoy serialized the response but it has not been flushed.
378
   */
379
  virtual void onCodecLowLevelReset() PURE;
380
};
381

            
382
/**
383
 * An HTTP stream (request, response, and push).
384
 */
385
class Stream : public StreamResetHandler {
386
public:
387
  /**
388
   * Add stream callbacks.
389
   * @param callbacks supplies the callbacks to fire on stream events.
390
   */
391
  virtual void addCallbacks(StreamCallbacks& callbacks) PURE;
392

            
393
  /**
394
   * Remove stream callbacks.
395
   * @param callbacks supplies the callbacks to remove.
396
   */
397
  virtual void removeCallbacks(StreamCallbacks& callbacks) PURE;
398

            
399
  /**
400
   * Register the codec event callbacks for this stream.
401
   * The stream can only have a single registered callback at a time.
402
   * @param codec_callbacks the codec callbacks for this stream.
403
   * @return CodecEventCallbacks* the prior registered codec callbacks.
404
   */
405
  virtual CodecEventCallbacks*
406
  registerCodecEventCallbacks(CodecEventCallbacks* codec_callbacks) PURE;
407

            
408
  /**
409
   * Enable/disable further data from this stream.
410
   * Cessation of data may not be immediate. For example, for HTTP/2 this may stop further flow
411
   * control window updates which will result in the peer eventually stopping sending data.
412
   * @param disable informs if reads should be disabled (true) or re-enabled (false).
413
   *
414
   * Note that this function reference counts calls. For example
415
   * readDisable(true);  // Disables data
416
   * readDisable(true);  // Notes the stream is blocked by two sources
417
   * readDisable(false);  // Notes the stream is blocked by one source
418
   * readDisable(false);  // Marks the stream as unblocked, so resumes reading.
419
   */
420
  virtual void readDisable(bool disable) PURE;
421

            
422
  /**
423
   * Return the number of bytes this stream is allowed to buffer, or 0 if there is no limit
424
   * configured.
425
   * @return uint32_t the stream's configured buffer limits.
426
   */
427
  virtual uint32_t bufferLimit() const PURE;
428

            
429
  /**
430
   * @return string_view optionally return the reason behind codec level errors.
431
   *
432
   * This information is communicated via direct accessor rather than passed with the
433
   * CodecProtocolException so that the error can be associated only with the problematic stream and
434
   * not associated with every stream on the connection.
435
   */
436
  virtual absl::string_view responseDetails() { return ""; }
437

            
438
  /**
439
   * @return const Network::ConnectionInfoProvider& the adderess provider  of the connection
440
   * associated with the stream.
441
   */
442
  virtual const Network::ConnectionInfoProvider& connectionInfoProvider() PURE;
443

            
444
  /**
445
   * Set the flush timeout for the stream. At the codec level this is used to bound the amount of
446
   * time the codec will wait to flush body data pending open stream window. It does *not* count
447
   * small window updates as satisfying the idle timeout as this is a potential DoS vector.
448
   */
449
  virtual void setFlushTimeout(std::chrono::milliseconds timeout) PURE;
450

            
451
  /**
452
   * @return the account, if any, used by this stream.
453
   */
454
  virtual Buffer::BufferMemoryAccountSharedPtr account() const PURE;
455

            
456
  /**
457
   * Sets the account for this stream, propagating it to all of its buffers.
458
   * @param the account to assign this stream.
459
   */
460
  virtual void setAccount(Buffer::BufferMemoryAccountSharedPtr account) PURE;
461

            
462
  /**
463
   * Get the bytes meter for this stream.
464
   */
465
  virtual const StreamInfo::BytesMeterSharedPtr& bytesMeter() PURE;
466

            
467
  /**
468
   * @return absl::optional<uint32_t> the codec level stream ID if available
469
   * or nullopt if not applicable or not yet assigned.
470
   *
471
   * HTTP/1 streams return nullopt.
472
   * HTTP/2 streams return the HTTP/2 stream ID or nullopt if not available.
473
   * HTTP/3 streams return the HTTP/3 stream ID or nullopt if not available.
474
   */
475
  virtual absl::optional<uint32_t> codecStreamId() const PURE;
476
};
477

            
478
/**
479
 * A class for sharing what HTTP/2 SETTINGS were received from the peer.
480
 */
481
class ReceivedSettings {
482
public:
483
7
  virtual ~ReceivedSettings() = default;
484

            
485
  /**
486
   * @return value of SETTINGS_MAX_CONCURRENT_STREAMS, or absl::nullopt if it was not present.
487
   */
488
  virtual const absl::optional<uint32_t>& maxConcurrentStreams() const PURE;
489
};
490

            
491
/**
492
 * Connection level callbacks.
493
 */
494
class ConnectionCallbacks {
495
public:
496
131526
  virtual ~ConnectionCallbacks() = default;
497

            
498
  /**
499
   * Fires when the remote indicates "go away." No new streams should be created.
500
   */
501
  virtual void onGoAway(GoAwayErrorCode error_code) PURE;
502

            
503
  /**
504
   * Fires when the peer settings frame is received from the peer.
505
   * This may occur multiple times across the lifetime of the connection.
506
   * @param ReceivedSettings the settings received from the peer.
507
   */
508
21906
  virtual void onSettings(ReceivedSettings& settings) { UNREFERENCED_PARAMETER(settings); }
509

            
510
  /**
511
   * Fires when the MAX_STREAMS frame is received from the peer.
512
   * This is an HTTP/3 frame, indicating the new maximum stream ID which can be opened.
513
   * This may occur multiple times across the lifetime of an HTTP/3 connection.
514
   * @param num_streams the number of streams now allowed to be opened.
515
   */
516
2956
  virtual void onMaxStreamsChanged(uint32_t num_streams) { UNREFERENCED_PARAMETER(num_streams); }
517
};
518

            
519
/**
520
 * HTTP/1.* Codec settings
521
 */
522
struct Http1Settings {
523
  // Enable codec to parse absolute URIs. This enables forward/explicit proxy support for non TLS
524
  // traffic
525
  bool allow_absolute_url_{false};
526
  // Allow HTTP/1.0 from downstream.
527
  bool accept_http_10_{false};
528
  // Set a default host if no Host: header is present for HTTP/1.0 requests.`
529
  std::string default_host_for_http_10_;
530
  // Encode trailers in Http. By default the HTTP/1 codec drops proxied trailers.
531
  // Note that this only happens when Envoy is chunk encoding which occurs when:
532
  //  - The request is HTTP/1.1
533
  //  - Is neither a HEAD only request nor a HTTP Upgrade
534
  //  - Not a HEAD request
535
  bool enable_trailers_{false};
536
  // Allows Envoy to process requests/responses with both `Content-Length` and `Transfer-Encoding`
537
  // headers set. By default such messages are rejected, but if option is enabled - Envoy will
538
  // remove Content-Length header and process message.
539
  bool allow_chunked_length_{false};
540
  // Remove HTTP/1.1 Upgrade header tokens matching any provided matcher. By default such
541
  // messages are rejected
542
  std::shared_ptr<const std::vector<Matchers::StringMatcherPtr>> ignore_upgrade_matchers_;
543

            
544
  enum class HeaderKeyFormat {
545
    // By default no formatting is performed, presenting all headers in lowercase (as Envoy
546
    // internals normalize everything to lowercase.)
547
    Default,
548
    // Performs proper casing of header keys: the first and all alpha characters following a
549
    // non-alphanumeric character is capitalized.
550
    ProperCase,
551
    // A stateful formatter extension has been configured.
552
    StatefulFormatter,
553
  };
554

            
555
  // How header keys should be formatted when serializing HTTP/1.1 headers.
556
  HeaderKeyFormat header_key_format_{HeaderKeyFormat::Default};
557

            
558
  // Non-null IFF header_key_format_ is configured to StatefulFormatter.
559
  StatefulHeaderKeyFormatterFactorySharedPtr stateful_header_key_formatter_;
560

            
561
  // Behaviour on invalid HTTP messaging:
562
  // - if true, the HTTP/1.1 connection is left open (where possible)
563
  // - if false, the HTTP/1.1 connection is terminated
564
  bool stream_error_on_invalid_http_message_{false};
565

            
566
  // True if this is an edge Envoy (using downstream address, no trusted hops)
567
  // and https:// URLs should be rejected over unencrypted connections.
568
  bool validate_scheme_{false};
569

            
570
  // If true, Envoy will send a fully qualified URL in the firstline of the request.
571
  bool send_fully_qualified_url_{false};
572

            
573
  // If true, any non-empty method composed of valid characters is accepted.
574
  // If false, only methods from a hard-coded list of known methods are accepted.
575
  // Only implemented in BalsaParser. http-parser only accepts known methods.
576
  bool allow_custom_methods_{false};
577
};
578

            
579
/**
580
 * A connection (client or server) that owns multiple streams.
581
 */
582
class Connection {
583
public:
584
106307
  virtual ~Connection() = default;
585

            
586
  /**
587
   * Dispatch incoming connection data.
588
   * @param data supplies the data to dispatch. The codec will drain as many bytes as it processes.
589
   * @return Status indicating the status of the codec. Holds any errors encountered while
590
   * processing the incoming data.
591
   */
592
  virtual Status dispatch(Buffer::Instance& data) PURE;
593

            
594
  /**
595
   * Indicate "go away" to the remote. No new streams can be created beyond this point.
596
   */
597
  virtual void goAway() PURE;
598

            
599
  /**
600
   * @return the protocol backing the connection. This can change if for example an HTTP/1.1
601
   *         connection gets an HTTP/1.0 request on it.
602
   */
603
  virtual Protocol protocol() PURE;
604

            
605
  /**
606
   * Indicate a "shutdown notice" to the remote. This is a hint that the remote should not send
607
   * any new streams, but if streams do arrive that will not be reset.
608
   */
609
  virtual void shutdownNotice() PURE;
610

            
611
  /**
612
   * @return bool whether the codec has data that it wants to write but cannot due to protocol
613
   *              reasons (e.g, needing window updates).
614
   */
615
  virtual bool wantsToWrite() PURE;
616

            
617
  /**
618
   * Called when the underlying Network::Connection goes over its high watermark.
619
   */
620
  virtual void onUnderlyingConnectionAboveWriteBufferHighWatermark() PURE;
621

            
622
  /**
623
   * Called when the underlying Network::Connection goes from over its high watermark to under its
624
   * low watermark.
625
   */
626
  virtual void onUnderlyingConnectionBelowWriteBufferLowWatermark() PURE;
627
};
628

            
629
/**
630
 * Callbacks for downstream connection watermark limits.
631
 */
632
class DownstreamWatermarkCallbacks {
633
public:
634
95685
  virtual ~DownstreamWatermarkCallbacks() = default;
635

            
636
  /**
637
   * Called when the downstream connection or stream goes over its high watermark. Note that this
638
   * may be called separately for both the stream going over and the connection going over. It
639
   * is the responsibility of the DownstreamWatermarkCallbacks implementation to handle unwinding
640
   * multiple high and low watermark calls.
641
   */
642
  virtual void onAboveWriteBufferHighWatermark() PURE;
643

            
644
  /**
645
   * Called when the downstream connection or stream goes from over its high watermark to under its
646
   * low watermark. As with onAboveWriteBufferHighWatermark above, this may be called independently
647
   * when both the stream and the connection go under the low watermark limit, and the callee must
648
   * ensure that the flow of data does not resume until all callers which were above their high
649
   * watermarks have gone below.
650
   */
651
  virtual void onBelowWriteBufferLowWatermark() PURE;
652
};
653

            
654
/**
655
 * Callbacks for server connections.
656
 */
657
class ServerConnectionCallbacks : public virtual ConnectionCallbacks {
658
public:
659
  /**
660
   * Invoked when a new request stream is initiated by the remote.
661
   * @param response_encoder supplies the encoder to use for creating the response. The request and
662
   *                         response are backed by the same Stream object.
663
   * @param is_internally_created indicates if this stream was originated by a
664
   *   client, or was created by Envoy, by example as part of an internal redirect.
665
   * @return RequestDecoder& supplies the decoder callbacks to fire into for stream decoding
666
   *   events.
667
   */
668
  virtual RequestDecoder& newStream(ResponseEncoder& response_encoder,
669
                                    bool is_internally_created = false) PURE;
670
};
671

            
672
/**
673
 * A server side HTTP connection.
674
 */
675
class ServerConnection : public virtual Connection {};
676
using ServerConnectionPtr = std::unique_ptr<ServerConnection>;
677

            
678
/**
679
 * A client side HTTP connection.
680
 */
681
class ClientConnection : public virtual Connection {
682
public:
683
  /**
684
   * Create a new outgoing request stream.
685
   * @param response_decoder supplies the decoder callbacks to fire response events into.
686
   * @return RequestEncoder& supplies the encoder to write the request into.
687
   */
688
  virtual RequestEncoder& newStream(ResponseDecoder& response_decoder) PURE;
689
};
690

            
691
using ClientConnectionPtr = std::unique_ptr<ClientConnection>;
692

            
693
} // namespace Http
694
} // namespace Envoy