LCOV - code coverage report
Current view: top level - envoy/http - codec.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 11 12 91.7 %
Date: 2024-01-05 06:35:25 Functions: 11 12 91.7 %

          Line data    Source code
       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/pure.h"
      10             : #include "envoy/grpc/status.h"
      11             : #include "envoy/http/header_formatter.h"
      12             : #include "envoy/http/header_map.h"
      13             : #include "envoy/http/metadata_interface.h"
      14             : #include "envoy/http/protocol.h"
      15             : #include "envoy/http/stream_reset_handler.h"
      16             : #include "envoy/network/address.h"
      17             : #include "envoy/stream_info/stream_info.h"
      18             : 
      19             : #include "source/common/http/status.h"
      20             : 
      21             : namespace Envoy {
      22             : namespace Http {
      23             : 
      24             : enum class CodecType { HTTP1, HTTP2, HTTP3 };
      25             : 
      26             : namespace Http1 {
      27             : struct CodecStats;
      28             : }
      29             : 
      30             : namespace Http2 {
      31             : struct CodecStats;
      32             : }
      33             : 
      34             : namespace Http3 {
      35             : struct CodecStats;
      36             : }
      37             : 
      38             : // Legacy default value of 60K is safely under both codec default limits.
      39             : static constexpr uint32_t DEFAULT_MAX_REQUEST_HEADERS_KB = 60;
      40             : // Default maximum number of headers.
      41             : static constexpr uint32_t DEFAULT_MAX_HEADERS_COUNT = 100;
      42             : 
      43             : const char MaxRequestHeadersCountOverrideKey[] =
      44             :     "envoy.reloadable_features.max_request_headers_count";
      45             : const char MaxResponseHeadersCountOverrideKey[] =
      46             :     "envoy.reloadable_features.max_response_headers_count";
      47             : const char MaxRequestHeadersSizeOverrideKey[] =
      48             :     "envoy.reloadable_features.max_request_headers_size_kb";
      49             : 
      50             : class Stream;
      51             : class RequestDecoder;
      52             : 
      53             : /**
      54             :  * Error codes used to convey the reason for a GOAWAY.
      55             :  */
      56             : enum class GoAwayErrorCode {
      57             :   NoError,
      58             :   Other,
      59             : };
      60             : 
      61             : /**
      62             :  * Stream encoder options specific to HTTP/1.
      63             :  */
      64             : class Http1StreamEncoderOptions {
      65             : public:
      66        1862 :   virtual ~Http1StreamEncoderOptions() = default;
      67             : 
      68             :   /**
      69             :    * Force disable chunk encoding, even if there is no known content length. This effectively forces
      70             :    * HTTP/1.0 behavior in which the connection will need to be closed to indicate end of stream.
      71             :    */
      72             :   virtual void disableChunkEncoding() PURE;
      73             : };
      74             : 
      75             : using Http1StreamEncoderOptionsOptRef =
      76             :     absl::optional<std::reference_wrapper<Http1StreamEncoderOptions>>;
      77             : 
      78             : /**
      79             :  * Encodes an HTTP stream. This interface contains methods common to both the request and response
      80             :  * path.
      81             :  * TODO(mattklein123): Consider removing the StreamEncoder interface entirely and just duplicating
      82             :  * the methods in both the request/response path for simplicity.
      83             :  */
      84             : class StreamEncoder {
      85             : public:
      86        4607 :   virtual ~StreamEncoder() = default;
      87             : 
      88             :   /**
      89             :    * Encode a data frame.
      90             :    * @param data supplies the data to encode. The data may be moved by the encoder.
      91             :    * @param end_stream supplies whether this is the last data frame.
      92             :    */
      93             :   virtual void encodeData(Buffer::Instance& data, bool end_stream) PURE;
      94             : 
      95             :   /**
      96             :    * @return Stream& the backing stream.
      97             :    */
      98             :   virtual Stream& getStream() PURE;
      99             : 
     100             :   /**
     101             :    * Encode metadata.
     102             :    * @param metadata_map_vector is the vector of metadata maps to encode.
     103             :    */
     104             :   virtual void encodeMetadata(const MetadataMapVector& metadata_map_vector) PURE;
     105             : 
     106             :   /**
     107             :    * Return the HTTP/1 stream encoder options if applicable. If the stream is not HTTP/1 returns
     108             :    * absl::nullopt.
     109             :    */
     110             :   virtual Http1StreamEncoderOptionsOptRef http1StreamEncoderOptions() PURE;
     111             : };
     112             : 
     113             : /**
     114             :  * Stream encoder used for sending a request (client to server). Virtual inheritance is required
     115             :  * due to a parallel implementation split between the shared base class and the derived class.
     116             :  */
     117             : class RequestEncoder : public virtual StreamEncoder {
     118             : public:
     119             :   /**
     120             :    * Encode headers, optionally indicating end of stream.
     121             :    * @param headers supplies the header map to encode. Must have required HTTP headers.
     122             :    * @param end_stream supplies whether this is a header only request.
     123             :    * @return Status indicating whether encoding succeeded. Encoding will fail if request
     124             :    * headers are missing required HTTP headers (method, path for non-CONNECT, host for CONNECT).
     125             :    */
     126             :   virtual Status encodeHeaders(const RequestHeaderMap& headers, bool end_stream) PURE;
     127             : 
     128             :   /**
     129             :    * Encode trailers. This implicitly ends the stream.
     130             :    * @param trailers supplies the trailers to encode.
     131             :    */
     132             :   virtual void encodeTrailers(const RequestTrailerMap& trailers) PURE;
     133             : 
     134             :   /**
     135             :    * Enable TCP Tunneling.
     136             :    */
     137             :   virtual void enableTcpTunneling() PURE;
     138             : };
     139             : 
     140             : /**
     141             :  * Stream encoder used for sending a response (server to client). Virtual inheritance is required
     142             :  * due to a parallel implementation split between the shared base class and the derived class.
     143             :  */
     144             : class ResponseEncoder : public virtual StreamEncoder {
     145             : public:
     146             :   /**
     147             :    * Encode supported 1xx headers.
     148             :    * Currently 100-Continue, 102-Processing, and 103-Early-Data headers are supported.
     149             :    * @param headers supplies the 1xx header map to encode.
     150             :    */
     151             :   virtual void encode1xxHeaders(const ResponseHeaderMap& headers) PURE;
     152             : 
     153             :   /**
     154             :    * Encode headers, optionally indicating end of stream. Response headers must
     155             :    * have a valid :status set.
     156             :    * @param headers supplies the header map to encode.
     157             :    * @param end_stream supplies whether this is a header only response.
     158             :    */
     159             :   virtual void encodeHeaders(const ResponseHeaderMap& headers, bool end_stream) PURE;
     160             : 
     161             :   /**
     162             :    * Encode trailers. This implicitly ends the stream.
     163             :    * @param trailers supplies the trailers to encode.
     164             :    */
     165             :   virtual void encodeTrailers(const ResponseTrailerMap& trailers) PURE;
     166             : 
     167             :   /**
     168             :    * Indicates whether invalid HTTP messaging should be handled with a stream error or a connection
     169             :    * error.
     170             :    */
     171             :   virtual bool streamErrorOnInvalidHttpMessage() const PURE;
     172             : 
     173             :   /**
     174             :    * Set a new request decoder for this ResponseEncoder. This is helpful in the case of an internal
     175             :    * redirect, in which a new request decoder is created in the context of the same downstream
     176             :    * request.
     177             :    * @param decoder new request decoder.
     178             :    */
     179             :   virtual void setRequestDecoder(RequestDecoder& decoder) PURE;
     180             : 
     181             :   /**
     182             :    * Set headers, trailers, and stream info for deferred logging. This allows HCM to hand off
     183             :    * stream-level details to the codec for logging after the stream may be destroyed (e.g. on
     184             :    * receiving the final ack packet from the client). Note that headers and trailers are const
     185             :    * as they will not be modified after this point.
     186             :    * @param request_header_map Request headers for this stream.
     187             :    * @param response_header_map Response headers for this stream.
     188             :    * @param response_trailer_map Response trailers for this stream.
     189             :    * @param stream_info Stream info for this stream.
     190             :    */
     191             :   virtual void
     192             :   setDeferredLoggingHeadersAndTrailers(Http::RequestHeaderMapConstSharedPtr request_header_map,
     193             :                                        Http::ResponseHeaderMapConstSharedPtr response_header_map,
     194             :                                        Http::ResponseTrailerMapConstSharedPtr response_trailer_map,
     195             :                                        StreamInfo::StreamInfo& stream_info) PURE;
     196             : };
     197             : 
     198             : /**
     199             :  * Decodes an HTTP stream. These are callbacks fired into a sink. This interface contains methods
     200             :  * common to both the request and response path.
     201             :  * TODO(mattklein123): Consider removing the StreamDecoder interface entirely and just duplicating
     202             :  * the methods in both the request/response path for simplicity.
     203             :  */
     204             : class StreamDecoder {
     205             : public:
     206        3105 :   virtual ~StreamDecoder() = default;
     207             : 
     208             :   /**
     209             :    * Called with a decoded data frame.
     210             :    * @param data supplies the decoded data.
     211             :    * @param end_stream supplies whether this is the last data frame.
     212             :    */
     213             :   virtual void decodeData(Buffer::Instance& data, bool end_stream) PURE;
     214             : 
     215             :   /**
     216             :    * Called with decoded METADATA.
     217             :    * @param decoded METADATA.
     218             :    */
     219             :   virtual void decodeMetadata(MetadataMapPtr&& metadata_map) PURE;
     220             : };
     221             : 
     222             : /**
     223             :  * Stream decoder used for receiving a request (client to server). Virtual inheritance is required
     224             :  * due to a parallel implementation split between the shared base class and the derived class.
     225             :  */
     226             : class RequestDecoder : public virtual StreamDecoder {
     227             : public:
     228             :   /**
     229             :    * Called with decoded headers, optionally indicating end of stream.
     230             :    * @param headers supplies the decoded headers map.
     231             :    * @param end_stream supplies whether this is a header only request.
     232             :    */
     233             :   virtual void decodeHeaders(RequestHeaderMapSharedPtr&& headers, bool end_stream) PURE;
     234             : 
     235             :   /**
     236             :    * Called with a decoded trailers frame. This implicitly ends the stream.
     237             :    * @param trailers supplies the decoded trailers.
     238             :    */
     239             :   virtual void decodeTrailers(RequestTrailerMapPtr&& trailers) PURE;
     240             : 
     241             :   /**
     242             :    * Called if the codec needs to send a protocol error.
     243             :    * @param code supplies the HTTP error code to send.
     244             :    * @param body supplies an optional body to send with the local reply.
     245             :    * @param modify_headers supplies a way to edit headers before they are sent downstream.
     246             :    * @param grpc_status an optional gRPC status for gRPC requests
     247             :    * @param details details about the source of the error, for debug purposes
     248             :    */
     249             :   virtual void sendLocalReply(Code code, absl::string_view body,
     250             :                               const std::function<void(ResponseHeaderMap& headers)>& modify_headers,
     251             :                               const absl::optional<Grpc::Status::GrpcStatus> grpc_status,
     252             :                               absl::string_view details) PURE;
     253             : 
     254             :   /**
     255             :    * @return StreamInfo::StreamInfo& the stream_info for this stream.
     256             :    */
     257             :   virtual StreamInfo::StreamInfo& streamInfo() PURE;
     258             : 
     259             :   /**
     260             :    * @return List of shared pointers to access loggers for this stream.
     261             :    */
     262             :   virtual std::list<AccessLog::InstanceSharedPtr> accessLogHandlers() PURE;
     263             : };
     264             : 
     265             : /**
     266             :  * Stream decoder used for receiving a response (server to client). Virtual inheritance is required
     267             :  * due to a parallel implementation split between the shared base class and the derived class.
     268             :  */
     269             : class ResponseDecoder : public virtual StreamDecoder {
     270             : public:
     271             :   /**
     272             :    * Called with decoded 1xx headers.
     273             :    * Currently 100-Continue, 102-Processing, and 103-Early-Data headers are supported.
     274             :    * @param headers supplies the decoded 1xx headers map.
     275             :    */
     276             :   virtual void decode1xxHeaders(ResponseHeaderMapPtr&& headers) PURE;
     277             : 
     278             :   /**
     279             :    * Called with decoded headers, optionally indicating end of stream.
     280             :    * @param headers supplies the decoded headers map.
     281             :    * @param end_stream supplies whether this is a header only response.
     282             :    */
     283             :   virtual void decodeHeaders(ResponseHeaderMapPtr&& headers, bool end_stream) PURE;
     284             : 
     285             :   /**
     286             :    * Called with a decoded trailers frame. This implicitly ends the stream.
     287             :    * @param trailers supplies the decoded trailers.
     288             :    */
     289             :   virtual void decodeTrailers(ResponseTrailerMapPtr&& trailers) PURE;
     290             : 
     291             :   /**
     292             :    * Dump the response decoder to the specified ostream.
     293             :    *
     294             :    * @param os the ostream to dump state to
     295             :    * @param indent_level the depth, for pretty-printing.
     296             :    *
     297             :    * This function is called on Envoy fatal errors so should avoid memory allocation.
     298             :    */
     299             :   virtual void dumpState(std::ostream& os, int indent_level = 0) const PURE;
     300             : };
     301             : 
     302             : /**
     303             :  * Callbacks that fire against a stream.
     304             :  */
     305             : class StreamCallbacks {
     306             : public:
     307        2621 :   virtual ~StreamCallbacks() = default;
     308             : 
     309             :   /**
     310             :    * Fires when a stream has been remote reset.
     311             :    * @param reason supplies the reset reason.
     312             :    * @param transport_failure_reason supplies underlying transport failure reason.
     313             :    */
     314             :   virtual void onResetStream(StreamResetReason reason,
     315             :                              absl::string_view transport_failure_reason) PURE;
     316             : 
     317             :   /**
     318             :    * Fires when a stream, or the connection the stream is sending to, goes over its high watermark.
     319             :    */
     320             :   virtual void onAboveWriteBufferHighWatermark() PURE;
     321             : 
     322             :   /**
     323             :    * Fires when a stream, or the connection the stream is sending to, goes from over its high
     324             :    * watermark to under its low watermark.
     325             :    */
     326             :   virtual void onBelowWriteBufferLowWatermark() PURE;
     327             : };
     328             : 
     329             : /**
     330             :  * Codec event callbacks for a given HTTP Stream.
     331             :  * This can be used to tightly couple an entity with a streams low-level events.
     332             :  */
     333             : class CodecEventCallbacks {
     334             : public:
     335         671 :   virtual ~CodecEventCallbacks() = default;
     336             :   /**
     337             :    * Called when the the underlying codec finishes encoding.
     338             :    */
     339             :   virtual void onCodecEncodeComplete() PURE;
     340             : 
     341             :   /**
     342             :    * Called when the underlying codec has a low level reset.
     343             :    * e.g. Envoy serialized the response but it has not been flushed.
     344             :    */
     345             :   virtual void onCodecLowLevelReset() PURE;
     346             : };
     347             : 
     348             : /**
     349             :  * An HTTP stream (request, response, and push).
     350             :  */
     351             : class Stream : public StreamResetHandler {
     352             : public:
     353             :   /**
     354             :    * Add stream callbacks.
     355             :    * @param callbacks supplies the callbacks to fire on stream events.
     356             :    */
     357             :   virtual void addCallbacks(StreamCallbacks& callbacks) PURE;
     358             : 
     359             :   /**
     360             :    * Remove stream callbacks.
     361             :    * @param callbacks supplies the callbacks to remove.
     362             :    */
     363             :   virtual void removeCallbacks(StreamCallbacks& callbacks) PURE;
     364             : 
     365             :   /**
     366             :    * Register the codec event callbacks for this stream.
     367             :    * The stream can only have a single registered callback at a time.
     368             :    * @param codec_callbacks the codec callbacks for this stream.
     369             :    * @return CodecEventCallbacks* the prior registered codec callbacks.
     370             :    */
     371             :   virtual CodecEventCallbacks*
     372             :   registerCodecEventCallbacks(CodecEventCallbacks* codec_callbacks) PURE;
     373             : 
     374             :   /**
     375             :    * Enable/disable further data from this stream.
     376             :    * Cessation of data may not be immediate. For example, for HTTP/2 this may stop further flow
     377             :    * control window updates which will result in the peer eventually stopping sending data.
     378             :    * @param disable informs if reads should be disabled (true) or re-enabled (false).
     379             :    *
     380             :    * Note that this function reference counts calls. For example
     381             :    * readDisable(true);  // Disables data
     382             :    * readDisable(true);  // Notes the stream is blocked by two sources
     383             :    * readDisable(false);  // Notes the stream is blocked by one source
     384             :    * readDisable(false);  // Marks the stream as unblocked, so resumes reading.
     385             :    */
     386             :   virtual void readDisable(bool disable) PURE;
     387             : 
     388             :   /**
     389             :    * Return the number of bytes this stream is allowed to buffer, or 0 if there is no limit
     390             :    * configured.
     391             :    * @return uint32_t the stream's configured buffer limits.
     392             :    */
     393             :   virtual uint32_t bufferLimit() const PURE;
     394             : 
     395             :   /**
     396             :    * @return string_view optionally return the reason behind codec level errors.
     397             :    *
     398             :    * This information is communicated via direct accessor rather than passed with the
     399             :    * CodecProtocolException so that the error can be associated only with the problematic stream and
     400             :    * not associated with every stream on the connection.
     401             :    */
     402          88 :   virtual absl::string_view responseDetails() { return ""; }
     403             : 
     404             :   /**
     405             :    * @return const Network::ConnectionInfoProvider& the adderess provider  of the connection
     406             :    * associated with the stream.
     407             :    */
     408             :   virtual const Network::ConnectionInfoProvider& connectionInfoProvider() PURE;
     409             : 
     410             :   /**
     411             :    * Set the flush timeout for the stream. At the codec level this is used to bound the amount of
     412             :    * time the codec will wait to flush body data pending open stream window. It does *not* count
     413             :    * small window updates as satisfying the idle timeout as this is a potential DoS vector.
     414             :    */
     415             :   virtual void setFlushTimeout(std::chrono::milliseconds timeout) PURE;
     416             : 
     417             :   /**
     418             :    * @return the account, if any, used by this stream.
     419             :    */
     420             :   virtual Buffer::BufferMemoryAccountSharedPtr account() const PURE;
     421             : 
     422             :   /**
     423             :    * Sets the account for this stream, propagating it to all of its buffers.
     424             :    * @param the account to assign this stream.
     425             :    */
     426             :   virtual void setAccount(Buffer::BufferMemoryAccountSharedPtr account) PURE;
     427             : 
     428             :   /**
     429             :    * Get the bytes meter for this stream.
     430             :    */
     431             :   virtual const StreamInfo::BytesMeterSharedPtr& bytesMeter() PURE;
     432             : };
     433             : 
     434             : /**
     435             :  * A class for sharing what HTTP/2 SETTINGS were received from the peer.
     436             :  */
     437             : class ReceivedSettings {
     438             : public:
     439         903 :   virtual ~ReceivedSettings() = default;
     440             : 
     441             :   /**
     442             :    * @return value of SETTINGS_MAX_CONCURRENT_STREAMS, or absl::nullopt if it was not present.
     443             :    */
     444             :   virtual const absl::optional<uint32_t>& maxConcurrentStreams() const PURE;
     445             : };
     446             : 
     447             : /**
     448             :  * Connection level callbacks.
     449             :  */
     450             : class ConnectionCallbacks {
     451             : public:
     452        1921 :   virtual ~ConnectionCallbacks() = default;
     453             : 
     454             :   /**
     455             :    * Fires when the remote indicates "go away." No new streams should be created.
     456             :    */
     457             :   virtual void onGoAway(GoAwayErrorCode error_code) PURE;
     458             : 
     459             :   /**
     460             :    * Fires when the peer settings frame is received from the peer.
     461             :    * This may occur multiple times across the lifetime of the connection.
     462             :    * @param ReceivedSettings the settings received from the peer.
     463             :    */
     464         365 :   virtual void onSettings(ReceivedSettings& settings) { UNREFERENCED_PARAMETER(settings); }
     465             : 
     466             :   /**
     467             :    * Fires when the MAX_STREAMS frame is received from the peer.
     468             :    * This is an HTTP/3 frame, indicating the new maximum stream ID which can be opened.
     469             :    * This may occur multiple times across the lifetime of an HTTP/3 connection.
     470             :    * @param num_streams the number of streams now allowed to be opened.
     471             :    */
     472           0 :   virtual void onMaxStreamsChanged(uint32_t num_streams) { UNREFERENCED_PARAMETER(num_streams); }
     473             : };
     474             : 
     475             : /**
     476             :  * HTTP/1.* Codec settings
     477             :  */
     478             : struct Http1Settings {
     479             :   // Enable codec to parse absolute URIs. This enables forward/explicit proxy support for non TLS
     480             :   // traffic
     481             :   bool allow_absolute_url_{false};
     482             :   // Allow HTTP/1.0 from downstream.
     483             :   bool accept_http_10_{false};
     484             :   // Set a default host if no Host: header is present for HTTP/1.0 requests.`
     485             :   std::string default_host_for_http_10_;
     486             :   // Encode trailers in Http. By default the HTTP/1 codec drops proxied trailers.
     487             :   // Note that this only happens when Envoy is chunk encoding which occurs when:
     488             :   //  - The request is HTTP/1.1
     489             :   //  - Is neither a HEAD only request nor a HTTP Upgrade
     490             :   //  - Not a HEAD request
     491             :   bool enable_trailers_{false};
     492             :   // Allows Envoy to process requests/responses with both `Content-Length` and `Transfer-Encoding`
     493             :   // headers set. By default such messages are rejected, but if option is enabled - Envoy will
     494             :   // remove Content-Length header and process message.
     495             :   bool allow_chunked_length_{false};
     496             : 
     497             :   enum class HeaderKeyFormat {
     498             :     // By default no formatting is performed, presenting all headers in lowercase (as Envoy
     499             :     // internals normalize everything to lowercase.)
     500             :     Default,
     501             :     // Performs proper casing of header keys: the first and all alpha characters following a
     502             :     // non-alphanumeric character is capitalized.
     503             :     ProperCase,
     504             :     // A stateful formatter extension has been configured.
     505             :     StatefulFormatter,
     506             :   };
     507             : 
     508             :   // How header keys should be formatted when serializing HTTP/1.1 headers.
     509             :   HeaderKeyFormat header_key_format_{HeaderKeyFormat::Default};
     510             : 
     511             :   // Non-null IFF header_key_format_ is configured to StatefulFormatter.
     512             :   StatefulHeaderKeyFormatterFactorySharedPtr stateful_header_key_formatter_;
     513             : 
     514             :   // Behaviour on invalid HTTP messaging:
     515             :   // - if true, the HTTP/1.1 connection is left open (where possible)
     516             :   // - if false, the HTTP/1.1 connection is terminated
     517             :   bool stream_error_on_invalid_http_message_{false};
     518             : 
     519             :   // True if this is an edge Envoy (using downstream address, no trusted hops)
     520             :   // and https:// URLs should be rejected over unencrypted connections.
     521             :   bool validate_scheme_{false};
     522             : 
     523             :   // If true, Envoy will send a fully qualified URL in the firstline of the request.
     524             :   bool send_fully_qualified_url_{false};
     525             : 
     526             :   // If true, BalsaParser is used for HTTP/1 parsing; if false, http-parser is
     527             :   // used. See issue #21245.
     528             :   bool use_balsa_parser_{false};
     529             : 
     530             :   // If true, any non-empty method composed of valid characters is accepted.
     531             :   // If false, only methods from a hard-coded list of known methods are accepted.
     532             :   // Only implemented in BalsaParser. http-parser only accepts known methods.
     533             :   bool allow_custom_methods_{false};
     534             : };
     535             : 
     536             : /**
     537             :  * A connection (client or server) that owns multiple streams.
     538             :  */
     539             : class Connection {
     540             : public:
     541        6051 :   virtual ~Connection() = default;
     542             : 
     543             :   /**
     544             :    * Dispatch incoming connection data.
     545             :    * @param data supplies the data to dispatch. The codec will drain as many bytes as it processes.
     546             :    * @return Status indicating the status of the codec. Holds any errors encountered while
     547             :    * processing the incoming data.
     548             :    */
     549             :   virtual Status dispatch(Buffer::Instance& data) PURE;
     550             : 
     551             :   /**
     552             :    * Indicate "go away" to the remote. No new streams can be created beyond this point.
     553             :    */
     554             :   virtual void goAway() PURE;
     555             : 
     556             :   /**
     557             :    * @return the protocol backing the connection. This can change if for example an HTTP/1.1
     558             :    *         connection gets an HTTP/1.0 request on it.
     559             :    */
     560             :   virtual Protocol protocol() PURE;
     561             : 
     562             :   /**
     563             :    * Indicate a "shutdown notice" to the remote. This is a hint that the remote should not send
     564             :    * any new streams, but if streams do arrive that will not be reset.
     565             :    */
     566             :   virtual void shutdownNotice() PURE;
     567             : 
     568             :   /**
     569             :    * @return bool whether the codec has data that it wants to write but cannot due to protocol
     570             :    *              reasons (e.g, needing window updates).
     571             :    */
     572             :   virtual bool wantsToWrite() PURE;
     573             : 
     574             :   /**
     575             :    * Called when the underlying Network::Connection goes over its high watermark.
     576             :    */
     577             :   virtual void onUnderlyingConnectionAboveWriteBufferHighWatermark() PURE;
     578             : 
     579             :   /**
     580             :    * Called when the underlying Network::Connection goes from over its high watermark to under its
     581             :    * low watermark.
     582             :    */
     583             :   virtual void onUnderlyingConnectionBelowWriteBufferLowWatermark() PURE;
     584             : };
     585             : 
     586             : /**
     587             :  * Callbacks for downstream connection watermark limits.
     588             :  */
     589             : class DownstreamWatermarkCallbacks {
     590             : public:
     591         506 :   virtual ~DownstreamWatermarkCallbacks() = default;
     592             : 
     593             :   /**
     594             :    * Called when the downstream connection or stream goes over its high watermark. Note that this
     595             :    * may be called separately for both the stream going over and the connection going over. It
     596             :    * is the responsibility of the DownstreamWatermarkCallbacks implementation to handle unwinding
     597             :    * multiple high and low watermark calls.
     598             :    */
     599             :   virtual void onAboveWriteBufferHighWatermark() PURE;
     600             : 
     601             :   /**
     602             :    * Called when the downstream connection or stream goes from over its high watermark to under its
     603             :    * low watermark. As with onAboveWriteBufferHighWatermark above, this may be called independently
     604             :    * when both the stream and the connection go under the low watermark limit, and the callee must
     605             :    * ensure that the flow of data does not resume until all callers which were above their high
     606             :    * watermarks have gone below.
     607             :    */
     608             :   virtual void onBelowWriteBufferLowWatermark() PURE;
     609             : };
     610             : 
     611             : /**
     612             :  * Callbacks for server connections.
     613             :  */
     614             : class ServerConnectionCallbacks : public virtual ConnectionCallbacks {
     615             : public:
     616             :   /**
     617             :    * Invoked when a new request stream is initiated by the remote.
     618             :    * @param response_encoder supplies the encoder to use for creating the response. The request and
     619             :    *                         response are backed by the same Stream object.
     620             :    * @param is_internally_created indicates if this stream was originated by a
     621             :    *   client, or was created by Envoy, by example as part of an internal redirect.
     622             :    * @return RequestDecoder& supplies the decoder callbacks to fire into for stream decoding
     623             :    *   events.
     624             :    */
     625             :   virtual RequestDecoder& newStream(ResponseEncoder& response_encoder,
     626             :                                     bool is_internally_created = false) PURE;
     627             : };
     628             : 
     629             : /**
     630             :  * A server side HTTP connection.
     631             :  */
     632             : class ServerConnection : public virtual Connection {};
     633             : using ServerConnectionPtr = std::unique_ptr<ServerConnection>;
     634             : 
     635             : /**
     636             :  * A client side HTTP connection.
     637             :  */
     638             : class ClientConnection : public virtual Connection {
     639             : public:
     640             :   /**
     641             :    * Create a new outgoing request stream.
     642             :    * @param response_decoder supplies the decoder callbacks to fire response events into.
     643             :    * @return RequestEncoder& supplies the encoder to write the request into.
     644             :    */
     645             :   virtual RequestEncoder& newStream(ResponseDecoder& response_decoder) PURE;
     646             : };
     647             : 
     648             : using ClientConnectionPtr = std::unique_ptr<ClientConnection>;
     649             : 
     650             : } // namespace Http
     651             : } // namespace Envoy

Generated by: LCOV version 1.15