Refine IndeterminateLengthMessageSection enum for BinaryHttpResponse encoding.
The IndeterminateLengthMessageSection enum is updated to provide more granular states, which will be needed for the response decoder implementation.
PiperOrigin-RevId: 854214614
diff --git a/quiche/binary_http/binary_http_message.cc b/quiche/binary_http/binary_http_message.cc
index 2ee5302..b91b3b1 100644
--- a/quiche/binary_http/binary_http_message.cc
+++ b/quiche/binary_http/binary_http_message.cc
@@ -884,7 +884,8 @@
return field_section_length.status();
}
uint64_t total_length = *field_section_length;
- if (!framing_indicator_encoded_) {
+ if (current_section_ ==
+ IndeterminateLengthMessageSection::kFramingIndicator) {
total_length += quiche::QuicheDataWriter::GetVarInt62Len(
kIndeterminateLengthResponseFraming);
}
@@ -895,11 +896,13 @@
std::string data(total_length, '\0');
QuicheDataWriter writer(total_length, data.data());
- if (!framing_indicator_encoded_) {
+ if (current_section_ ==
+ IndeterminateLengthMessageSection::kFramingIndicator) {
if (!writer.WriteVarInt62(kIndeterminateLengthResponseFraming)) {
return absl::InternalError("Failed to write framing indicator.");
}
- framing_indicator_encoded_ = true;
+ current_section_ =
+ IndeterminateLengthMessageSection::kInformationalOrFinalStatusCode;
}
if (status_code.has_value() && !writer.WriteVarInt62(*status_code)) {
return absl::InternalError("Failed to write status code.");
@@ -918,12 +921,20 @@
BinaryHttpResponse::IndeterminateLengthEncoder::GetMessageSectionString(
IndeterminateLengthMessageSection section) const {
switch (section) {
- case IndeterminateLengthMessageSection::kInformationalResponseOrHeader:
- return "InformationalResponseOrHeader";
+ case IndeterminateLengthMessageSection::kFramingIndicator:
+ return "FramingIndicator";
+ case IndeterminateLengthMessageSection::kInformationalOrFinalStatusCode:
+ return "InformationalOrFinalStatusCode";
+ case IndeterminateLengthMessageSection::kInformationalResponseHeader:
+ return "InformationalResponseHeader";
+ case IndeterminateLengthMessageSection::kFinalResponseHeader:
+ return "FinalResponseHeader";
case IndeterminateLengthMessageSection::kBody:
return "Body";
case IndeterminateLengthMessageSection::kTrailer:
return "Trailer";
+ case IndeterminateLengthMessageSection::kPadding:
+ return "Padding";
case IndeterminateLengthMessageSection::kEnd:
return "End";
default:
@@ -935,7 +946,9 @@
BinaryHttpResponse::IndeterminateLengthEncoder::EncodeInformationalResponse(
uint16_t status_code, absl::Span<FieldView> fields) {
if (current_section_ !=
- IndeterminateLengthMessageSection::kInformationalResponseOrHeader) {
+ IndeterminateLengthMessageSection::kFramingIndicator &&
+ current_section_ !=
+ IndeterminateLengthMessageSection::kInformationalOrFinalStatusCode) {
current_section_ = IndeterminateLengthMessageSection::kEnd;
return absl::InvalidArgumentError(absl::StrCat(
"EncodeInformationalResponse called in incorrect section: ",
@@ -951,7 +964,8 @@
if (!data.ok()) {
current_section_ = IndeterminateLengthMessageSection::kEnd;
}
-
+ current_section_ =
+ IndeterminateLengthMessageSection::kInformationalOrFinalStatusCode;
return data;
}
@@ -959,7 +973,9 @@
BinaryHttpResponse::IndeterminateLengthEncoder::EncodeHeaders(
uint16_t status_code, absl::Span<FieldView> headers) {
if (current_section_ !=
- IndeterminateLengthMessageSection::kInformationalResponseOrHeader) {
+ IndeterminateLengthMessageSection::kFramingIndicator &&
+ current_section_ !=
+ IndeterminateLengthMessageSection::kInformationalOrFinalStatusCode) {
current_section_ = IndeterminateLengthMessageSection::kEnd;
return absl::InvalidArgumentError(
absl::StrCat("EncodeHeaders called in incorrect section: ",
diff --git a/quiche/binary_http/binary_http_message.h b/quiche/binary_http/binary_http_message.h
index da467f9..921249c 100644
--- a/quiche/binary_http/binary_http_message.h
+++ b/quiche/binary_http/binary_http_message.h
@@ -421,9 +421,13 @@
private:
enum class IndeterminateLengthMessageSection {
- kInformationalResponseOrHeader,
+ kFramingIndicator,
+ kInformationalOrFinalStatusCode,
+ kInformationalResponseHeader,
+ kFinalResponseHeader,
kBody,
kTrailer,
+ kPadding,
kEnd,
};
// Returns Binary Http known length request formatted response.
@@ -463,8 +467,7 @@
IndeterminateLengthMessageSection section) const;
IndeterminateLengthMessageSection current_section_ =
- IndeterminateLengthMessageSection::kInformationalResponseOrHeader;
- bool framing_indicator_encoded_ = false;
+ IndeterminateLengthMessageSection::kFramingIndicator;
};
void QUICHE_EXPORT PrintTo(const BinaryHttpResponse& msg, std::ostream* os);