Repository: envoyproxy/envoy
File: envoy/http/filter.h (C/C++)

Code before:
  /**
   * Attempts to create a locally generated response using the provided response_code and body_text
   * parameters. If the request was a gRPC request the local reply will be encoded as a gRPC
   * response with a 200 HTTP response code and grpc-status and grpc-message headers mapped from the
   * provided parameters.
   *
   * If a response has already started (e.g. if the router calls sendLocalReply after encoding
   * headers) this will either ship the reply directly to the downstream codec, or reset the stream.
   *
   * @param response_code supplies the HTTP response code.
   * @param body_text supplies the optional body text which is sent using the text/plain content
   *                  type, or encoded in the grpc-message header.
   * @param modify_headers supplies an optional callback function that can modify the
   *                       response headers.
   * @param grpc_status the gRPC status code to override the httpToGrpcStatus mapping with.
   * @param details a string detailing why this local reply was sent.
   */
  virtual void sendLocalReply(Code response_code, absl::string_view body_text,
                              std::function<void(ResponseHeaderMap& headers)> modify_headers,
                              const absl::optional<Grpc::Status::GrpcStatus> grpc_status,
                              absl::string_view details) PURE;

  /**
   * Attempt to send GOAWAY and close the connection, and no filter chain will move forward.
   */
  virtual void sendGoAwayAndClose(bool immediate_close = false) PURE;

  /**
   * Adds decoded metadata. This function can only be called in
   * StreamDecoderFilter::decodeHeaders/Data/Trailers(). Do not call in
   * StreamDecoderFilter::decodeMetadata().
   *
   * @return a reference to metadata map vector, where new metadata map can be added.
   */
  virtual MetadataMapVector& addDecodedMetadata() PURE;

  /**
   * Called with 1xx headers to be encoded.
   *
   * Currently supported codes for this function include 100.
   *
   * This is not folded into encodeHeaders because most Envoy users and filters will not be proxying
   * 1xx headers and with it split out, can ignore the complexity of multiple encodeHeaders calls.
   *
   * This is currently only called once per request but implementations should
   * handle multiple calls as multiple 1xx headers are legal.
   *
   * @param headers supplies the headers to be encoded.
   */
  virtual void encode1xxHeaders(ResponseHeaderMapPtr&& headers) PURE;


Review comment (suggestion):
Default behavior should be true to avoid behavior change. Or we should provide a parameter named `bool graceful = false` (like our /drain_listeners admin interface)

```suggestion
  virtual void sendGoAwayAndClose(bool immediate_close = true) PURE;
```

Code after:
  /**
   * Attempts to create a locally generated response using the provided response_code and body_text
   * parameters. If the request was a gRPC request the local reply will be encoded as a gRPC
   * response with a 200 HTTP response code and grpc-status and grpc-message headers mapped from the
   * provided parameters.
   *
   * If a response has already started (e.g. if the router calls sendLocalReply after encoding
   * headers) this will either ship the reply directly to the downstream codec, or reset the stream.
   *
   * @param response_code supplies the HTTP response code.
   * @param body_text supplies the optional body text which is sent using the text/plain content
   *                  type, or encoded in the grpc-message header.
   * @param modify_headers supplies an optional callback function that can modify the
   *                       response headers.
   * @param grpc_status the gRPC status code to override the httpToGrpcStatus mapping with.
   * @param details a string detailing why this local reply was sent.
   */
  virtual void sendLocalReply(Code response_code, absl::string_view body_text,
                              std::function<void(ResponseHeaderMap& headers)> modify_headers,
                              const absl::optional<Grpc::Status::GrpcStatus> grpc_status,
                              absl::string_view details) PURE;

  /**
   * Attempt to send GOAWAY and close the connection, and no filter chain will move forward.
   */
  virtual void sendGoAwayAndClose(bool graceful = false) PURE;

  /**
   * Adds decoded metadata. This function can only be called in
   * StreamDecoderFilter::decodeHeaders/Data/Trailers(). Do not call in
   * StreamDecoderFilter::decodeMetadata().
   *
   * @return a reference to metadata map vector, where new metadata map can be added.
   */
  virtual MetadataMapVector& addDecodedMetadata() PURE;

  /**
   * Called with 1xx headers to be encoded.
   *
   * Currently supported codes for this function include 100.
   *
   * This is not folded into encodeHeaders because most Envoy users and filters will not be proxying
   * 1xx headers and with it split out, can ignore the complexity of multiple encodeHeaders calls.
   *
   * This is currently only called once per request but implementations should
   * handle multiple calls as multiple 1xx headers are legal.
   *
   * @param headers supplies the headers to be encoded.
   */
  virtual void encode1xxHeaders(ResponseHeaderMapPtr&& headers) PURE;