void Filter::onStreamMaxDurationReached(UpstreamRequest& upstream_request) {
  upstream_request.resetStream();

  if (maybeRetryReset(Http::StreamResetReason::LocalReset, upstream_request)) {
    return;
  }

  upstream_request.removeFromList(upstream_requests_);
  cleanup();

  if (downstream_response_started_ &&
      !Runtime::runtimeFeatureEnabled("envoy.reloadable_features.allow_500_after_100")) {
    callbacks_->streamInfo().setResponseCodeDetails(
        StreamInfo::ResponseCodeDetails::get().UpstreamMaxStreamDurationReached);
    callbacks_->resetStream();
  } else {
    callbacks_->streamInfo().setResponseFlag(
        StreamInfo::ResponseFlag::UpstreamMaxStreamDurationReached);
    // sendLocalReply may instead reset the stream if downstream_response_started_ is true.
    callbacks_->sendLocalReply(
        Http::Code::RequestTimeout, "upstream max stream duration reached", modify_headers_,
        absl::nullopt, StreamInfo::ResponseCodeDetails::get().UpstreamMaxStreamDurationReached);
  }
}
void Filter::onStreamMaxDurationReached(UpstreamRequest& upstream_request) {
  upstream_request.resetStream();

  if (maybeRetryReset(Http::StreamResetReason::LocalReset, upstream_request)) {
    return;
  }

  upstream_request.removeFromList(upstream_requests_);
  cleanup();

  if (downstream_response_started_ &&
      !Runtime::runtimeFeatureEnabled("envoy.reloadable_features.allow_500_after_100")) {
    callbacks_->streamInfo().setResponseCodeDetails(
        StreamInfo::ResponseCodeDetails::get().UpstreamMaxStreamDurationReached);
    callbacks_->resetStream();
  } else {
    callbacks_->streamInfo().setResponseFlag(
        StreamInfo::ResponseFlag::UpstreamMaxStreamDurationReached);
     
    callbacks_->sendLocalReply(
        Http::Code::RequestTimeout, "upstream max stream duration reached", modify_headers_,
        absl::nullopt, StreamInfo::ResponseCodeDetails::get().UpstreamMaxStreamDurationReached);
  }
}