Status RequestEncoderImpl::encodeHeaders(const RequestHeaderMap& headers, bool end_stream) {
  // Required headers must be present. This can only happen by some erroneous processing after the
  // downstream codecs decode.
  RETURN_IF_ERROR(HeaderUtility::checkRequiredRequestHeaders(headers));

  const HeaderEntry* method = headers.Method();
  const HeaderEntry* path = headers.Path();
  const HeaderEntry* host = headers.Host();
  bool is_connect = HeaderUtility::isConnect(headers);
  const Http::HeaderValues& header_values = Http::Headers::get();

  if (method->value() == header_values.MethodValues.Head) {
    head_request_ = true;
  } else if (method->value() == header_values.MethodValues.Connect) {
    disableChunkEncoding();
    connection_.connection().enableHalfClose(true);
    connect_request_ = true;
  }
  if (Utility::isUpgrade(headers)) {
    upgrade_request_ = true;
  }

  absl::string_view host_or_path_view;
  if (is_connect) {
    host_or_path_view = host->value().getStringView();
  } else {
    host_or_path_view = path->value().getStringView();
  }

  connection_.buffer().addFragments(
      {method->value().getStringView(), SPACE, host_or_path_view, REQUEST_POSTFIX});

  encodeHeadersBase(headers, absl::nullopt, end_stream,
                    HeaderUtility::requestShouldHaveNoBody(headers));
  return okStatus();
}
Status RequestEncoderImpl::encodeHeaders(const RequestHeaderMap& headers, bool end_stream) {
   
   
  RETURN_IF_ERROR(HeaderUtility::checkRequiredRequestHeaders(headers));

  const HeaderEntry* method = headers.Method();
  const HeaderEntry* path = headers.Path();
  const HeaderEntry* host = headers.Host();
  bool is_connect = HeaderUtility::isConnect(headers);
  const Http::HeaderValues& header_values = Http::Headers::get();

  if (method->value() == header_values.MethodValues.Head) {
    head_request_ = true;
  } else if (method->value() == header_values.MethodValues.Connect) {
    disableChunkEncoding();
    connection_.connection().enableHalfClose(true);
    connect_request_ = true;
  }
  if (Utility::isUpgrade(headers)) {
    upgrade_request_ = true;
  }

  absl::string_view host_or_path_view;
  if (is_connect) {
    host_or_path_view = host->value().getStringView();
  } else {
    host_or_path_view = path->value().getStringView();
  }

  connection_.buffer().addFragments(
      {method->value().getStringView(), SPACE, host_or_path_view, REQUEST_POSTFIX});

  encodeHeadersBase(headers, absl::nullopt, end_stream,
                    HeaderUtility::requestShouldHaveNoBody(headers));
  return okStatus();
}