Allow responses to HEAD requests to contain Content-Length or Transfer-Encoding The failing prober sends curl requests with the [`-I` param](http://cs///depot/google3/net/fabric/monitoring/cloud_sdn_management/cep_workflows/csdnm_efg_probers/efg_control_plane_shard0_prober/efg_control_plane_shard0_prober.pb.txt;ws=reubent%2F418520;l=63), meaning it is sending a `HEAD` request. Enforcement of `content_length_or_transfer_encoding_in_bodyless_response` was initially added to the same block where we check if the response should have a body or not. Responses to HEAD requests should not have a body. The logic error there is that, even though a response to a HEAD request cannot have a body, it is still permitted by the RFCs to return headers that describe the body it _would have_. RFC 9110, Section 9.3.2: "The server SHOULD send the same header fields in response to a HEAD request as it would have sent if the request method had been GET". So this check has been moved to been moved to BalsaFrame::ProcessHeader and only limits TE/CL on 1xx and 204. New e2e and unit tests are added to confirm all RFC defined behavior: > A server MAY send a Content-Length header field in a response to a HEAD request (Section 9.3.2); `HEADResponseWithContentLengthAllowed` > A server MAY send a Content-Length header field in a 304 (Not Modified) response `304WithContentLengthAllowed` > A server MUST NOT send a Content-Length header field in any response with a status code of 1xx (Informational) or 204 (No Content) `1xxResponseWithContentLengthDisallowed and 204ResponseWithContentLengthDisallowed` > Transfer-Encoding MAY be sent in a response to a HEAD request or in a 304 (Not Modified) response (Section 15.4.5 of [HTTP]) to a GET request, neither of which includes a message body `304WithTransferEncodingAllowed` and `HEADResponseWithTransferEncodingAllowed` > A server MUST NOT send a Transfer-Encoding header field in any response with a status code of 1xx (Informational) or 204 (No Content). `204WithTransferEncodingDisallowed` Protected by gfe2_reloadable_flag_use_zoll_balsa_http_validation_policy. PiperOrigin-RevId: 949125790
diff --git a/quiche/balsa/balsa_frame.cc b/quiche/balsa/balsa_frame.cc index e5abcf8..60a3e36 100644 --- a/quiche/balsa/balsa_frame.cc +++ b/quiche/balsa/balsa_frame.cc
@@ -878,6 +878,12 @@ } if (!is_trailer) { + if (!is_request_) { + const int response_code = headers->parsed_response_code_; + const bool response_code_forbids_body = + !BalsaHeaders::ResponseCanHaveBody(response_code); + } + if (content_length_idx != 0 && transfer_encoding_idx != 0) { if (http_validation_policy().validate_transfer_encoding && http_validation_policy()