Repository: envoyproxy/envoy
File: source/common/http/http2/codec_impl.cc (C++)

Code before:
    if (stream && name == static_cast<absl::string_view>(Http::Headers::get().HostLegacy)) {
      // Check if there is already the :authority header
      const auto result = stream->headers().get(Http::Headers::get().Host);
      if (!result.empty()) {
        // Discard the host header value
        return 0;
      }
      // Otherwise use host value as :authority
    }
  }
  return saveHeader(stream_id, std::move(name), std::move(value));
}

Http::Status ServerConnectionImpl::dispatch(Buffer::Instance& data) {
  // Make sure downstream outbound queue was not flooded by the upstream frames.
  RETURN_IF_ERROR(protocol_constraints_.checkOutboundFrameLimits());
  if (should_send_go_away_and_close_on_dispatch_ != nullptr &&
      should_send_go_away_and_close_on_dispatch_->shouldShedLoad()) {
    ConnectionImpl::shutdownNotice();
    sent_go_away_on_dispatch_ = true;
    return envoyOverloadError(
        "Load shed point http2_server_go_away_and_close_on_dispatch triggered");
  }
  if (should_send_go_away_on_dispatch_ != nullptr && !sent_go_away_on_dispatch_ &&
      should_send_go_away_on_dispatch_->shouldShedLoad()) {
    ConnectionImpl::shutdownNotice();
    sent_go_away_on_dispatch_ = true;
  }
  return ConnectionImpl::dispatch(data);
}

absl::optional<int> ServerConnectionImpl::checkHeaderNameForUnderscores(
    [[maybe_unused]] absl::string_view header_name) {
#ifndef ENVOY_ENABLE_UHV
  // This check has been moved to UHV
  if (headers_with_underscores_action_ != envoy::config::core::v3::HttpProtocolOptions::ALLOW &&
      Http::HeaderUtility::headerNameContainsUnderscore(header_name)) {
    if (headers_with_underscores_action_ ==
        envoy::config::core::v3::HttpProtocolOptions::DROP_HEADER) {
      ENVOY_CONN_LOG(debug, "Dropping header with invalid characters in its name: {}", connection_,
                     header_name);
      stats_.incDroppedHeadersWithUnderscores();
      return 0;
    }
    ENVOY_CONN_LOG(debug, "Rejecting request due to header name with underscores: {}", connection_,
                   header_name);
    stats_.incRequestsRejectedWithUnderscoresInHeaders();
    return ERR_TEMPORAL_CALLBACK_FAILURE;
  }
#else
  // Workaround for gcc not understanding [[maybe_unused]] for class members.

Review comment (suggestion):
If this is necessary could you add a comment to explain why then to avoid the future developer/reader be confused? thanks. :)

Code after:
}

Status ClientConnectionImpl::onBeginHeaders(int32_t stream_id) {
  StreamImpl* stream = getStream(stream_id);
  if (stream != nullptr) {
    return stream->onBeginHeaders();
  }
  return codecClientError(absl::StrFormat("stream %d is already gone", stream_id));
}

int ClientConnectionImpl::onHeader(int32_t stream_id, HeaderString&& name, HeaderString&& value) {
  ASSERT(connection_.state() == Network::Connection::State::Open);
  return saveHeader(stream_id, std::move(name), std::move(value));
}

StreamResetReason ClientConnectionImpl::getMessagingErrorResetReason() const {
  connection_.streamInfo().setResponseFlag(StreamInfo::CoreResponseFlag::UpstreamProtocolError);

  return StreamResetReason::ProtocolError;
}

ServerConnectionImpl::ServerConnectionImpl(
    Network::Connection& connection, Http::ServerConnectionCallbacks& callbacks, CodecStats& stats,
    Random::RandomGenerator& random_generator,
    const envoy::config::core::v3::Http2ProtocolOptions& http2_options,
    const uint32_t max_request_headers_kb, const uint32_t max_request_headers_count,
    envoy::config::core::v3::HttpProtocolOptions::HeadersWithUnderscoresAction
        headers_with_underscores_action,
    Server::OverloadManager& overload_manager)
    : ConnectionImpl(connection, stats, random_generator, http2_options, max_request_headers_kb,
                     max_request_headers_count),
      callbacks_(callbacks), headers_with_underscores_action_(headers_with_underscores_action),
      should_send_go_away_on_dispatch_(overload_manager.getLoadShedPoint(
          Server::LoadShedPointName::get().H2ServerGoAwayOnDispatch)),
      should_send_go_away_and_close_on_dispatch_(overload_manager.getLoadShedPoint(
          Server::LoadShedPointName::get().H2ServerGoAwayAndCloseOnDispatch)) {
  ENVOY_LOG_ONCE_IF(trace, should_send_go_away_on_dispatch_ == nullptr,
                    "LoadShedPoint envoy.load_shed_points.http2_server_go_away_on_dispatch is not "
                    "found. Is it configured?");
  ENVOY_LOG_ONCE_IF(
      trace, should_send_go_away_and_close_on_dispatch_ == nullptr,
      "LoadShedPoint envoy.load_shed_points.http2_server_go_away_and_close_on_dispatch is not "
      "found. Is it configured?");
  Http2Options h2_options(http2_options, max_request_headers_kb);

  auto direct_visitor = std::make_unique<Http2Visitor>(this);

#ifdef ENVOY_NGHTTP2
  if (use_oghttp2_library_) {
#endif
    visitor_ = std::move(direct_visitor);