Repository: envoyproxy/envoy
File: source/extensions/filters/http/ext_authz/ext_authz.cc (C++)

Code before:
  if (!response_headers_to_add_if_absent_.empty()) {
    for (const auto& [key, value] : response_headers_to_add_if_absent_) {
      ENVOY_STREAM_LOG(trace, "'{}':'{}'", *encoder_callbacks_, key.get(), value);
      if (auto header_entry = headers.get(key); header_entry.empty()) {
        if (headers.size() >= headers.maxHeadersCount()) {
          omitted_response_headers = true;
          ENVOY_STREAM_LOG(warn, "Cannot add new response header, header map is full.",
                           *encoder_callbacks_);
          break;
        }
        ENVOY_STREAM_LOG(trace, "ext_authz filter added header(s) to the encoded response:",
                         *encoder_callbacks_);
        headers.addCopy(key, value);
      }
    }
  }

  if (!response_headers_to_overwrite_if_exists_.empty()) {
    for (const auto& [key, value] : response_headers_to_overwrite_if_exists_) {
      ENVOY_STREAM_LOG(trace, "'{}':'{}'", *encoder_callbacks_, key, value);
      if (auto header_entry = headers.get(key); !header_entry.empty()) {
        ENVOY_STREAM_LOG(
            trace, "ext_authz filter set header(s) to the encoded response:", *encoder_callbacks_);
        headers.setCopy(key, value);
      }
    }
  }

  if (omitted_response_headers) {
    stats_.omitted_response_headers_.inc();
  }

  return Http::FilterHeadersStatus::Continue;
}

Http::FilterDataStatus Filter::encodeData(Buffer::Instance&, bool) {
  return Http::FilterDataStatus::Continue;
}

Http::FilterTrailersStatus Filter::encodeTrailers(Http::ResponseTrailerMap&) {
  return Http::FilterTrailersStatus::Continue;
}

Http::FilterMetadataStatus Filter::encodeMetadata(Http::MetadataMap&) {
  return Http::FilterMetadataStatus::Continue;
}

void Filter::setDecoderFilterCallbacks(Http::StreamDecoderFilterCallbacks& callbacks) {
  decoder_callbacks_ = &callbacks;
}


Review comment (suggestion):
Unless, you want to change the logs to include which header was dropped, I think the log should be moved into this block so it only logs once per stream, not once per header.

Code after:
        if (headers.size() >= headers.maxHeadersCount()) {
          omitted_response_headers = true;
          break;
        }
        ENVOY_STREAM_LOG(trace, "ext_authz filter added header(s) to the encoded response:",
                         *encoder_callbacks_);
        headers.addCopy(key, value);
      }
    }
  }

  if (!response_headers_to_overwrite_if_exists_.empty()) {
    for (const auto& [key, value] : response_headers_to_overwrite_if_exists_) {
      ENVOY_STREAM_LOG(trace, "'{}':'{}'", *encoder_callbacks_, key, value);
      if (auto header_entry = headers.get(key); !header_entry.empty()) {
        ENVOY_STREAM_LOG(
            trace, "ext_authz filter set header(s) to the encoded response:", *encoder_callbacks_);
        headers.setCopy(key, value);
      }
    }
  }

  if (omitted_response_headers) {
    ENVOY_LOG_EVERY_POW_2(
        warn, "Some ext_authz response headers weren't added because the header map was full.");
    stats_.omitted_response_headers_.inc();
  }

  return Http::FilterHeadersStatus::Continue;
}

Http::FilterDataStatus Filter::encodeData(Buffer::Instance&, bool) {
  return Http::FilterDataStatus::Continue;
}

Http::FilterTrailersStatus Filter::encodeTrailers(Http::ResponseTrailerMap&) {
  return Http::FilterTrailersStatus::Continue;
}

Http::FilterMetadataStatus Filter::encodeMetadata(Http::MetadataMap&) {
  return Http::FilterMetadataStatus::Continue;
}

void Filter::setDecoderFilterCallbacks(Http::StreamDecoderFilterCallbacks& callbacks) {
  decoder_callbacks_ = &callbacks;
}

void Filter::updateLoggingInfo(const absl::optional<Grpc::Status::GrpcStatus>& grpc_status) {
  if (!config_->emitFilterStateStats()) {
    return;
  }