HeaderKeyFormatterConstPtr encodeOnlyFormatterFromSettings(const Http::Http1Settings& settings) {
StatefulHeaderKeyFormatterPtr statefulFormatterFromSettings(const Http::Http1Settings& settings) {
const uint64_t header_size = connection_.buffer().addFragments({key, COLON_SPACE, value, CRLF});
// There is no header field compression in HTTP/1.1, so the wire representation is the same as the
void ServerConnectionImpl::maybeAddSentinelBufferFragment(Buffer::Instance& output_buffer) {
// When the response is written out, the fragment will be deleted and the counter will be updated
Buffer::OwnedBufferFragmentImpl::create(absl::string_view("", 0), response_buffer_releasor_);
void ResponseEncoderImpl::encodeHeaders(const ResponseHeaderMap& headers, bool end_stream) {
encodeHeadersBase(headers, absl::make_optional<uint64_t>(numeric_status), end_stream, false);
Status RequestEncoderImpl::encodeHeaders(const RequestHeaderMap& headers, bool end_stream) {
// Headers are now validated by UHV before encoding by the codec. Two checks below are not needed
// Required headers must be present. This can only happen by some erroneous processing after the
ConnectionImpl::setAndCheckCallbackStatusOr(Envoy::StatusOr<CallbackResult>&& statusor) {
deferred_end_stream_headers_(false), dispatching_(false), max_headers_kb_(max_headers_kb),
parser_ = std::make_unique<BalsaParser>(type, this, max_headers_kb_ * 1024, enableTrailers(),
// protocol for each request. Envoy defaults to 1.1 but sets the protocol to 1.0 where applicable
return codecProtocolError("http/1.1 protocol error: extraneous data after response complete");
// There is no header field compression in HTTP/1.1, so the wire representation is the same as the
getBytesMeter().addDecompressedHeaderBytesReceived(getBytesMeter().headerBytesReceived());
const absl::string_view encoding = request_or_response_headers.getTransferEncodingValue();
// Returning CallbackResult::NoBodyData informs http_parser to not expect a body or further data
ASSERT(parser_->getStatus() == ParserStatus::Ok || parser_->getStatus() == ParserStatus::Paused);
: ConnectionImpl(connection, stats, settings, MessageType::Request, max_request_headers_kb,
Status ServerConnectionImpl::handlePath(RequestHeaderMap& headers, absl::string_view method) {
// Handle the case where response happens prior to request complete. It's up to upper layer code
ENVOY_CONN_LOG(trace, "Server: onHeadersComplete size={}", connection_, headers->size());
active_request_ = std::make_unique<ActiveRequest>(*this, std::move(bytes_meter_before_stream_));
active_request_->request_decoder_ = &callbacks_.newStream(active_request_->response_encoder_);
// Read disable the connection if the downstream is sending additional data while we are working
// back pressure. However this means that the calling code needs to detect if there is more data
if (headers_with_underscores_action_ != envoy::config::core::v3::HttpProtocolOptions::ALLOW &&
Http::HeaderUtility::headerNameContainsUnderscore(current_header_field_.getStringView())) {
ENVOY_CONN_LOG(debug, "Dropping header with invalid characters in its name: {}", connection_,
void ServerConnectionImpl::ActiveRequest::dumpState(std::ostream& os, int indent_level) const {
// If reads were disabled due to flow control, we expect reads to always be enabled again before
pending_response_.emplace(*this, std::move(bytes_meter_before_stream_), &response_decoder);
ENVOY_CONN_LOG(trace, "Client: onHeadersComplete size={}", connection_, headers->size());
if (parser_->statusCode() < Http::Code::OK || parser_->statusCode() == Http::Code::NoContent) {
// After calling decodeData() with end stream set to true, we should no longer be able to reset.
// Encoder is used as part of decode* calls later in this function so pending_response_ can not
ENVOY_CONN_LOG(trace, "Resetting stream due to premature H/1 upstream close.", connection_);
// This can get called without an active stream/request when the response completion causes us to