Allow content-type parameters in MASQUE/OHTTP test code PiperOrigin-RevId: 847230837
diff --git a/quiche/quic/masque/masque_ohttp_client.cc b/quiche/quic/masque/masque_ohttp_client.cc index 8461afb..65ef668 100644 --- a/quiche/quic/masque/masque_ohttp_client.cc +++ b/quiche/quic/masque/masque_ohttp_client.cc
@@ -8,6 +8,7 @@ #include <ostream> #include <string> #include <utility> +#include <vector> #include "absl/cleanup/cleanup.h" #include "absl/status/status.h" @@ -15,6 +16,7 @@ #include "absl/strings/match.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" +#include "absl/strings/str_split.h" #include "absl/strings/string_view.h" #include "openssl/base.h" #include "quiche/quic/masque/masque_connection_pool.h" @@ -22,6 +24,7 @@ #include "quiche/binary_http/binary_http_message.h" #include "quiche/common/platform/api/quiche_logging.h" #include "quiche/common/quiche_status_utils.h" +#include "quiche/common/quiche_text_utils.h" #include "quiche/oblivious_http/buffers/oblivious_http_request.h" #include "quiche/oblivious_http/buffers/oblivious_http_response.h" #include "quiche/oblivious_http/common/oblivious_http_header_key_config.h" @@ -135,7 +138,12 @@ return absl::InvalidArgumentError( absl::StrCat("No content-type header in ", content_type, " response.")); } - if (content_type_it->second != content_type) { + std::vector<absl::string_view> content_type_split = + absl::StrSplit(content_type_it->second, absl::MaxSplits(';', 1)); + absl::string_view content_type_without_params = content_type_split[0]; + quiche::QuicheTextUtils::RemoveLeadingAndTrailingWhitespace( + &content_type_without_params); + if (content_type_without_params != content_type) { return absl::InvalidArgumentError( absl::StrCat("Unexpected content-type in ", content_type, " response: ", content_type_it->second));
diff --git a/quiche/quic/masque/masque_tcp_server_bin.cc b/quiche/quic/masque/masque_tcp_server_bin.cc index ca3fd56..f8538b2 100644 --- a/quiche/quic/masque/masque_tcp_server_bin.cc +++ b/quiche/quic/masque/masque_tcp_server_bin.cc
@@ -120,17 +120,19 @@ namespace { +absl::string_view RemoveParameters(absl::string_view value) { + std::vector<absl::string_view> split = + absl::StrSplit(value, absl::MaxSplits(';', 1)); + absl::string_view without_params = split[0]; + quiche::QuicheTextUtils::RemoveLeadingAndTrailingWhitespace(&without_params); + return without_params; +} + bool ListHeaderContainsValue(absl::string_view header, absl::string_view value) { std::vector<absl::string_view> header_split = absl::StrSplit(header, ','); for (absl::string_view header_value : header_split) { - quiche::QuicheTextUtils::RemoveLeadingAndTrailingWhitespace(&header_value); - std::vector<absl::string_view> header_value_split = - absl::StrSplit(header_value, absl::MaxSplits(';', 1)); - absl::string_view header_value_without_params = header_value_split[0]; - quiche::QuicheTextUtils::RemoveLeadingAndTrailingWhitespace( - &header_value_without_params); - if (header_value_without_params == value) { + if (RemoveParameters(header_value) == value) { return true; } } @@ -610,7 +612,11 @@ std::vector<absl::string_view> path_parts = absl::StrSplit(path_pair->second, absl::MaxSplits('?', 1)); absl::string_view path = path_parts[0]; + absl::string_view content_type; auto content_type_pair = headers.find("content-type"); + if (content_type_pair != headers.end()) { + content_type = RemoveParameters(content_type_pair->second); + } auto accept_pair = headers.find("accept"); if (!gateway_path_.empty() && path == gateway_path_ && masque_ohttp_gateway_ && method_pair->second == "GET" && @@ -640,8 +646,7 @@ } else if (auto relay_pair = relay_gateway_urls_.find(path); relay_pair != relay_gateway_urls_.end() && method_pair->second == "POST" && - content_type_pair != headers.end() && - content_type_pair->second == "message/ohttp-req") { + content_type == "message/ohttp-req") { absl::Status status = HandleOhttpRelayRequest(connection, stream_id, body, relay_pair->second); if (status.ok()) { @@ -654,8 +659,7 @@ } } else if (!gateway_path_.empty() && path == gateway_path_ && method_pair->second == "POST" && - content_type_pair != headers.end() && - content_type_pair->second == "message/ohttp-req") { + content_type == "message/ohttp-req") { absl::Status status = HandleOhttpGatewayRequest(connection, stream_id, body); if (status.ok()) {