diff --git a/include/envoy/http/header_map.h b/include/envoy/http/header_map.h index 8a094c1d793ce..eef9498593ec3 100644 --- a/include/envoy/http/header_map.h +++ b/include/envoy/http/header_map.h @@ -118,11 +118,6 @@ class HeaderString { */ char* buffer() { return buffer_.dynamic_; } - /** - * @return a null terminated C string. - */ - const char* c_str() const { return buffer_.ref_; } - /** * @return an absl::string_view. */ @@ -143,14 +138,24 @@ class HeaderString { /** * @return whether a substring exists in the string. + * + * TODO(dnoe): Eliminate this by migrating callers to use string_view find + * directly (#6580) */ - bool find(const char* str) const { return strstr(c_str(), str); } + bool find(const char* str) const { + return getStringView().find(absl::string_view(str)) != absl::string_view::npos; + } /** * Set the value of the string by copying data into it. This overwrites any existing string. */ void setCopy(const char* data, uint32_t size); + /** + * Set the value of the string by copying data into it. This overwrites any existing string. + */ + void setCopy(absl::string_view view); + /** * Set the value of the string to an integer. This overwrites any existing string. */ @@ -173,8 +178,10 @@ class HeaderString { */ Type type() const { return type_; } - bool operator==(const char* rhs) const { return 0 == strcmp(c_str(), rhs); } - bool operator!=(const char* rhs) const { return 0 != strcmp(c_str(), rhs); } + bool operator==(const char* rhs) const { return getStringView() == absl::string_view(rhs); } + bool operator==(absl::string_view rhs) const { return getStringView() == rhs; } + bool operator!=(const char* rhs) const { return getStringView() != absl::string_view(rhs); } + bool operator!=(absl::string_view rhs) const { return getStringView() != rhs; } private: union Buffer { @@ -524,8 +531,8 @@ class HeaderMap { friend std::ostream& operator<<(std::ostream& os, const HeaderMap& headers) { headers.iterate( [](const HeaderEntry& header, void* context) -> HeaderMap::Iterate { - *static_cast(context) - << "'" << header.key().c_str() << "', '" << header.value().c_str() << "'\n"; + *static_cast(context) << "'" << header.key().getStringView() << "', '" + << header.value().getStringView() << "'\n"; return HeaderMap::Iterate::Continue; }, &os); diff --git a/source/common/access_log/access_log_formatter.cc b/source/common/access_log/access_log_formatter.cc index 15a9bdb825b99..6f51ee2cfc615 100644 --- a/source/common/access_log/access_log_formatter.cc +++ b/source/common/access_log/access_log_formatter.cc @@ -434,7 +434,7 @@ std::string HeaderFormatter::format(const Http::HeaderMap& headers) const { if (!header) { header_value_string = UnspecifiedValueString; } else { - header_value_string = header->value().c_str(); + header_value_string = std::string(header->value().getStringView()); } if (max_length_ && header_value_string.length() > max_length_.value()) { diff --git a/source/common/access_log/access_log_impl.cc b/source/common/access_log/access_log_impl.cc index da75fedb5fb78..852b6e4c47461 100644 --- a/source/common/access_log/access_log_impl.cc +++ b/source/common/access_log/access_log_impl.cc @@ -118,9 +118,10 @@ bool RuntimeFilter::evaluate(const StreamInfo::StreamInfo&, const Http::HeaderMa const Http::HeaderMap&, const Http::HeaderMap&) { const Http::HeaderEntry* uuid = request_header.RequestId(); uint64_t random_value; + // TODO(dnoe): Migrate uuidModBy to take string_view (#6580) if (use_independent_randomness_ || uuid == nullptr || !UuidUtils::uuidModBy( - uuid->value().c_str(), random_value, + std::string(uuid->value().getStringView()), random_value, ProtobufPercentHelper::fractionalPercentDenominatorToInt(percent_.denominator()))) { random_value = random_.random(); } diff --git a/source/common/common/utility.h b/source/common/common/utility.h index 9eaddb7f64da1..11bf3735314f2 100644 --- a/source/common/common/utility.h +++ b/source/common/common/utility.h @@ -572,14 +572,13 @@ template struct TrieLookupTable { * exists. * @return false when a value already exists for the given key. */ - bool add(const char* key, Value value, bool overwrite_existing = true) { + bool add(absl::string_view key, Value value, bool overwrite_existing = true) { TrieEntry* current = &root_; - while (uint8_t c = *key) { + for (uint8_t c : key) { if (!current->entries_[c]) { current->entries_[c] = std::make_unique>(); } current = current->entries_[c].get(); - key++; } if (current->value_ && !overwrite_existing) { return false; @@ -593,13 +592,11 @@ template struct TrieLookupTable { * @param key the key used to find. * @return the value associated with the key. */ - Value find(const char* key) const { + Value find(absl::string_view key) const { const TrieEntry* current = &root_; - while (uint8_t c = *key) { + for (uint8_t c : key) { current = current->entries_[c].get(); - if (current) { - key++; - } else { + if (current == nullptr) { return nullptr; } } diff --git a/source/common/grpc/common.cc b/source/common/grpc/common.cc index ee123d02ff01d..40e1077b630a5 100644 --- a/source/common/grpc/common.cc +++ b/source/common/grpc/common.cc @@ -31,7 +31,8 @@ bool Common::hasGrpcContentType(const Http::HeaderMap& headers) { absl::StartsWith(content_type->value().getStringView(), Http::Headers::get().ContentTypeValues.Grpc) && (content_type->value().size() == Http::Headers::get().ContentTypeValues.Grpc.size() || - content_type->value().c_str()[Http::Headers::get().ContentTypeValues.Grpc.size()] == '+'); + content_type->value() + .getStringView()[Http::Headers::get().ContentTypeValues.Grpc.size()] == '+'); } bool Common::isGrpcResponseHeader(const Http::HeaderMap& headers, bool end_stream) { @@ -53,11 +54,13 @@ void Common::chargeStat(const Upstream::ClusterInfo& cluster, const std::string& } cluster.statsScope() .counter(fmt::format("{}.{}.{}.{}", protocol, grpc_service, grpc_method, - grpc_status->value().c_str())) + grpc_status->value().getStringView())) .inc(); uint64_t grpc_status_code; + const std::string grpc_status_string(grpc_status->value().getStringView()); + // TODO(dnoe): Migrate to pure string_view (#6580) const bool success = - StringUtil::atoull(grpc_status->value().c_str(), grpc_status_code) && grpc_status_code == 0; + StringUtil::atoull(grpc_status_string.c_str(), grpc_status_code) && grpc_status_code == 0; chargeStat(cluster, protocol, grpc_service, grpc_method, success); } @@ -85,7 +88,9 @@ absl::optional Common::getGrpcStatus(const Http::HeaderMap& if (!grpc_status_header || grpc_status_header->value().empty()) { return absl::optional(); } - if (!StringUtil::atoull(grpc_status_header->value().c_str(), grpc_status_code) || + // TODO(dnoe): Migrate to pure string_view (#6580) + std::string grpc_status_header_string(grpc_status_header->value().getStringView()); + if (!StringUtil::atoull(grpc_status_header_string.c_str(), grpc_status_code) || grpc_status_code > Status::GrpcStatus::MaximumValid) { return absl::optional(Status::GrpcStatus::InvalidCode); } @@ -94,15 +99,15 @@ absl::optional Common::getGrpcStatus(const Http::HeaderMap& std::string Common::getGrpcMessage(const Http::HeaderMap& trailers) { const auto entry = trailers.GrpcMessage(); - return entry ? entry->value().c_str() : EMPTY_STRING; + return entry ? std::string(entry->value().getStringView()) : EMPTY_STRING; } bool Common::resolveServiceAndMethod(const Http::HeaderEntry* path, std::string* service, std::string* method) { - if (path == nullptr || path->value().c_str() == nullptr) { + if (path == nullptr) { return false; } - const auto parts = StringUtil::splitToken(path->value().c_str(), "/"); + const auto parts = StringUtil::splitToken(path->value().getStringView(), "/"); if (parts.size() != 2) { return false; } @@ -138,8 +143,9 @@ std::chrono::milliseconds Common::getGrpcTimeout(Http::HeaderMap& request_header Http::HeaderEntry* header_grpc_timeout_entry = request_headers.GrpcTimeout(); if (header_grpc_timeout_entry) { uint64_t grpc_timeout; - const char* unit = - StringUtil::strtoull(header_grpc_timeout_entry->value().c_str(), grpc_timeout); + // TODO(dnoe): Migrate to pure string_view (#6580) + std::string grpc_timeout_string(header_grpc_timeout_entry->value().getStringView()); + const char* unit = StringUtil::strtoull(grpc_timeout_string.c_str(), grpc_timeout); if (unit != nullptr && *unit != '\0') { switch (*unit) { case 'H': @@ -231,9 +237,7 @@ void Common::checkForHeaderOnlyError(Http::Message& http_response) { throw Exception(absl::optional(), "bad grpc-status header"); } - const Http::HeaderEntry* grpc_status_message = http_response.headers().GrpcMessage(); - throw Exception(grpc_status_code.value(), - grpc_status_message ? grpc_status_message->value().c_str() : EMPTY_STRING); + throw Exception(grpc_status_code.value(), Common::getGrpcMessage(http_response.headers())); } void Common::validateResponse(Http::Message& http_response) { @@ -255,9 +259,7 @@ void Common::validateResponse(Http::Message& http_response) { } if (grpc_status_code.value() != 0) { - const Http::HeaderEntry* grpc_status_message = http_response.trailers()->GrpcMessage(); - throw Exception(grpc_status_code.value(), - grpc_status_message ? grpc_status_message->value().c_str() : EMPTY_STRING); + throw Exception(grpc_status_code.value(), Common::getGrpcMessage(*http_response.trailers())); } } diff --git a/source/common/grpc/google_async_client_impl.cc b/source/common/grpc/google_async_client_impl.cc index a9798a4971d3e..3a8a180c70ab0 100644 --- a/source/common/grpc/google_async_client_impl.cc +++ b/source/common/grpc/google_async_client_impl.cc @@ -156,7 +156,8 @@ void GoogleAsyncStreamImpl::initialize(bool /*buffer_body_for_retry*/) { initial_metadata.iterate( [](const Http::HeaderEntry& header, void* ctxt) { auto* client_context = static_cast(ctxt); - client_context->AddMetadata(header.key().c_str(), header.value().c_str()); + client_context->AddMetadata(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return Http::HeaderMap::Iterate::Continue; }, &ctxt_); diff --git a/source/common/http/async_client_impl.cc b/source/common/http/async_client_impl.cc index d2de75c1b69e0..0ff58f7e69d62 100644 --- a/source/common/http/async_client_impl.cc +++ b/source/common/http/async_client_impl.cc @@ -113,7 +113,7 @@ void AsyncStreamImpl::encodeTrailers(HeaderMapPtr&& trailers) { } void AsyncStreamImpl::sendHeaders(HeaderMap& headers, bool end_stream) { - if (Http::Headers::get().MethodValues.Head == headers.Method()->value().c_str()) { + if (Http::Headers::get().MethodValues.Head == headers.Method()->value().getStringView()) { is_head_request_ = true; } diff --git a/source/common/http/conn_manager_impl.cc b/source/common/http/conn_manager_impl.cc index 764dc0e179dcb..286ee7855f67b 100644 --- a/source/common/http/conn_manager_impl.cc +++ b/source/common/http/conn_manager_impl.cc @@ -573,7 +573,8 @@ const Network::Connection* ConnectionManagerImpl::ActiveStream::connection() { // e.g. many early returns do not currently handle connection: close properly. void ConnectionManagerImpl::ActiveStream::decodeHeaders(HeaderMapPtr&& headers, bool end_stream) { request_headers_ = std::move(headers); - if (Http::Headers::get().MethodValues.Head == request_headers_->Method()->value().c_str()) { + if (Http::Headers::get().MethodValues.Head == + request_headers_->Method()->value().getStringView()) { is_head_request_ = true; } ENVOY_STREAM_LOG(debug, "request headers complete (end_stream={}):\n{}", *this, end_stream, @@ -661,7 +662,8 @@ void ConnectionManagerImpl::ActiveStream::decodeHeaders(HeaderMapPtr&& headers, // when the allow_absolute_url flag is enabled on the HCM. // https://tools.ietf.org/html/rfc7230#section-5.3 We also need to check for the existence of // :path because CONNECT does not have a path, and we don't support that currently. - if (!request_headers_->Path() || request_headers_->Path()->value().c_str()[0] != '/') { + if (!request_headers_->Path() || request_headers_->Path()->value().getStringView().empty() || + request_headers_->Path()->value().getStringView()[0] != '/') { connection_manager_.stats_.named_.downstream_rq_non_relative_path_.inc(); sendLocalReply(Grpc::Common::hasGrpcContentType(*request_headers_), Code::NotFound, "", nullptr, is_head_request_, absl::nullopt); @@ -779,7 +781,8 @@ void ConnectionManagerImpl::ActiveStream::traceRequest() { // should be used to override the active span's operation. if (req_operation_override) { if (!req_operation_override->value().empty()) { - active_span_->setOperation(req_operation_override->value().c_str()); + // TODO(dnoe): Migrate setOperation to take string_view (#6580) + active_span_->setOperation(std::string(req_operation_override->value().getStringView())); // Clear the decorated operation so won't be used in the response header, as // it has been overridden by the inbound decorator operation request header. @@ -1289,7 +1292,7 @@ void ConnectionManagerImpl::ActiveStream::encodeHeaders(ActiveStreamEncoderFilte // should be used to override the active span's operation. if (resp_operation_override) { if (!resp_operation_override->value().empty() && active_span_) { - active_span_->setOperation(resp_operation_override->value().c_str()); + active_span_->setOperation(std::string(resp_operation_override->value().getStringView())); } // Remove header so not propagated to service. headers.removeEnvoyDecoratorOperation(); @@ -1588,7 +1591,7 @@ bool ConnectionManagerImpl::ActiveStream::createFilterChain() { } if (connection_manager_.config_.filterFactory().createUpgradeFilterChain( - upgrade->value().c_str(), upgrade_map, *this)) { + upgrade->value().getStringView(), upgrade_map, *this)) { state_.successful_upgrade_ = true; connection_manager_.stats_.named_.downstream_cx_upgrades_total_.inc(); connection_manager_.stats_.named_.downstream_cx_upgrades_active_.inc(); diff --git a/source/common/http/conn_manager_utility.cc b/source/common/http/conn_manager_utility.cc index 164b8712c2954..1243d8339fdb3 100644 --- a/source/common/http/conn_manager_utility.cc +++ b/source/common/http/conn_manager_utility.cc @@ -223,7 +223,8 @@ void ConnectionManagerUtility::mutateTracingRequestHeader(HeaderMap& request_hea return; } - std::string x_request_id = request_headers.RequestId()->value().c_str(); + // TODO(dnoe): Migrate uuidModBy and others below to take string_view (#6580) + std::string x_request_id(request_headers.RequestId()->value().getStringView()); uint64_t result; // Skip if x-request-id is corrupted. if (!UuidUtils::uuidModBy(x_request_id, result, 10000)) { diff --git a/source/common/http/header_map_impl.cc b/source/common/http/header_map_impl.cc index 66500d425383d..20747d7e6efe6 100644 --- a/source/common/http/header_map_impl.cc +++ b/source/common/http/header_map_impl.cc @@ -213,6 +213,10 @@ void HeaderString::setCopy(const char* data, uint32_t size) { ASSERT(valid()); } +void HeaderString::setCopy(absl::string_view view) { + this->setCopy(view.data(), static_cast(view.size())); +} + void HeaderString::setInteger(uint64_t value) { switch (type_) { case Type::Reference: { @@ -272,7 +276,7 @@ void HeaderMapImpl::HeaderEntryImpl::value(absl::string_view value) { void HeaderMapImpl::HeaderEntryImpl::value(uint64_t value) { value_.setInteger(value); } void HeaderMapImpl::HeaderEntryImpl::value(const HeaderEntry& header) { - value(header.value().c_str(), header.value().size()); + value(header.value().getStringView()); } #define INLINE_HEADER_STATIC_MAP_ENTRY(name) \ @@ -324,9 +328,9 @@ void HeaderMapImpl::copyFrom(const HeaderMap& header_map) { [](const HeaderEntry& header, void* context) -> HeaderMap::Iterate { // TODO(mattklein123) PERF: Avoid copying here if not necessary. HeaderString key_string; - key_string.setCopy(header.key().c_str(), header.key().size()); + key_string.setCopy(header.key().getStringView()); HeaderString value_string; - value_string.setCopy(header.value().c_str(), header.value().size()); + value_string.setCopy(header.value().getStringView()); static_cast(context)->addViaMove(std::move(key_string), std::move(value_string)); @@ -341,7 +345,7 @@ bool HeaderMapImpl::operator==(const HeaderMapImpl& rhs) const { } for (auto i = headers_.begin(), j = rhs.headers_.begin(); i != headers_.end(); ++i, ++j) { - if (i->key() != j->key().c_str() || i->value() != j->value().c_str()) { + if (i->key() != j->key().getStringView() || i->value() != j->value().getStringView()) { return false; } } @@ -352,14 +356,14 @@ bool HeaderMapImpl::operator==(const HeaderMapImpl& rhs) const { bool HeaderMapImpl::operator!=(const HeaderMapImpl& rhs) const { return !operator==(rhs); } void HeaderMapImpl::insertByKey(HeaderString&& key, HeaderString&& value) { - EntryCb cb = ConstSingleton::get().find(key.c_str()); + EntryCb cb = ConstSingleton::get().find(key.getStringView()); if (cb) { key.clear(); StaticLookupResponse ref_lookup_response = cb(*this); if (*ref_lookup_response.entry_ == nullptr) { maybeCreateInline(ref_lookup_response.entry_, *ref_lookup_response.key_, std::move(value)); } else { - appendToHeader((*ref_lookup_response.entry_)->value(), value.c_str()); + appendToHeader((*ref_lookup_response.entry_)->value(), value.getStringView()); value.clear(); } } else { @@ -371,9 +375,9 @@ void HeaderMapImpl::insertByKey(HeaderString&& key, HeaderString&& value) { void HeaderMapImpl::addViaMove(HeaderString&& key, HeaderString&& value) { // If this is an inline header, we can't addViaMove, because we'll overwrite // the existing value. - auto* entry = getExistingInline(key.c_str()); + auto* entry = getExistingInline(key.getStringView()); if (entry != nullptr) { - appendToHeader(entry->value(), value.c_str()); + appendToHeader(entry->value(), value.getStringView()); key.clear(); value.clear(); } else { @@ -404,7 +408,7 @@ void HeaderMapImpl::addReferenceKey(const LowerCaseString& key, const std::strin } void HeaderMapImpl::addCopy(const LowerCaseString& key, uint64_t value) { - auto* entry = getExistingInline(key.get().c_str()); + auto* entry = getExistingInline(key.get()); if (entry != nullptr) { char buf[32]; StringUtil::itoa(buf, sizeof(buf), value); @@ -421,7 +425,7 @@ void HeaderMapImpl::addCopy(const LowerCaseString& key, uint64_t value) { } void HeaderMapImpl::addCopy(const LowerCaseString& key, const std::string& value) { - auto* entry = getExistingInline(key.get().c_str()); + auto* entry = getExistingInline(key.get()); if (entry != nullptr) { appendToHeader(entry->value(), value); return; @@ -499,7 +503,7 @@ void HeaderMapImpl::iterateReverse(ConstIterateCb cb, void* context) const { HeaderMap::Lookup HeaderMapImpl::lookup(const LowerCaseString& key, const HeaderEntry** entry) const { - EntryCb cb = ConstSingleton::get().find(key.get().c_str()); + EntryCb cb = ConstSingleton::get().find(key.get()); if (cb) { // The accessor callbacks for predefined inline headers take a HeaderMapImpl& as an argument; // even though we don't make any modifications, we need to cast_cast in order to use the @@ -521,7 +525,7 @@ HeaderMap::Lookup HeaderMapImpl::lookup(const LowerCaseString& key, } void HeaderMapImpl::remove(const LowerCaseString& key) { - EntryCb cb = ConstSingleton::get().find(key.get().c_str()); + EntryCb cb = ConstSingleton::get().find(key.get()); if (cb) { StaticLookupResponse ref_lookup_response = cb(*this); removeInline(ref_lookup_response.entry_); @@ -542,7 +546,7 @@ void HeaderMapImpl::removePrefix(const LowerCaseString& prefix) { if (to_remove) { // If this header should be removed, make sure any references in the // static lookup table are cleared as well. - EntryCb cb = ConstSingleton::get().find(entry.key().c_str()); + EntryCb cb = ConstSingleton::get().find(entry.key().getStringView()); if (cb) { StaticLookupResponse ref_lookup_response = cb(*this); if (ref_lookup_response.entry_) { @@ -580,7 +584,7 @@ HeaderMapImpl::HeaderEntryImpl& HeaderMapImpl::maybeCreateInline(HeaderEntryImpl return **entry; } -HeaderMapImpl::HeaderEntryImpl* HeaderMapImpl::getExistingInline(const char* key) { +HeaderMapImpl::HeaderEntryImpl* HeaderMapImpl::getExistingInline(absl::string_view key) { EntryCb cb = ConstSingleton::get().find(key); if (cb) { StaticLookupResponse ref_lookup_response = cb(*this); diff --git a/source/common/http/header_map_impl.h b/source/common/http/header_map_impl.h index 3bdbd1cd206ee..ffa2e069f33d6 100644 --- a/source/common/http/header_map_impl.h +++ b/source/common/http/header_map_impl.h @@ -138,7 +138,9 @@ class HeaderMapImpl : public HeaderMap, NonCopyable { public: HeaderList() : pseudo_headers_end_(headers_.end()) {} - template bool isPseudoHeader(const Key& key) { return key.c_str()[0] == ':'; } + template bool isPseudoHeader(const Key& key) { + return !key.getStringView().empty() && key.getStringView()[0] == ':'; + } template std::list::iterator insert(Key&& key, Value&&... value) { @@ -189,7 +191,7 @@ class HeaderMapImpl : public HeaderMap, NonCopyable { HeaderEntryImpl& maybeCreateInline(HeaderEntryImpl** entry, const LowerCaseString& key); HeaderEntryImpl& maybeCreateInline(HeaderEntryImpl** entry, const LowerCaseString& key, HeaderString&& value); - HeaderEntryImpl* getExistingInline(const char* key); + HeaderEntryImpl* getExistingInline(absl::string_view key); void removeInline(HeaderEntryImpl** entry); diff --git a/source/common/http/header_utility.cc b/source/common/http/header_utility.cc index d0cea22f11dd0..3a0cd2c05c0aa 100644 --- a/source/common/http/header_utility.cc +++ b/source/common/http/header_utility.cc @@ -87,16 +87,19 @@ bool HeaderUtility::matchHeaders(const Http::HeaderMap& request_headers, } bool match; + const absl::string_view header_view = header->value().getStringView(); switch (header_data.header_match_type_) { case HeaderMatchType::Value: - match = header_data.value_.empty() || header->value() == header_data.value_.c_str(); + match = header_data.value_.empty() || header_view == header_data.value_; break; case HeaderMatchType::Regex: - match = std::regex_match(header->value().c_str(), header_data.regex_pattern_); + match = std::regex_match(header_view.begin(), header_view.end(), header_data.regex_pattern_); break; case HeaderMatchType::Range: { int64_t header_value = 0; - match = StringUtil::atoll(header->value().c_str(), header_value, 10) && + // TODO(dnoe): Migrate to pure string_view to eliminate std:string instance (#6580) + const std::string header_string(header_view); + match = StringUtil::atoll(header_string.c_str(), header_value, 10) && header_value >= header_data.range_.start() && header_value < header_data.range_.end(); break; } @@ -104,10 +107,10 @@ bool HeaderUtility::matchHeaders(const Http::HeaderMap& request_headers, match = true; break; case HeaderMatchType::Prefix: - match = absl::StartsWith(header->value().getStringView(), header_data.value_); + match = absl::StartsWith(header_view, header_data.value_); break; case HeaderMatchType::Suffix: - match = absl::EndsWith(header->value().getStringView(), header_data.value_); + match = absl::EndsWith(header_view, header_data.value_); break; default: NOT_REACHED_GCOVR_EXCL_LINE; @@ -120,9 +123,9 @@ void HeaderUtility::addHeaders(Http::HeaderMap& headers, const Http::HeaderMap& headers_to_add.iterate( [](const Http::HeaderEntry& header, void* context) -> Http::HeaderMap::Iterate { Http::HeaderString k; - k.setCopy(header.key().c_str(), header.key().size()); + k.setCopy(header.key().getStringView()); Http::HeaderString v; - v.setCopy(header.value().c_str(), header.value().size()); + v.setCopy(header.value().getStringView()); static_cast(context)->addViaMove(std::move(k), std::move(v)); return Http::HeaderMap::Iterate::Continue; }, diff --git a/source/common/http/http1/codec_impl.cc b/source/common/http/http1/codec_impl.cc index eda67fa94b5a0..ded79fb00a93c 100644 --- a/source/common/http/http1/codec_impl.cc +++ b/source/common/http/http1/codec_impl.cc @@ -42,6 +42,9 @@ void StreamEncoderImpl::encodeHeader(const char* key, uint32_t key_size, const c connection_.addCharToBuffer('\r'); connection_.addCharToBuffer('\n'); } +void StreamEncoderImpl::encodeHeader(absl::string_view key, absl::string_view value) { + this->encodeHeader(key.data(), key.size(), value.data(), value.size()); +} void StreamEncoderImpl::encode100ContinueHeaders(const HeaderMap& headers) { ASSERT(headers.Status()->value() == "100"); @@ -54,11 +57,11 @@ void StreamEncoderImpl::encodeHeaders(const HeaderMap& headers, bool end_stream) bool saw_content_length = false; headers.iterate( [](const HeaderEntry& header, void* context) -> HeaderMap::Iterate { - const char* key_to_use = header.key().c_str(); + absl::string_view key_to_use = header.key().getStringView(); uint32_t key_size_to_use = header.key().size(); // Translate :authority -> host so that upper layers do not need to deal with this. if (key_size_to_use > 1 && key_to_use[0] == ':' && key_to_use[1] == 'a') { - key_to_use = Headers::get().HostLegacy.get().c_str(); + key_to_use = absl::string_view(Headers::get().HostLegacy.get()); key_size_to_use = Headers::get().HostLegacy.get().size(); } @@ -67,8 +70,8 @@ void StreamEncoderImpl::encodeHeaders(const HeaderMap& headers, bool end_stream) return HeaderMap::Iterate::Continue; } - static_cast(context)->encodeHeader( - key_to_use, key_size_to_use, header.value().c_str(), header.value().size()); + static_cast(context)->encodeHeader(key_to_use, + header.value().getStringView()); return HeaderMap::Iterate::Continue; }, this); @@ -265,14 +268,14 @@ void RequestStreamEncoderImpl::encodeHeaders(const HeaderMap& headers, bool end_ if (!method || !path) { throw CodecClientException(":method and :path must be specified"); } - if (method->value() == Headers::get().MethodValues.Head.c_str()) { + if (method->value() == Headers::get().MethodValues.Head) { head_request_ = true; } connection_.onEncodeHeaders(headers); connection_.reserveBuffer(std::max(4096U, path->value().size() + 4096)); - connection_.copyToBuffer(method->value().c_str(), method->value().size()); + connection_.copyToBuffer(method->value().getStringView().data(), method->value().size()); connection_.addCharToBuffer(' '); - connection_.copyToBuffer(path->value().c_str(), path->value().size()); + connection_.copyToBuffer(path->value().getStringView().data(), path->value().size()); connection_.copyToBuffer(REQUEST_POSTFIX, sizeof(REQUEST_POSTFIX) - 1); StreamEncoderImpl::encodeHeaders(headers, end_stream); @@ -328,7 +331,7 @@ ConnectionImpl::ConnectionImpl(Network::Connection& connection, http_parser_type void ConnectionImpl::completeLastHeader() { ENVOY_CONN_LOG(trace, "completed header: key={} value={}", connection_, - current_header_field_.c_str(), current_header_value_.c_str()); + current_header_field_.getStringView(), current_header_value_.getStringView()); if (!current_header_field_.empty()) { toLowerTable().toLowerCase(current_header_field_.buffer(), current_header_field_.size()); current_header_map_->addViaMove(std::move(current_header_field_), @@ -508,8 +511,9 @@ void ServerConnectionImpl::handlePath(HeaderMapImpl& headers, unsigned int metho bool is_connect = (method == HTTP_CONNECT); // The url is relative or a wildcard when the method is OPTIONS. Nothing to do here. - if (active_request_->request_url_.c_str()[0] == '/' || - ((method == HTTP_OPTIONS) && active_request_->request_url_.c_str()[0] == '*')) { + if (!active_request_->request_url_.getStringView().empty() && + (active_request_->request_url_.getStringView()[0] == '/' || + ((method == HTTP_OPTIONS) && active_request_->request_url_.getStringView()[0] == '*'))) { headers.addViaMove(std::move(path), std::move(active_request_->request_url_)); return; } diff --git a/source/common/http/http1/codec_impl.h b/source/common/http/http1/codec_impl.h index c0e7bf43186b0..27b80e5e5b81b 100644 --- a/source/common/http/http1/codec_impl.h +++ b/source/common/http/http1/codec_impl.h @@ -68,6 +68,13 @@ class StreamEncoderImpl : public StreamEncoder, */ void encodeHeader(const char* key, uint32_t key_size, const char* value, uint32_t value_size); + /** + * Called to encode an individual header. + * @param key supplies the header to encode as a string_view. + * @param value supplies the value to encode as a string_view. + */ + void encodeHeader(absl::string_view key, absl::string_view value); + /** * Called to finalize a stream encode. */ diff --git a/source/common/http/http2/codec_impl.cc b/source/common/http/http2/codec_impl.cc index c1b429752f2bc..465a6734fcde0 100644 --- a/source/common/http/http2/codec_impl.cc +++ b/source/common/http/http2/codec_impl.cc @@ -33,7 +33,8 @@ bool Utility::reconstituteCrumbledCookies(const HeaderString& key, const HeaderS cookies.append("; ", 2); } - cookies.append(value.c_str(), value.size()); + const absl::string_view value_view = value.getStringView(); + cookies.append(value_view.data(), value_view.size()); return true; } @@ -79,9 +80,11 @@ static void insertHeader(std::vector& headers, const HeaderEntry& he if (header.value().type() == HeaderString::Type::Reference) { flags |= NGHTTP2_NV_FLAG_NO_COPY_VALUE; } - headers.push_back({remove_const(header.key().c_str()), - remove_const(header.value().c_str()), header.key().size(), - header.value().size(), flags}); + const absl::string_view header_key = header.key().getStringView(); + const absl::string_view header_value = header.value().getStringView(); + headers.push_back({remove_const(header_key.data()), + remove_const(header_value.data()), header_key.size(), + header_value.size(), flags}); } void ConnectionImpl::StreamImpl::buildHeaders(std::vector& final_headers, diff --git a/source/common/http/http2/codec_impl.h b/source/common/http/http2/codec_impl.h index 339f6ce288f0b..5c3057679a3c8 100644 --- a/source/common/http/http2/codec_impl.h +++ b/source/common/http/http2/codec_impl.h @@ -244,7 +244,7 @@ class ConnectionImpl : public virtual Connection, protected Logger::Loggable& final_headers, nghttp2_data_provider* provider) override; void transformUpgradeFromH1toH2(HeaderMap& headers) override { - upgrade_type_ = headers.Upgrade()->value().c_str(); + upgrade_type_ = std::string(headers.Upgrade()->value().getStringView()); Http::Utility::transformUpgradeRequestFromH1toH2(headers); } void maybeTransformUpgradeFromH2ToH1() override { diff --git a/source/common/http/utility.cc b/source/common/http/utility.cc index 92c787125c630..a2ec61275f5e2 100644 --- a/source/common/http/utility.cc +++ b/source/common/http/utility.cc @@ -88,8 +88,8 @@ void Utility::appendVia(HeaderMap& headers, const std::string& via) { std::string Utility::createSslRedirectPath(const HeaderMap& headers) { ASSERT(headers.Host()); ASSERT(headers.Path()); - return fmt::format("https://{}{}", headers.Host()->value().c_str(), - headers.Path()->value().c_str()); + return fmt::format("https://{}{}", headers.Host()->value().getStringView(), + headers.Path()->value().getStringView()); } Utility::QueryParams Utility::parseQueryString(absl::string_view url) { @@ -121,8 +121,14 @@ Utility::QueryParams Utility::parseQueryString(absl::string_view url) { return params; } -const char* Utility::findQueryStringStart(const HeaderString& path) { - return std::find(path.c_str(), path.c_str() + path.size(), '?'); +absl::string_view Utility::findQueryStringStart(const HeaderString& path) { + absl::string_view path_str = path.getStringView(); + size_t query_offset = path_str.find('?'); + if (query_offset == absl::string_view::npos) { + query_offset = path_str.length(); + } + path_str.remove_prefix(query_offset); + return path_str; } std::string Utility::parseCookieValue(const HeaderMap& headers, const std::string& key) { @@ -138,13 +144,14 @@ std::string Utility::parseCookieValue(const HeaderMap& headers, const std::strin headers.iterateReverse( [](const HeaderEntry& header, void* context) -> HeaderMap::Iterate { // Find the cookie headers in the request (typically, there's only one). - if (header.key() == Http::Headers::get().Cookie.get().c_str()) { + if (header.key() == Http::Headers::get().Cookie.get()) { + // Split the cookie header into individual cookies. - for (const auto s : StringUtil::splitToken(header.value().c_str(), ";")) { + for (const auto s : StringUtil::splitToken(header.value().getStringView(), ";")) { // Find the key part of the cookie (i.e. the name of the cookie). size_t first_non_space = s.find_first_not_of(" "); size_t equals_index = s.find('='); - if (equals_index == std::string::npos) { + if (equals_index == absl::string_view::npos) { // The cookie is malformed if it does not have an `=`. Continue // checking other cookies in this header. continue; @@ -206,15 +213,15 @@ bool Utility::hasSetCookie(const HeaderMap& headers, const std::string& key) { headers.iterate( [](const HeaderEntry& header, void* context) -> HeaderMap::Iterate { // Find the set-cookie headers in the request - if (header.key() == Http::Headers::get().SetCookie.get().c_str()) { - const std::string value{header.value().c_str()}; + if (header.key() == Http::Headers::get().SetCookie.get()) { + const absl::string_view value{header.value().getStringView()}; const size_t equals_index = value.find('='); - if (equals_index == std::string::npos) { + if (equals_index == absl::string_view::npos) { // The cookie is malformed if it does not have an `=`. return HeaderMap::Iterate::Continue; } - std::string k = value.substr(0, equals_index); + absl::string_view k = value.substr(0, equals_index); State* state = static_cast(context); if (k == state->key_) { state->ret_ = true; @@ -231,7 +238,8 @@ bool Utility::hasSetCookie(const HeaderMap& headers, const std::string& key) { uint64_t Utility::getResponseStatus(const HeaderMap& headers) { const HeaderEntry* header = headers.Status(); uint64_t response_code; - if (!header || !StringUtil::atoull(headers.Status()->value().c_str(), response_code)) { + if (!header || !StringUtil::atoull(std::string(headers.Status()->value().getStringView()).c_str(), + response_code)) { throw CodecClientException(":status must be specified and a valid unsigned long"); } return response_code; @@ -247,7 +255,7 @@ bool Utility::isUpgrade(const HeaderMap& headers) { bool Utility::isH2UpgradeRequest(const HeaderMap& headers) { return headers.Method() && - headers.Method()->value().c_str() == Http::Headers::get().MethodValues.Connect && + headers.Method()->value().getStringView() == Http::Headers::get().MethodValues.Connect && headers.Protocol() && !headers.Protocol()->value().empty(); } @@ -349,7 +357,7 @@ Utility::getLastAddressFromXFF(const Http::HeaderMap& request_headers, uint32_t return {nullptr, false}; } - absl::string_view xff_string(xff_header->value().c_str(), xff_header->value().size()); + absl::string_view xff_string(xff_header->value().getStringView()); static const std::string separator(","); // Ignore the last num_to_skip addresses at the end of XFF. for (uint32_t i = 0; i < num_to_skip; i++) { @@ -473,13 +481,13 @@ void Utility::transformUpgradeRequestFromH1toH2(HeaderMap& headers) { const HeaderString& upgrade = headers.Upgrade()->value(); headers.insertMethod().value().setReference(Http::Headers::get().MethodValues.Connect); - headers.insertProtocol().value().setCopy(upgrade.c_str(), upgrade.size()); + headers.insertProtocol().value().setCopy(upgrade.getStringView()); headers.removeUpgrade(); headers.removeConnection(); // nghttp2 rejects upgrade requests/responses with content length, so strip // any unnecessary content length header. if (headers.ContentLength() != nullptr && - absl::string_view("0") == headers.ContentLength()->value().c_str()) { + headers.ContentLength()->value().getStringView() == "0") { headers.removeContentLength(); } } @@ -491,7 +499,7 @@ void Utility::transformUpgradeResponseFromH1toH2(HeaderMap& headers) { headers.removeUpgrade(); headers.removeConnection(); if (headers.ContentLength() != nullptr && - absl::string_view("0") == headers.ContentLength()->value().c_str()) { + headers.ContentLength()->value().getStringView() == "0") { headers.removeContentLength(); } } @@ -501,14 +509,14 @@ void Utility::transformUpgradeRequestFromH2toH1(HeaderMap& headers) { const HeaderString& protocol = headers.Protocol()->value(); headers.insertMethod().value().setReference(Http::Headers::get().MethodValues.Get); - headers.insertUpgrade().value().setCopy(protocol.c_str(), protocol.size()); + headers.insertUpgrade().value().setCopy(protocol.getStringView()); headers.insertConnection().value().setReference(Http::Headers::get().ConnectionValues.Upgrade); headers.removeProtocol(); } void Utility::transformUpgradeResponseFromH2toH1(HeaderMap& headers, absl::string_view upgrade) { if (getResponseStatus(headers) == 200) { - headers.insertUpgrade().value().setCopy(upgrade.data(), upgrade.size()); + headers.insertUpgrade().value().setCopy(upgrade); headers.insertConnection().value().setReference(Http::Headers::get().ConnectionValues.Upgrade); headers.insertStatus().value().setInteger(101); } diff --git a/source/common/http/utility.h b/source/common/http/utility.h index 5c4526ba9b3d2..24cb394c6fa32 100644 --- a/source/common/http/utility.h +++ b/source/common/http/utility.h @@ -70,10 +70,11 @@ QueryParams parseQueryString(absl::string_view url); /** * Finds the start of the query string in a path * @param path supplies a HeaderString& to search for the query string - * @return const char* a pointer to the beginning of the query string, or the end of the - * path if there is no query + * @return absl::string_view starting at the beginning of the query string, + * or a string_view starting at the end of the path if there was + * no query string. */ -const char* findQueryStringStart(const HeaderString& path); +absl::string_view findQueryStringStart(const HeaderString& path); /** * Parse a particular value out of a cookie diff --git a/source/common/router/config_impl.cc b/source/common/router/config_impl.cc index d17e0e56f4ca5..1b119c123328d 100644 --- a/source/common/router/config_impl.cc +++ b/source/common/router/config_impl.cc @@ -178,7 +178,7 @@ class HeaderHashMethod : public HashMethodImplBase { const Http::HeaderEntry* header = headers.get(header_name_); if (header) { - hash = HashUtil::xxHash64(header->value().c_str()); + hash = HashUtil::xxHash64(header->value().getStringView()); } return hash; } @@ -436,7 +436,7 @@ bool RouteEntryImplBase::matchRoute(const Http::HeaderMap& headers, uint64_t ran matches &= Http::HeaderUtility::matchHeaders(headers, config_headers_); if (!config_query_parameters_.empty()) { Http::Utility::QueryParams query_parameters = - Http::Utility::parseQueryString(headers.Path()->value().c_str()); + Http::Utility::parseQueryString(headers.Path()->value().getStringView()); matches &= ConfigUtility::matchQueryParams(query_parameters, config_query_parameters_); } @@ -494,7 +494,7 @@ void RouteEntryImplBase::finalizePathHeader(Http::HeaderMap& headers, return; } - std::string path = std::string(headers.Path()->value().c_str(), headers.Path()->value().size()); + std::string path(headers.Path()->value().getStringView()); if (insert_envoy_original_path) { headers.insertEnvoyOriginalPath().value(*headers.Path()); } @@ -542,7 +542,7 @@ absl::string_view RouteEntryImplBase::processRequestHost(const Http::HeaderMap& std::string RouteEntryImplBase::newPath(const Http::HeaderMap& headers) const { ASSERT(isDirectResponse()); - const char* final_scheme; + absl::string_view final_scheme; absl::string_view final_host; absl::string_view final_port; absl::string_view final_path; @@ -550,10 +550,10 @@ std::string RouteEntryImplBase::newPath(const Http::HeaderMap& headers) const { if (!scheme_redirect_.empty()) { final_scheme = scheme_redirect_.c_str(); } else if (https_redirect_) { - final_scheme = Http::Headers::get().SchemeValues.Https.c_str(); + final_scheme = Http::Headers::get().SchemeValues.Https; } else { ASSERT(headers.ForwardedProto()); - final_scheme = headers.ForwardedProto()->value().c_str(); + final_scheme = headers.ForwardedProto()->value().getStringView(); } if (!port_redirect_.empty()) { @@ -573,7 +573,7 @@ std::string RouteEntryImplBase::newPath(const Http::HeaderMap& headers) const { final_path = path_redirect_.c_str(); } else { ASSERT(headers.Path()); - final_path = absl::string_view(headers.Path()->value().c_str(), headers.Path()->value().size()); + final_path = headers.Path()->value().getStringView(); if (strip_query_) { size_t path_end = final_path.find("?"); if (path_end != absl::string_view::npos) { @@ -677,7 +677,7 @@ RouteConstSharedPtr RouteEntryImplBase::clusterEntry(const Http::HeaderMap& head const Http::HeaderEntry* entry = headers.get(cluster_header_name_); std::string final_cluster_name; if (entry) { - final_cluster_name = entry->value().c_str(); + final_cluster_name = std::string(entry->value().getStringView()); } // NOTE: Though we return a shared_ptr here, the current ownership model assumes that @@ -790,17 +790,17 @@ RouteConstSharedPtr PathRouteEntryImpl::matches(const Http::HeaderMap& headers, uint64_t random_value) const { if (RouteEntryImplBase::matchRoute(headers, random_value)) { const Http::HeaderString& path = headers.Path()->value(); - const char* query_string_start = Http::Utility::findQueryStringStart(path); + absl::string_view query_string = Http::Utility::findQueryStringStart(path); size_t compare_length = path.size(); - if (query_string_start != nullptr) { - compare_length = query_string_start - path.c_str(); + if (query_string.length() > 0) { + compare_length = compare_length - query_string.length(); } if (compare_length != path_.size()) { return nullptr; } - absl::string_view path_section(path.c_str(), compare_length); + const absl::string_view path_section = path.getStringView().substr(0, compare_length); if (case_sensitive_) { if (absl::string_view(path_) == path_section) { return clusterEntry(headers, random_value); @@ -824,11 +824,14 @@ RegexRouteEntryImpl::RegexRouteEntryImpl(const VirtualHostImpl& vhost, void RegexRouteEntryImpl::rewritePathHeader(Http::HeaderMap& headers, bool insert_envoy_original_path) const { const Http::HeaderString& path = headers.Path()->value(); - const char* query_string_start = Http::Utility::findQueryStringStart(path); + const absl::string_view query_string = Http::Utility::findQueryStringStart(path); + const size_t path_string_length = path.size() - query_string.length(); // TODO(yuval-k): This ASSERT can happen if the path was changed by a filter without clearing the // route cache. We should consider if ASSERT-ing is the desired behavior in this case. - ASSERT(std::regex_match(path.c_str(), query_string_start, regex_)); - std::string matched_path(path.c_str(), query_string_start); + + const absl::string_view path_view = path.getStringView(); + ASSERT(std::regex_match(path_view.begin(), path_view.begin() + path_string_length, regex_)); + const std::string matched_path(path_view.begin(), path_view.begin() + path_string_length); finalizePathHeader(headers, matched_path, insert_envoy_original_path); } @@ -837,8 +840,10 @@ RouteConstSharedPtr RegexRouteEntryImpl::matches(const Http::HeaderMap& headers, uint64_t random_value) const { if (RouteEntryImplBase::matchRoute(headers, random_value)) { const Http::HeaderString& path = headers.Path()->value(); - const char* query_string_start = Http::Utility::findQueryStringStart(path); - if (std::regex_match(path.c_str(), query_string_start, regex_)) { + const absl::string_view query_string = Http::Utility::findQueryStringStart(path); + if (std::regex_match(path.getStringView().begin(), + path.getStringView().begin() + (path.size() - query_string.length()), + regex_)) { return clusterEntry(headers, random_value); } } @@ -1026,7 +1031,8 @@ const VirtualHostImpl* RouteMatcher::findVirtualHost(const Http::HeaderMap& head // TODO (@rshriram) Match Origin header in WebSocket // request with VHost, using wildcard match - const std::string host = Http::LowerCaseString(headers.Host()->value().c_str()).get(); + const std::string host = + Http::LowerCaseString(std::string(headers.Host()->value().getStringView())).get(); const auto& iter = virtual_hosts_.find(host); if (iter != virtual_hosts_.end()) { return iter->second.get(); @@ -1069,9 +1075,10 @@ const VirtualCluster* VirtualHostImpl::virtualClusterFromEntries(const Http::HeaderMap& headers) const { for (const VirtualClusterEntry& entry : virtual_clusters_) { bool method_matches = - !entry.method_ || headers.Method()->value().c_str() == entry.method_.value(); + !entry.method_ || headers.Method()->value().getStringView() == entry.method_.value(); - if (method_matches && std::regex_match(headers.Path()->value().c_str(), entry.pattern_)) { + absl::string_view path_view = headers.Path()->value().getStringView(); + if (method_matches && std::regex_match(path_view.begin(), path_view.end(), entry.pattern_)) { return &entry; } } diff --git a/source/common/router/retry_state_impl.cc b/source/common/router/retry_state_impl.cc index 84e1863176031..3d84a4208e260 100644 --- a/source/common/router/retry_state_impl.cc +++ b/source/common/router/retry_state_impl.cc @@ -66,15 +66,16 @@ RetryStateImpl::RetryStateImpl(const RetryPolicy& route_policy, Http::HeaderMap& // Merge in the headers. if (request_headers.EnvoyRetryOn()) { - retry_on_ |= parseRetryOn(request_headers.EnvoyRetryOn()->value().c_str()); + retry_on_ |= parseRetryOn(request_headers.EnvoyRetryOn()->value().getStringView()); } if (request_headers.EnvoyRetryGrpcOn()) { - retry_on_ |= parseRetryGrpcOn(request_headers.EnvoyRetryGrpcOn()->value().c_str()); + retry_on_ |= parseRetryGrpcOn(request_headers.EnvoyRetryGrpcOn()->value().getStringView()); } if (retry_on_ != 0 && request_headers.EnvoyMaxRetries()) { - const char* max_retries = request_headers.EnvoyMaxRetries()->value().c_str(); + // TODO(dnoe): Migrate to pure string_view (#6580) + const std::string max_retries(request_headers.EnvoyMaxRetries()->value().getStringView()); uint64_t temp; - if (StringUtil::atoull(max_retries, temp)) { + if (StringUtil::atoull(max_retries.c_str(), temp)) { // The max retries header takes precedence if set. retries_remaining_ = temp; } diff --git a/source/common/router/router.cc b/source/common/router/router.cc index 72c9576a43d9f..3ea401798ad52 100644 --- a/source/common/router/router.cc +++ b/source/common/router/router.cc @@ -34,8 +34,9 @@ uint32_t getLength(const Buffer::Instance* instance) { return instance ? instanc bool schemeIsHttp(const Http::HeaderMap& downstream_headers, const Network::Connection& connection) { - if (downstream_headers.ForwardedProto() && downstream_headers.ForwardedProto()->value().c_str() == - Http::Headers::get().SchemeValues.Http) { + if (downstream_headers.ForwardedProto() && + downstream_headers.ForwardedProto()->value().getStringView() == + Http::Headers::get().SchemeValues.Http) { return true; } if (!connection.ssl()) { @@ -138,7 +139,9 @@ FilterUtility::finalTimeout(const RouteEntry& route, Http::HeaderMap& request_he Http::HeaderEntry* header_timeout_entry = request_headers.EnvoyUpstreamRequestTimeoutMs(); uint64_t header_timeout; if (header_timeout_entry) { - if (StringUtil::atoull(header_timeout_entry->value().c_str(), header_timeout)) { + // TODO(dnoe): Migrate to pure string_view (#6580) + if (StringUtil::atoull(std::string(header_timeout_entry->value().getStringView()).c_str(), + header_timeout)) { timeout.global_timeout_ = std::chrono::milliseconds(header_timeout); } request_headers.removeEnvoyUpstreamRequestTimeoutMs(); @@ -147,7 +150,9 @@ FilterUtility::finalTimeout(const RouteEntry& route, Http::HeaderMap& request_he // See if there is a per try/retry timeout. If it's >= global we just ignore it. Http::HeaderEntry* per_try_timeout_entry = request_headers.EnvoyUpstreamRequestPerTryTimeoutMs(); if (per_try_timeout_entry) { - if (StringUtil::atoull(per_try_timeout_entry->value().c_str(), header_timeout)) { + // TODO(dnoe): Migrate to pure string_view (#6580) + if (StringUtil::atoull(std::string(per_try_timeout_entry->value().getStringView()).c_str(), + header_timeout)) { timeout.per_try_timeout_ = std::chrono::milliseconds(header_timeout); } request_headers.removeEnvoyUpstreamRequestPerTryTimeoutMs(); @@ -274,7 +279,7 @@ Http::FilterHeadersStatus Filter::decodeHeaders(Http::HeaderMap& headers, bool e if (!route_) { config_.stats_.no_route_.inc(); ENVOY_STREAM_LOG(debug, "no cluster match for URL '{}'", *callbacks_, - headers.Path()->value().c_str()); + headers.Path()->value().getStringView()); callbacks_->streamInfo().setResponseFlag(StreamInfo::ResponseFlag::NoRouteFound); callbacks_->sendLocalReply(Http::Code::NotFound, "", nullptr, absl::nullopt); @@ -317,11 +322,11 @@ Http::FilterHeadersStatus Filter::decodeHeaders(Http::HeaderMap& headers, bool e // Set up stat prefixes, etc. request_vcluster_ = route_entry_->virtualCluster(headers); ENVOY_STREAM_LOG(debug, "cluster '{}' match for URL '{}'", *callbacks_, - route_entry_->clusterName(), headers.Path()->value().c_str()); + route_entry_->clusterName(), headers.Path()->value().getStringView()); const Http::HeaderEntry* request_alt_name = headers.EnvoyUpstreamAltStatName(); if (request_alt_name) { - alt_stat_prefix_ = std::string(request_alt_name->value().c_str()) + "."; + alt_stat_prefix_ = std::string(request_alt_name->value().getStringView()) + "."; headers.removeEnvoyUpstreamAltStatName(); } diff --git a/source/common/router/router_ratelimit.cc b/source/common/router/router_ratelimit.cc index f1f084265cd5a..f8827836367fa 100644 --- a/source/common/router/router_ratelimit.cc +++ b/source/common/router/router_ratelimit.cc @@ -40,7 +40,8 @@ bool RequestHeadersAction::populateDescriptor(const Router::RouteEntry&, return false; } - descriptor.entries_.push_back({descriptor_key_, header_value->value().c_str()}); + descriptor.entries_.push_back( + {descriptor_key_, std::string(header_value->value().getStringView())}); return true; } diff --git a/source/common/router/shadow_writer_impl.cc b/source/common/router/shadow_writer_impl.cc index baea1de78fa68..1597fbb8486b7 100644 --- a/source/common/router/shadow_writer_impl.cc +++ b/source/common/router/shadow_writer_impl.cc @@ -23,11 +23,12 @@ void ShadowWriterImpl::shadow(const std::string& cluster, Http::MessagePtr&& req ASSERT(!request->headers().Host()->value().empty()); // Switch authority to add a shadow postfix. This allows upstream logging to make more sense. - auto parts = StringUtil::splitToken(request->headers().Host()->value().c_str(), ":"); + auto parts = StringUtil::splitToken(request->headers().Host()->value().getStringView(), ":"); ASSERT(!parts.empty() && parts.size() <= 2); request->headers().Host()->value( - parts.size() == 2 ? absl::StrJoin(parts, "-shadow:") - : absl::StrCat(request->headers().Host()->value().c_str(), "-shadow")); + parts.size() == 2 + ? absl::StrJoin(parts, "-shadow:") + : absl::StrCat(request->headers().Host()->value().getStringView(), "-shadow")); // This is basically fire and forget. We don't handle cancelling. cm_.httpAsyncClientForCluster(cluster).send( std::move(request), *this, Http::AsyncClient::RequestOptions().setTimeout(timeout)); diff --git a/source/common/runtime/uuid_util.cc b/source/common/runtime/uuid_util.cc index 7f52c7edb7257..615b5c8ce46d3 100644 --- a/source/common/runtime/uuid_util.cc +++ b/source/common/runtime/uuid_util.cc @@ -21,7 +21,7 @@ bool UuidUtils::uuidModBy(const std::string& uuid, uint64_t& out, uint64_t mod) return true; } -UuidTraceStatus UuidUtils::isTraceableUuid(const std::string& uuid) { +UuidTraceStatus UuidUtils::isTraceableUuid(absl::string_view uuid) { if (uuid.length() != Runtime::RandomGeneratorImpl::UUID_LENGTH) { return UuidTraceStatus::NoTrace; } diff --git a/source/common/runtime/uuid_util.h b/source/common/runtime/uuid_util.h index b3c85e8254b18..cf2450b4d5e84 100644 --- a/source/common/runtime/uuid_util.h +++ b/source/common/runtime/uuid_util.h @@ -2,6 +2,8 @@ #include +#include "absl/strings/string_view.h" + namespace Envoy { enum class UuidTraceStatus { NoTrace, Sampled, Client, Forced }; @@ -30,7 +32,7 @@ class UuidUtils { /** * @return status of the uuid, to differentiate reason for tracing, etc. */ - static UuidTraceStatus isTraceableUuid(const std::string& uuid); + static UuidTraceStatus isTraceableUuid(absl::string_view uuid); private: // Byte on this position has predefined value of 4 for UUID4. diff --git a/source/common/tracing/http_tracer_impl.cc b/source/common/tracing/http_tracer_impl.cc index 1070ac3165cb2..809d43f543c70 100644 --- a/source/common/tracing/http_tracer_impl.cc +++ b/source/common/tracing/http_tracer_impl.cc @@ -23,13 +23,13 @@ static std::string buildResponseCode(const StreamInfo::StreamInfo& info) { } static std::string valueOrDefault(const Http::HeaderEntry* header, const char* default_value) { - return header ? header->value().c_str() : default_value; + return header ? std::string(header->value().getStringView()) : default_value; } static std::string buildUrl(const Http::HeaderMap& request_headers) { - std::string path = request_headers.EnvoyOriginalPath() - ? request_headers.EnvoyOriginalPath()->value().c_str() - : request_headers.Path()->value().c_str(); + std::string path(request_headers.EnvoyOriginalPath() + ? request_headers.EnvoyOriginalPath()->value().getStringView() + : request_headers.Path()->value().getStringView()); static const size_t max_path_length = 256; if (path.length() > max_path_length) { path = path.substr(0, max_path_length); @@ -64,9 +64,8 @@ Decision HttpTracerUtility::isTracing(const StreamInfo::StreamInfo& stream_info, return {Reason::NotTraceableRequestId, false}; } - // TODO PERF: Avoid copy. UuidTraceStatus trace_status = - UuidUtils::isTraceableUuid(request_headers.RequestId()->value().c_str()); + UuidUtils::isTraceableUuid(request_headers.RequestId()->value().getStringView()); switch (trace_status) { case UuidTraceStatus::Client: @@ -128,10 +127,11 @@ void HttpTracerUtility::finalizeSpan(Span& span, const Http::HeaderMap* request_ if (request_headers) { if (request_headers->RequestId()) { span.setTag(Tracing::Tags::get().GuidXRequestId, - std::string(request_headers->RequestId()->value().c_str())); + std::string(request_headers->RequestId()->value().getStringView())); } span.setTag(Tracing::Tags::get().HttpUrl, buildUrl(*request_headers)); - span.setTag(Tracing::Tags::get().HttpMethod, request_headers->Method()->value().c_str()); + span.setTag(Tracing::Tags::get().HttpMethod, + std::string(request_headers->Method()->value().getStringView())); span.setTag(Tracing::Tags::get().DownstreamCluster, valueOrDefault(request_headers->EnvoyDownstreamServiceCluster(), "-")); span.setTag(Tracing::Tags::get().UserAgent, valueOrDefault(request_headers->UserAgent(), "-")); @@ -140,14 +140,14 @@ void HttpTracerUtility::finalizeSpan(Span& span, const Http::HeaderMap* request_ if (request_headers->ClientTraceId()) { span.setTag(Tracing::Tags::get().GuidXClientTraceId, - std::string(request_headers->ClientTraceId()->value().c_str())); + std::string(request_headers->ClientTraceId()->value().getStringView())); } // Build tags based on the custom headers. for (const Http::LowerCaseString& header : tracing_config.requestHeadersForTags()) { const Http::HeaderEntry* entry = request_headers->get(header); if (entry) { - span.setTag(header.get(), entry->value().c_str()); + span.setTag(header.get(), std::string(entry->value().getStringView())); } } } @@ -184,7 +184,7 @@ SpanPtr HttpTracerImpl::startSpan(const Config& config, Http::HeaderMap& request if (config.operationName() == OperationName::Egress) { span_name.append(" "); - span_name.append(request_headers.Host()->value().c_str()); + span_name.append(std::string(request_headers.Host()->value().getStringView())); } SpanPtr active_span = driver_->startSpan(config, request_headers, span_name, diff --git a/source/common/upstream/health_checker_impl.cc b/source/common/upstream/health_checker_impl.cc index 4f9b3d110bc04..a8a3f8a77df52 100644 --- a/source/common/upstream/health_checker_impl.cc +++ b/source/common/upstream/health_checker_impl.cc @@ -236,7 +236,8 @@ HttpHealthCheckerImpl::HttpActiveHealthCheckSession::healthCheckResult() { parent_.stats_.verify_cluster_.inc(); std::string service_cluster_healthchecked = response_headers_->EnvoyUpstreamHealthCheckedCluster() - ? response_headers_->EnvoyUpstreamHealthCheckedCluster()->value().c_str() + ? std::string( + response_headers_->EnvoyUpstreamHealthCheckedCluster()->value().getStringView()) : EMPTY_STRING; if (service_cluster_healthchecked.find(parent_.service_name_.value()) == 0) { diff --git a/source/common/upstream/original_dst_cluster.cc b/source/common/upstream/original_dst_cluster.cc index a523d2453281f..f2a0af8911efc 100644 --- a/source/common/upstream/original_dst_cluster.cc +++ b/source/common/upstream/original_dst_cluster.cc @@ -117,8 +117,10 @@ OriginalDstCluster::LoadBalancer::requestOverrideHost(LoadBalancerContext* conte const Http::HeaderMap* downstream_headers = context->downstreamHeaders(); if (downstream_headers && downstream_headers->get(Http::Headers::get().EnvoyOriginalDstHost) != nullptr) { - const std::string& request_override_host = - downstream_headers->get(Http::Headers::get().EnvoyOriginalDstHost)->value().c_str(); + const std::string request_override_host( + downstream_headers->get(Http::Headers::get().EnvoyOriginalDstHost) + ->value() + .getStringView()); try { request_host = Network::Utility::parseInternetAddressAndPort(request_override_host, false); ENVOY_LOG(debug, "Using request override host {}.", request_override_host); diff --git a/source/extensions/access_loggers/http_grpc/grpc_access_log_impl.cc b/source/extensions/access_loggers/http_grpc/grpc_access_log_impl.cc index f32feaa20a13c..24132ccf2081f 100644 --- a/source/extensions/access_loggers/http_grpc/grpc_access_log_impl.cc +++ b/source/extensions/access_loggers/http_grpc/grpc_access_log_impl.cc @@ -306,28 +306,34 @@ void HttpGrpcAccessLog::log(const Http::HeaderMap* request_headers, // TODO(mattklein123): Populate port field. auto* request_properties = log_entry->mutable_request(); if (request_headers->Scheme() != nullptr) { - request_properties->set_scheme(request_headers->Scheme()->value().c_str()); + request_properties->set_scheme(std::string(request_headers->Scheme()->value().getStringView())); } if (request_headers->Host() != nullptr) { - request_properties->set_authority(request_headers->Host()->value().c_str()); + request_properties->set_authority( + std::string(request_headers->Host()->value().getStringView())); } if (request_headers->Path() != nullptr) { - request_properties->set_path(request_headers->Path()->value().c_str()); + request_properties->set_path(std::string(request_headers->Path()->value().getStringView())); } if (request_headers->UserAgent() != nullptr) { - request_properties->set_user_agent(request_headers->UserAgent()->value().c_str()); + request_properties->set_user_agent( + std::string(request_headers->UserAgent()->value().getStringView())); } if (request_headers->Referer() != nullptr) { - request_properties->set_referer(request_headers->Referer()->value().c_str()); + request_properties->set_referer( + std::string(request_headers->Referer()->value().getStringView())); } if (request_headers->ForwardedFor() != nullptr) { - request_properties->set_forwarded_for(request_headers->ForwardedFor()->value().c_str()); + request_properties->set_forwarded_for( + std::string(request_headers->ForwardedFor()->value().getStringView())); } if (request_headers->RequestId() != nullptr) { - request_properties->set_request_id(request_headers->RequestId()->value().c_str()); + request_properties->set_request_id( + std::string(request_headers->RequestId()->value().getStringView())); } if (request_headers->EnvoyOriginalPath() != nullptr) { - request_properties->set_original_path(request_headers->EnvoyOriginalPath()->value().c_str()); + request_properties->set_original_path( + std::string(request_headers->EnvoyOriginalPath()->value().getStringView())); } request_properties->set_request_headers_bytes(request_headers->byteSize()); request_properties->set_request_body_bytes(stream_info.bytesReceived()); @@ -335,7 +341,7 @@ void HttpGrpcAccessLog::log(const Http::HeaderMap* request_headers, envoy::api::v2::core::RequestMethod method = envoy::api::v2::core::RequestMethod::METHOD_UNSPECIFIED; envoy::api::v2::core::RequestMethod_Parse( - std::string(request_headers->Method()->value().c_str()), &method); + std::string(request_headers->Method()->value().getStringView()), &method); request_properties->set_request_method(method); } if (!request_headers_to_log_.empty()) { @@ -344,7 +350,8 @@ void HttpGrpcAccessLog::log(const Http::HeaderMap* request_headers, for (const auto& header : request_headers_to_log_) { const Http::HeaderEntry* entry = request_headers->get(header); if (entry != nullptr) { - logged_headers->insert({header.get(), ProtobufTypes::String(entry->value().c_str())}); + logged_headers->insert( + {header.get(), ProtobufTypes::String(entry->value().getStringView())}); } } } @@ -362,7 +369,8 @@ void HttpGrpcAccessLog::log(const Http::HeaderMap* request_headers, for (const auto& header : response_headers_to_log_) { const Http::HeaderEntry* entry = response_headers->get(header); if (entry != nullptr) { - logged_headers->insert({header.get(), ProtobufTypes::String(entry->value().c_str())}); + logged_headers->insert( + {header.get(), ProtobufTypes::String(entry->value().getStringView())}); } } } @@ -373,7 +381,8 @@ void HttpGrpcAccessLog::log(const Http::HeaderMap* request_headers, for (const auto& header : response_trailers_to_log_) { const Http::HeaderEntry* entry = response_trailers->get(header); if (entry != nullptr) { - logged_headers->insert({header.get(), ProtobufTypes::String(entry->value().c_str())}); + logged_headers->insert( + {header.get(), ProtobufTypes::String(entry->value().getStringView())}); } } } diff --git a/source/extensions/filters/common/ext_authz/ext_authz_http_impl.cc b/source/extensions/filters/common/ext_authz/ext_authz_http_impl.cc index 3d7760ece43d6..747e163d6521e 100644 --- a/source/extensions/filters/common/ext_authz/ext_authz_http_impl.cc +++ b/source/extensions/filters/common/ext_authz/ext_authz_http_impl.cc @@ -38,7 +38,8 @@ struct SuccessResponse { // UpstreamHeaderMatcher if (context->matchers_->matches(header.key().getStringView())) { context->response_->headers_to_add.emplace_back( - Http::LowerCaseString{header.key().c_str()}, header.value().c_str()); + Http::LowerCaseString{std::string(header.key().getStringView())}, + header.value().getStringView()); } return Http::HeaderMap::Iterate::Continue; }, @@ -215,7 +216,9 @@ ResponsePtr RawHttpClientImpl::toResponse(Http::MessagePtr message) { // Set an error status if parsing status code fails. A Forbidden response is sent to the client // if the filter has not been configured with failure_mode_allow. uint64_t status_code{}; - if (!StringUtil::atoull(message->headers().Status()->value().c_str(), status_code)) { + // TODO(dnoe): Migrate to pure string_view to eliminate std:string instance (#6580) + const std::string status_string(message->headers().Status()->value().getStringView()); + if (!StringUtil::atoull(status_string.c_str(), status_code)) { ENVOY_LOG(warn, "ext_authz HTTP client failed to parse the HTTP status code."); return std::make_unique(errorResponse()); } diff --git a/source/extensions/filters/http/common/aws/utility.cc b/source/extensions/filters/http/common/aws/utility.cc index 55f4a5aab08b4..88836f7b7721b 100644 --- a/source/extensions/filters/http/common/aws/utility.cc +++ b/source/extensions/filters/http/common/aws/utility.cc @@ -21,18 +21,18 @@ std::map Utility::canonicalizeHeaders(const Http::Head return Http::HeaderMap::Iterate::Continue; } // Pseudo-headers should not be canonicalized - if (entry.key().c_str()[0] == ':') { + if (!entry.key().getStringView().empty() && entry.key().getStringView()[0] == ':') { return Http::HeaderMap::Iterate::Continue; } std::string value(entry.value().getStringView()); // Remove leading, trailing, and deduplicate repeated ascii spaces absl::RemoveExtraAsciiWhitespace(&value); - const auto iter = map->find(entry.key().c_str()); + const auto iter = map->find(std::string(entry.key().getStringView())); // If the entry already exists, append the new value to the end if (iter != map->end()) { iter->second += fmt::format(",{}", value); } else { - map->emplace(entry.key().c_str(), value); + map->emplace(std::string(entry.key().getStringView()), value); } return Http::HeaderMap::Iterate::Continue; }, @@ -91,4 +91,4 @@ Utility::joinCanonicalHeaderNames(const std::map& cano } // namespace Common } // namespace HttpFilters } // namespace Extensions -} // namespace Envoy \ No newline at end of file +} // namespace Envoy diff --git a/source/extensions/filters/http/cors/cors_filter.cc b/source/extensions/filters/http/cors/cors_filter.cc index 42443222d41b3..997beb5385fc2 100644 --- a/source/extensions/filters/http/cors/cors_filter.cc +++ b/source/extensions/filters/http/cors/cors_filter.cc @@ -54,7 +54,8 @@ Http::FilterHeadersStatus CorsFilter::decodeHeaders(Http::HeaderMap& headers, bo is_cors_request_ = true; const auto method = headers.Method(); - if (method == nullptr || method->value().c_str() != Http::Headers::get().MethodValues.Options) { + if (method == nullptr || + method->value().getStringView() != Http::Headers::get().MethodValues.Options) { return Http::FilterHeadersStatus::Continue; } @@ -134,7 +135,8 @@ bool CorsFilter::isOriginAllowedRegex(const Http::HeaderString& origin) { return false; } for (const auto& regex : *allowOriginRegexes()) { - if (std::regex_match(origin.c_str(), regex)) { + const absl::string_view origin_view = origin.getStringView(); + if (std::regex_match(origin_view.begin(), origin_view.end(), regex)) { return true; } } diff --git a/source/extensions/filters/http/dynamo/dynamo_request_parser.cc b/source/extensions/filters/http/dynamo/dynamo_request_parser.cc index ab427876a20c8..3ddf79653ad28 100644 --- a/source/extensions/filters/http/dynamo/dynamo_request_parser.cc +++ b/source/extensions/filters/http/dynamo/dynamo_request_parser.cc @@ -59,7 +59,7 @@ std::string RequestParser::parseOperation(const Http::HeaderMap& headerMap) { const Http::HeaderEntry* x_amz_target = headerMap.get(X_AMZ_TARGET); if (x_amz_target) { // Normally x-amz-target contains Version.Operation, e.g., DynamoDB_20160101.GetItem - auto version_and_operation = StringUtil::splitToken(x_amz_target->value().c_str(), "."); + auto version_and_operation = StringUtil::splitToken(x_amz_target->value().getStringView(), "."); if (version_and_operation.size() == 2) { operation = std::string{version_and_operation[1]}; } diff --git a/source/extensions/filters/http/fault/fault_filter.cc b/source/extensions/filters/http/fault/fault_filter.cc index 6c10fd2ff5fcf..c9502ff938c56 100644 --- a/source/extensions/filters/http/fault/fault_filter.cc +++ b/source/extensions/filters/http/fault/fault_filter.cc @@ -106,7 +106,8 @@ Http::FilterHeadersStatus FaultFilter::decodeHeaders(Http::HeaderMap& headers, b } if (headers.EnvoyDownstreamServiceCluster()) { - downstream_cluster_ = headers.EnvoyDownstreamServiceCluster()->value().c_str(); + downstream_cluster_ = + std::string(headers.EnvoyDownstreamServiceCluster()->value().getStringView()); downstream_cluster_delay_percent_key_ = fmt::format("fault.http.{}.delay.fixed_delay_percent", downstream_cluster_); @@ -361,7 +362,8 @@ bool FaultFilter::matchesDownstreamNodes(const Http::HeaderMap& headers) { return false; } - const std::string downstream_node = headers.EnvoyDownstreamServiceNode()->value().c_str(); + const absl::string_view downstream_node = + headers.EnvoyDownstreamServiceNode()->value().getStringView(); return fault_settings_->downstreamNodes().find(downstream_node) != fault_settings_->downstreamNodes().end(); } diff --git a/source/extensions/filters/http/fault/fault_filter.h b/source/extensions/filters/http/fault/fault_filter.h index 58e539c677667..fcf78ca15d003 100644 --- a/source/extensions/filters/http/fault/fault_filter.h +++ b/source/extensions/filters/http/fault/fault_filter.h @@ -59,7 +59,7 @@ class FaultSettings : public Router::RouteSpecificFilterConfig { return request_delay_config_.get(); } const std::string& upstreamCluster() const { return upstream_cluster_; } - const std::unordered_set& downstreamNodes() const { return downstream_nodes_; } + const absl::flat_hash_set& downstreamNodes() const { return downstream_nodes_; } absl::optional maxActiveFaults() const { return max_active_faults_; } const Filters::Common::Fault::FaultRateLimitConfig* responseRateLimit() const { return response_rate_limit_.get(); @@ -71,7 +71,7 @@ class FaultSettings : public Router::RouteSpecificFilterConfig { Filters::Common::Fault::FaultDelayConfigPtr request_delay_config_; std::string upstream_cluster_; // restrict faults to specific upstream cluster std::vector fault_filter_headers_; - std::unordered_set downstream_nodes_{}; // Inject failures for specific downstream + absl::flat_hash_set downstream_nodes_{}; // Inject failures for specific downstream absl::optional max_active_faults_; Filters::Common::Fault::FaultRateLimitConfigPtr response_rate_limit_; }; diff --git a/source/extensions/filters/http/grpc_http1_bridge/http1_bridge_filter.cc b/source/extensions/filters/http/grpc_http1_bridge/http1_bridge_filter.cc index fb221b06a5be2..08245d1b5ec23 100644 --- a/source/extensions/filters/http/grpc_http1_bridge/http1_bridge_filter.cc +++ b/source/extensions/filters/http/grpc_http1_bridge/http1_bridge_filter.cc @@ -71,7 +71,9 @@ Http::FilterTrailersStatus Http1BridgeFilter::encodeTrailers(Http::HeaderMap& tr const Http::HeaderEntry* grpc_status_header = trailers.GrpcStatus(); if (grpc_status_header) { uint64_t grpc_status_code; - if (!StringUtil::atoull(grpc_status_header->value().c_str(), grpc_status_code) || + // TODO(dnoe): Migrate to pure string_view to eliminate std:string instance (#6580) + std::string grpc_status_code_string(grpc_status_header->value().getStringView()); + if (!StringUtil::atoull(grpc_status_code_string.c_str(), grpc_status_code) || grpc_status_code != 0) { response_headers_->Status()->value(enumToInt(Http::Code::ServiceUnavailable)); } diff --git a/source/extensions/filters/http/grpc_http1_reverse_bridge/filter.cc b/source/extensions/filters/http/grpc_http1_reverse_bridge/filter.cc index b87f41c3b1c8f..8af9266159639 100644 --- a/source/extensions/filters/http/grpc_http1_reverse_bridge/filter.cc +++ b/source/extensions/filters/http/grpc_http1_reverse_bridge/filter.cc @@ -33,7 +33,8 @@ void adjustContentLength(Http::HeaderMap& headers, auto length_header = headers.ContentLength(); if (length_header != nullptr) { uint64_t length; - if (StringUtil::atoull(length_header->value().c_str(), length)) { + const std::string length_header_string(length_header->value().getStringView()); + if (StringUtil::atoull(length_header_string.c_str(), length)) { length_header->value(adjustment(length)); } } @@ -56,7 +57,7 @@ Http::FilterHeadersStatus Filter::decodeHeaders(Http::HeaderMap& headers, bool e // We keep track of the original content-type to ensure that we handle // gRPC content type variations such as application/grpc+proto. - content_type_ = headers.ContentType()->value().c_str(); + content_type_ = std::string(headers.ContentType()->value().getStringView()); headers.ContentType()->value(upstream_content_type_); headers.insertAccept().value(upstream_content_type_); diff --git a/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc b/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc index 95efe9885e83a..188cf374bb27f 100644 --- a/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc +++ b/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc @@ -155,8 +155,8 @@ ProtobufUtil::Status JsonTranscoderConfig::createTranscoder( return ProtobufUtil::Status(Code::INVALID_ARGUMENT, "Request headers has application/grpc content-type"); } - const ProtobufTypes::String method = headers.Method()->value().c_str(); - ProtobufTypes::String path = headers.Path()->value().c_str(); + const ProtobufTypes::String method(headers.Method()->value().getStringView()); + ProtobufTypes::String path(headers.Path()->value().getStringView()); ProtobufTypes::String args; const size_t pos = path.find('?'); diff --git a/source/extensions/filters/http/grpc_web/grpc_web_filter.cc b/source/extensions/filters/http/grpc_web/grpc_web_filter.cc index d6dbccefb88a3..0cdfb9979423d 100644 --- a/source/extensions/filters/http/grpc_web/grpc_web_filter.cc +++ b/source/extensions/filters/http/grpc_web/grpc_web_filter.cc @@ -19,8 +19,8 @@ namespace GrpcWeb { const uint8_t GrpcWebFilter::GRPC_WEB_TRAILER = 0b10000000; // Supported gRPC-Web content-types. -const std::unordered_set& GrpcWebFilter::gRpcWebContentTypes() const { - static const std::unordered_set* types = new std::unordered_set( +const absl::flat_hash_set& GrpcWebFilter::gRpcWebContentTypes() const { + static const absl::flat_hash_set* types = new absl::flat_hash_set( {Http::Headers::get().ContentTypeValues.GrpcWeb, Http::Headers::get().ContentTypeValues.GrpcWebProto, Http::Headers::get().ContentTypeValues.GrpcWebText, @@ -31,7 +31,7 @@ const std::unordered_set& GrpcWebFilter::gRpcWebContentTypes() cons bool GrpcWebFilter::isGrpcWebRequest(const Http::HeaderMap& headers) { const Http::HeaderEntry* content_type = headers.ContentType(); if (content_type != nullptr) { - return gRpcWebContentTypes().count(content_type->value().c_str()) > 0; + return gRpcWebContentTypes().count(content_type->value().getStringView()) > 0; } return false; } @@ -51,9 +51,10 @@ Http::FilterHeadersStatus GrpcWebFilter::decodeHeaders(Http::HeaderMap& headers, headers.removeContentLength(); setupStatTracking(headers); - if (content_type != nullptr && - (Http::Headers::get().ContentTypeValues.GrpcWebText == content_type->value().c_str() || - Http::Headers::get().ContentTypeValues.GrpcWebTextProto == content_type->value().c_str())) { + if (content_type != nullptr && (Http::Headers::get().ContentTypeValues.GrpcWebText == + content_type->value().getStringView() || + Http::Headers::get().ContentTypeValues.GrpcWebTextProto == + content_type->value().getStringView())) { // Checks whether gRPC-Web client is sending base64 encoded request. is_text_request_ = true; } @@ -61,8 +62,9 @@ Http::FilterHeadersStatus GrpcWebFilter::decodeHeaders(Http::HeaderMap& headers, const Http::HeaderEntry* accept = headers.Accept(); if (accept != nullptr && - (Http::Headers::get().ContentTypeValues.GrpcWebText == accept->value().c_str() || - Http::Headers::get().ContentTypeValues.GrpcWebTextProto == accept->value().c_str())) { + (Http::Headers::get().ContentTypeValues.GrpcWebText == accept->value().getStringView() || + Http::Headers::get().ContentTypeValues.GrpcWebTextProto == + accept->value().getStringView())) { // Checks whether gRPC-Web client is asking for base64 encoded response. is_text_response_ = true; } @@ -192,9 +194,9 @@ Http::FilterTrailersStatus GrpcWebFilter::encodeTrailers(Http::HeaderMap& traile trailers.iterate( [](const Http::HeaderEntry& header, void* context) -> Http::HeaderMap::Iterate { Buffer::Instance* temp = static_cast(context); - temp->add(header.key().c_str(), header.key().size()); + temp->add(header.key().getStringView().data(), header.key().size()); temp->add(":"); - temp->add(header.value().c_str(), header.value().size()); + temp->add(header.value().getStringView().data(), header.value().size()); temp->add("\r\n"); return Http::HeaderMap::Iterate::Continue; }, diff --git a/source/extensions/filters/http/grpc_web/grpc_web_filter.h b/source/extensions/filters/http/grpc_web/grpc_web_filter.h index 5ed34171966b2..07b5e3187a181 100644 --- a/source/extensions/filters/http/grpc_web/grpc_web_filter.h +++ b/source/extensions/filters/http/grpc_web/grpc_web_filter.h @@ -56,7 +56,7 @@ class GrpcWebFilter : public Http::StreamFilter, NonCopyable { bool isGrpcWebRequest(const Http::HeaderMap& headers); static const uint8_t GRPC_WEB_TRAILER; - const std::unordered_set& gRpcWebContentTypes() const; + const absl::flat_hash_set& gRpcWebContentTypes() const; Upstream::ClusterInfoConstSharedPtr cluster_; Http::StreamDecoderFilterCallbacks* decoder_callbacks_{}; diff --git a/source/extensions/filters/http/gzip/gzip_filter.cc b/source/extensions/filters/http/gzip/gzip_filter.cc index 0a0c789c1851c..11d02c60a7713 100644 --- a/source/extensions/filters/http/gzip/gzip_filter.cc +++ b/source/extensions/filters/http/gzip/gzip_filter.cc @@ -149,8 +149,8 @@ Http::FilterDataStatus GzipFilter::encodeData(Buffer::Instance& data, bool end_s bool GzipFilter::hasCacheControlNoTransform(Http::HeaderMap& headers) const { const Http::HeaderEntry* cache_control = headers.CacheControl(); if (cache_control) { - return StringUtil::caseFindToken(cache_control->value().c_str(), ",", - Http::Headers::get().CacheControlValues.NoTransform.c_str()); + return StringUtil::caseFindToken(cache_control->value().getStringView(), ",", + Http::Headers::get().CacheControlValues.NoTransform); } return false; @@ -166,8 +166,8 @@ bool GzipFilter::isAcceptEncodingAllowed(Http::HeaderMap& headers) const { if (accept_encoding) { bool is_wildcard = false; // true if found and not followed by `q=0`. - for (const auto token : StringUtil::splitToken(headers.AcceptEncoding()->value().c_str(), ",", - false /* keep_empty */)) { + for (const auto token : StringUtil::splitToken( + headers.AcceptEncoding()->value().getStringView(), ",", false /* keep_empty */)) { const auto value = StringUtil::trim(StringUtil::cropRight(token, ";")); const auto q_value = StringUtil::trim(StringUtil::cropLeft(token, ";")); // If value is the gzip coding, check the qvalue and return. @@ -211,7 +211,9 @@ bool GzipFilter::isAcceptEncodingAllowed(Http::HeaderMap& headers) const { bool GzipFilter::isContentTypeAllowed(Http::HeaderMap& headers) const { const Http::HeaderEntry* content_type = headers.ContentType(); if (content_type && !config_->contentTypeValues().empty()) { - std::string value{StringUtil::trim(StringUtil::cropRight(content_type->value().c_str(), ";"))}; + // TODO(dnoe): Eliminate std:string construction with Swiss table (#6580) + const std::string value{ + StringUtil::trim(StringUtil::cropRight(content_type->value().getStringView(), ";"))}; return config_->contentTypeValues().find(value) != config_->contentTypeValues().end(); } @@ -230,9 +232,10 @@ bool GzipFilter::isMinimumContentLength(Http::HeaderMap& headers) const { const Http::HeaderEntry* content_length = headers.ContentLength(); if (content_length) { uint64_t length; - const bool is_minimum_content_length = - StringUtil::atoull(content_length->value().c_str(), length) && - length >= config_->minimumLength(); + // TODO(dnoe): Make StringUtil::atoull and friends string_view friendly. + const std::string content_length_str(content_length->value().getStringView()); + const bool is_minimum_content_length = StringUtil::atoull(content_length_str.c_str(), length) && + length >= config_->minimumLength(); if (!is_minimum_content_length) { config_->stats().content_length_too_small_.inc(); } @@ -241,8 +244,8 @@ bool GzipFilter::isMinimumContentLength(Http::HeaderMap& headers) const { const Http::HeaderEntry* transfer_encoding = headers.TransferEncoding(); return (transfer_encoding && - StringUtil::caseFindToken(transfer_encoding->value().c_str(), ",", - Http::Headers::get().TransferEncodingValues.Chunked.c_str())); + StringUtil::caseFindToken(transfer_encoding->value().getStringView(), ",", + Http::Headers::get().TransferEncodingValues.Chunked)); } bool GzipFilter::isTransferEncodingAllowed(Http::HeaderMap& headers) const { @@ -251,7 +254,7 @@ bool GzipFilter::isTransferEncodingAllowed(Http::HeaderMap& headers) const { for (auto header_value : // TODO(gsagula): add Http::HeaderMap::string_view() so string length doesn't need to be // computed twice. Find all other sites where this can be improved. - StringUtil::splitToken(transfer_encoding->value().c_str(), ",", true)) { + StringUtil::splitToken(transfer_encoding->value().getStringView(), ",", true)) { const auto trimmed_value = StringUtil::trim(header_value); if (StringUtil::caseCompare(trimmed_value, Http::Headers::get().TransferEncodingValues.Gzip) || @@ -268,10 +271,10 @@ bool GzipFilter::isTransferEncodingAllowed(Http::HeaderMap& headers) const { void GzipFilter::insertVaryHeader(Http::HeaderMap& headers) { const Http::HeaderEntry* vary = headers.Vary(); if (vary) { - if (!StringUtil::findToken(vary->value().c_str(), ",", + if (!StringUtil::findToken(vary->value().getStringView(), ",", Http::Headers::get().VaryValues.AcceptEncoding, true)) { std::string new_header; - absl::StrAppend(&new_header, vary->value().c_str(), ", ", + absl::StrAppend(&new_header, vary->value().getStringView(), ", ", Http::Headers::get().VaryValues.AcceptEncoding); headers.insertVary().value(new_header); } @@ -288,7 +291,7 @@ void GzipFilter::insertVaryHeader(Http::HeaderMap& headers) { void GzipFilter::sanitizeEtagHeader(Http::HeaderMap& headers) { const Http::HeaderEntry* etag = headers.Etag(); if (etag) { - absl::string_view value(etag->value().c_str()); + absl::string_view value(etag->value().getStringView()); if (value.length() > 2 && !((value[0] == 'w' || value[0] == 'W') && value[1] == '/')) { headers.removeEtag(); } diff --git a/source/extensions/filters/http/jwt_authn/extractor.cc b/source/extensions/filters/http/jwt_authn/extractor.cc index 9e0bd9ea64043..b589c2c8bb716 100644 --- a/source/extensions/filters/http/jwt_authn/extractor.cc +++ b/source/extensions/filters/http/jwt_authn/extractor.cc @@ -203,7 +203,7 @@ std::vector ExtractorImpl::extract(const Http::HeaderMap& h } // Check query parameter locations. - const auto& params = Http::Utility::parseQueryString(headers.Path()->value().c_str()); + const auto& params = Http::Utility::parseQueryString(headers.Path()->value().getStringView()); for (const auto& location_it : param_locations_) { const auto& param_key = location_it.first; const auto& location_spec = location_it.second; diff --git a/source/extensions/filters/http/jwt_authn/matcher.cc b/source/extensions/filters/http/jwt_authn/matcher.cc index 252bc330d739a..123e590a7e727 100644 --- a/source/extensions/filters/http/jwt_authn/matcher.cc +++ b/source/extensions/filters/http/jwt_authn/matcher.cc @@ -90,8 +90,8 @@ class PathMatcherImpl : public BaseMatcherImpl { bool matches(const Http::HeaderMap& headers) const override { if (BaseMatcherImpl::matchRoute(headers)) { const Http::HeaderString& path = headers.Path()->value(); - size_t compare_length = Http::Utility::findQueryStringStart(path) - path.c_str(); - + const size_t compare_length = + path.getStringView().length() - Http::Utility::findQueryStringStart(path).length(); auto real_path = path.getStringView().substr(0, compare_length); bool match = case_sensitive_ ? real_path == path_ : StringUtil::caseCompare(real_path, path_); if (match) { @@ -119,8 +119,10 @@ class RegexMatcherImpl : public BaseMatcherImpl { bool matches(const Http::HeaderMap& headers) const override { if (BaseMatcherImpl::matchRoute(headers)) { const Http::HeaderString& path = headers.Path()->value(); - const char* query_string_start = Http::Utility::findQueryStringStart(path); - if (std::regex_match(path.c_str(), query_string_start, regex_)) { + const absl::string_view query_string = Http::Utility::findQueryStringStart(path); + absl::string_view path_view = path.getStringView(); + path_view.remove_suffix(query_string.length()); + if (std::regex_match(path_view.begin(), path_view.end(), regex_)) { ENVOY_LOG(debug, "Regex requirement '{}' matched.", regex_str_); return true; } diff --git a/source/extensions/filters/http/lua/lua_filter.cc b/source/extensions/filters/http/lua/lua_filter.cc index 11404f110b776..88315c1f68b1a 100644 --- a/source/extensions/filters/http/lua/lua_filter.cc +++ b/source/extensions/filters/http/lua/lua_filter.cc @@ -117,9 +117,9 @@ int StreamHandleWrapper::luaRespond(lua_State* state) { Http::HeaderMapPtr headers = buildHeadersFromTable(state, 2); uint64_t status; - if (headers->Status() == nullptr || - !StringUtil::atoull(headers->Status()->value().c_str(), status) || status < 200 || - status >= 600) { + const std::string status_string(headers->Status()->value().getStringView()); + if (headers->Status() == nullptr || !StringUtil::atoull(status_string.c_str(), status) || + status < 200 || status >= 600) { luaL_error(state, ":status must be between 200-599"); } @@ -212,8 +212,10 @@ void StreamHandleWrapper::onSuccess(Http::MessagePtr&& response) { response->headers().iterate( [](const Http::HeaderEntry& header, void* context) -> Http::HeaderMap::Iterate { lua_State* state = static_cast(context); - lua_pushstring(state, header.key().c_str()); - lua_pushstring(state, header.value().c_str()); + lua_pushlstring(state, header.key().getStringView().data(), + header.key().getStringView().length()); + lua_pushlstring(state, header.value().getStringView().data(), + header.value().getStringView().length()); lua_settable(state, -3); return Http::HeaderMap::Iterate::Continue; }, diff --git a/source/extensions/filters/http/lua/wrappers.cc b/source/extensions/filters/http/lua/wrappers.cc index cec3f527dc3b9..f675d34cfa598 100644 --- a/source/extensions/filters/http/lua/wrappers.cc +++ b/source/extensions/filters/http/lua/wrappers.cc @@ -25,8 +25,10 @@ int HeaderMapIterator::luaPairsIterator(lua_State* state) { parent_.iterator_.reset(); return 0; } else { - lua_pushstring(state, entries_[current_]->key().c_str()); - lua_pushstring(state, entries_[current_]->value().c_str()); + const absl::string_view key_view(entries_[current_]->key().getStringView()); + lua_pushlstring(state, key_view.data(), key_view.length()); + const absl::string_view value_view(entries_[current_]->value().getStringView()); + lua_pushlstring(state, value_view.data(), value_view.length()); current_++; return 2; } @@ -45,7 +47,8 @@ int HeaderMapWrapper::luaGet(lua_State* state) { const char* key = luaL_checkstring(state, 2); const Http::HeaderEntry* entry = headers_.get(Http::LowerCaseString(key)); if (entry != nullptr) { - lua_pushstring(state, entry->value().c_str()); + lua_pushlstring(state, entry->value().getStringView().data(), + entry->value().getStringView().length()); return 1; } else { return 0; diff --git a/source/extensions/filters/http/squash/squash_filter.cc b/source/extensions/filters/http/squash/squash_filter.cc index d55f82f9410fb..9e12c6c4d43fe 100644 --- a/source/extensions/filters/http/squash/squash_filter.cc +++ b/source/extensions/filters/http/squash/squash_filter.cc @@ -197,7 +197,7 @@ void SquashFilter::onCreateAttachmentSuccess(Http::MessagePtr&& m) { // Get the config object that was created if (Http::Utility::getResponseStatus(m->headers()) != enumToInt(Http::Code::Created)) { ENVOY_LOG(debug, "Squash: can't create attachment object. status {} - not squashing", - m->headers().Status()->value().c_str()); + m->headers().Status()->value().getStringView()); doneSquashing(); } else { std::string debug_attachment_id; diff --git a/source/extensions/filters/http/tap/tap_config_impl.cc b/source/extensions/filters/http/tap/tap_config_impl.cc index 7dc047a6b3d20..68106ab0c6eaf 100644 --- a/source/extensions/filters/http/tap/tap_config_impl.cc +++ b/source/extensions/filters/http/tap/tap_config_impl.cc @@ -17,8 +17,8 @@ Http::HeaderMap::Iterate fillHeaderList(const Http::HeaderEntry& header, void* c Protobuf::RepeatedPtrField& header_list = *reinterpret_cast*>(context); auto& new_header = *header_list.Add(); - new_header.set_key(header.key().c_str()); - new_header.set_value(header.value().c_str()); + new_header.set_key(std::string(header.key().getStringView())); + new_header.set_value(std::string(header.value().getStringView())); return Http::HeaderMap::Iterate::Continue; } } // namespace diff --git a/source/extensions/filters/network/thrift_proxy/router/router_ratelimit_impl.cc b/source/extensions/filters/network/thrift_proxy/router/router_ratelimit_impl.cc index 398bbda698742..c1f3f99f7cb20 100644 --- a/source/extensions/filters/network/thrift_proxy/router/router_ratelimit_impl.cc +++ b/source/extensions/filters/network/thrift_proxy/router/router_ratelimit_impl.cc @@ -44,7 +44,8 @@ bool RequestHeadersAction::populateDescriptor(const RouteEntry&, RateLimit::Desc return false; } - descriptor.entries_.push_back({descriptor_key_, header_value->value().c_str()}); + descriptor.entries_.push_back( + {descriptor_key_, std::string(header_value->value().getStringView())}); return true; } diff --git a/source/extensions/filters/network/thrift_proxy/twitter_protocol_impl.cc b/source/extensions/filters/network/thrift_proxy/twitter_protocol_impl.cc index 8d104250bff52..614e98de363ae 100644 --- a/source/extensions/filters/network/thrift_proxy/twitter_protocol_impl.cc +++ b/source/extensions/filters/network/thrift_proxy/twitter_protocol_impl.cc @@ -393,13 +393,15 @@ class RequestHeader { RequestHeader& rh = *static_cast(cb); if (key == Headers::get().ClientId.get()) { - rh.client_id_ = ClientId(header.value().c_str()); + rh.client_id_ = ClientId(std::string(header.value().getStringView())); } else if (key == Headers::get().Dest.get()) { - rh.dest_ = header.value().c_str(); + rh.dest_ = std::string(header.value().getStringView()); } else if (key.find(":d:") == 0 && key.size() > 3) { - rh.delegations_.emplace_back(std::string(key.substr(3)), header.value().c_str()); + rh.delegations_.emplace_back(std::string(key.substr(3)), + std::string(header.value().getStringView())); } else if (key[0] != ':') { - rh.contexts_.emplace_back(std::string(key), header.value().c_str()); + rh.contexts_.emplace_back(std::string(key), + std::string(header.value().getStringView())); } return Http::HeaderMap::Iterate::Continue; }, @@ -577,8 +579,8 @@ class ResponseHeader { [](const Http::HeaderEntry& header, void* cb) -> Http::HeaderMap::Iterate { absl::string_view key = header.key().getStringView(); if (!key.empty() && key[0] != ':') { - static_cast*>(cb)->emplace_back(std::string(key), - header.value().c_str()); + static_cast*>(cb)->emplace_back( + std::string(key), std::string(header.value().getStringView())); } return Http::HeaderMap::Iterate::Continue; }, diff --git a/source/extensions/tracers/common/ot/opentracing_driver_impl.cc b/source/extensions/tracers/common/ot/opentracing_driver_impl.cc index 177418d2ff892..75faf846d9140 100644 --- a/source/extensions/tracers/common/ot/opentracing_driver_impl.cc +++ b/source/extensions/tracers/common/ot/opentracing_driver_impl.cc @@ -51,7 +51,8 @@ class OpenTracingHTTPHeadersReader : public opentracing::HTTPHeadersReader { request_headers_.lookup(Http::LowerCaseString{key}, &entry); switch (lookup_result) { case Http::HeaderMap::Lookup::Found: - return opentracing::string_view{entry->value().c_str(), entry->value().size()}; + return opentracing::string_view{entry->value().getStringView().data(), + entry->value().getStringView().length()}; case Http::HeaderMap::Lookup::NotFound: return opentracing::make_unexpected(opentracing::key_not_found_error); case Http::HeaderMap::Lookup::NotSupported: @@ -71,8 +72,10 @@ class OpenTracingHTTPHeadersReader : public opentracing::HTTPHeadersReader { static Http::HeaderMap::Iterate headerMapCallback(const Http::HeaderEntry& header, void* context) { OpenTracingCb* callback = static_cast(context); - opentracing::string_view key{header.key().c_str(), header.key().size()}; - opentracing::string_view value{header.value().c_str(), header.value().size()}; + opentracing::string_view key{header.key().getStringView().data(), + header.key().getStringView().length()}; + opentracing::string_view value{header.value().getStringView().data(), + header.value().getStringView().length()}; if ((*callback)(key, value)) { return Http::HeaderMap::Iterate::Continue; } else { @@ -154,7 +157,8 @@ Tracing::SpanPtr OpenTracingDriver::startSpan(const Tracing::Config& config, std::unique_ptr parent_span_ctx; if (propagation_mode == PropagationMode::SingleHeader && request_headers.OtSpanContext()) { opentracing::expected> parent_span_ctx_maybe; - std::string parent_context = Base64::decode(request_headers.OtSpanContext()->value().c_str()); + std::string parent_context = + Base64::decode(std::string(request_headers.OtSpanContext()->value().getStringView())); if (!parent_context.empty()) { InputConstMemoryStream istream{parent_context.data(), parent_context.size()}; diff --git a/source/extensions/tracers/zipkin/span_context_extractor.cc b/source/extensions/tracers/zipkin/span_context_extractor.cc index 50caff9db8c04..dc9413760367c 100644 --- a/source/extensions/tracers/zipkin/span_context_extractor.cc +++ b/source/extensions/tracers/zipkin/span_context_extractor.cc @@ -86,7 +86,7 @@ std::pair SpanContextExtractor::extractSpanContext(bool is_sa if (b3_span_id_entry && b3_trace_id_entry) { // Extract trace id - which can either be 128 or 64 bit. For 128 bit, // it needs to be divided into two 64 bit numbers (high and low). - const std::string tid = b3_trace_id_entry->value().c_str(); + const std::string tid(b3_trace_id_entry->value().getStringView()); if (b3_trace_id_entry->value().size() == 32) { const std::string high_tid = tid.substr(0, 16); const std::string low_tid = tid.substr(16, 16); @@ -99,14 +99,14 @@ std::pair SpanContextExtractor::extractSpanContext(bool is_sa throw ExtractorException(fmt::format("Invalid trace_id {}", tid.c_str())); } - const std::string spid = b3_span_id_entry->value().c_str(); + const std::string spid(b3_span_id_entry->value().getStringView()); if (!StringUtil::atoull(spid.c_str(), span_id, 16)) { throw ExtractorException(fmt::format("Invalid span id {}", spid.c_str())); } auto b3_parent_id_entry = request_headers_.get(ZipkinCoreConstants::get().X_B3_PARENT_SPAN_ID); if (b3_parent_id_entry && !b3_parent_id_entry->value().empty()) { - const std::string pspid = b3_parent_id_entry->value().c_str(); + const std::string pspid(b3_parent_id_entry->value().getStringView()); if (!StringUtil::atoull(pspid.c_str(), parent_id, 16)) { throw ExtractorException(fmt::format("Invalid parent span id {}", pspid.c_str())); } @@ -123,7 +123,7 @@ std::pair SpanContextExtractor::extractSpanContextFromB3SingleFormat(bool is_sampled) { auto b3_head_entry = request_headers_.get(ZipkinCoreConstants::get().B3); ASSERT(b3_head_entry); - const std::string b3 = b3_head_entry->value().c_str(); + const std::string b3(b3_head_entry->value().getStringView()); if (!b3.length()) { throw ExtractorException("Invalid input: empty"); } @@ -226,4 +226,4 @@ SpanContextExtractor::extractSpanContextFromB3SingleFormat(bool is_sampled) { } // namespace Zipkin } // namespace Tracers } // namespace Extensions -} // namespace Envoy \ No newline at end of file +} // namespace Envoy diff --git a/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc b/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc index 84b5f26530b1c..a2ccbb989afb9 100644 --- a/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc +++ b/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc @@ -105,12 +105,13 @@ Tracing::SpanPtr Driver::startSpan(const Tracing::Config& config, Http::HeaderMa auto ret_span_context = extractor.extractSpanContext(sampled); if (!ret_span_context.second) { // Create a root Zipkin span. No context was found in the headers. - new_zipkin_span = - tracer.startSpan(config, request_headers.Host()->value().c_str(), start_time); + new_zipkin_span = tracer.startSpan( + config, std::string(request_headers.Host()->value().getStringView()), start_time); new_zipkin_span->setSampled(sampled); } else { - new_zipkin_span = tracer.startSpan(config, request_headers.Host()->value().c_str(), - start_time, ret_span_context.first); + new_zipkin_span = + tracer.startSpan(config, std::string(request_headers.Host()->value().getStringView()), + start_time, ret_span_context.first); } } catch (const ExtractorException& e) { diff --git a/test/common/config/http_subscription_test_harness.h b/test/common/config/http_subscription_test_harness.h index 3eec9b65e749f..35c2e6d3b87f1 100644 --- a/test/common/config/http_subscription_test_harness.h +++ b/test/common/config/http_subscription_test_harness.h @@ -64,12 +64,12 @@ class HttpSubscriptionTestHarness : public SubscriptionTestHarness { Http::AsyncClient::Callbacks& callbacks, const Http::AsyncClient::RequestOptions&) { http_callbacks_ = &callbacks; - EXPECT_EQ("POST", std::string(request->headers().Method()->value().c_str())); + EXPECT_EQ("POST", std::string(request->headers().Method()->value().getStringView())); EXPECT_EQ(Http::Headers::get().ContentTypeValues.Json, - std::string(request->headers().ContentType()->value().c_str())); - EXPECT_EQ("eds_cluster", std::string(request->headers().Host()->value().c_str())); + std::string(request->headers().ContentType()->value().getStringView())); + EXPECT_EQ("eds_cluster", std::string(request->headers().Host()->value().getStringView())); EXPECT_EQ("/v2/discovery:endpoints", - std::string(request->headers().Path()->value().c_str())); + std::string(request->headers().Path()->value().getStringView())); std::string expected_request = "{"; if (!version_.empty()) { expected_request += "\"version_info\":\"" + version + "\","; @@ -82,7 +82,7 @@ class HttpSubscriptionTestHarness : public SubscriptionTestHarness { expected_request += "}"; EXPECT_EQ(expected_request, request->bodyAsString()); EXPECT_EQ(fmt::format_int(expected_request.size()).str(), - std::string(request->headers().ContentLength()->value().c_str())); + std::string(request->headers().ContentLength()->value().getStringView())); request_in_progress_ = true; return &http_request_; })); diff --git a/test/common/config/subscription_factory_test.cc b/test/common/config/subscription_factory_test.cc index 6c673162ed332..3497f16a1826e 100644 --- a/test/common/config/subscription_factory_test.cc +++ b/test/common/config/subscription_factory_test.cc @@ -252,10 +252,11 @@ TEST_F(SubscriptionFactoryTest, HttpSubscription) { EXPECT_CALL(cm_.async_client_, send_(_, _, _)) .WillOnce(Invoke([this](Http::MessagePtr& request, Http::AsyncClient::Callbacks&, const Http::AsyncClient::RequestOptions&) { - EXPECT_EQ("POST", std::string(request->headers().Method()->value().c_str())); - EXPECT_EQ("static_cluster", std::string(request->headers().Host()->value().c_str())); + EXPECT_EQ("POST", std::string(request->headers().Method()->value().getStringView())); + EXPECT_EQ("static_cluster", + std::string(request->headers().Host()->value().getStringView())); EXPECT_EQ("/v2/discovery:endpoints", - std::string(request->headers().Path()->value().c_str())); + std::string(request->headers().Path()->value().getStringView())); return &http_request_; })); EXPECT_CALL(http_request_, cancel()); diff --git a/test/common/grpc/common_test.cc b/test/common/grpc/common_test.cc index 290328a53941a..8600ec8b9372f 100644 --- a/test/common/grpc/common_test.cc +++ b/test/common/grpc/common_test.cc @@ -79,25 +79,25 @@ TEST(GrpcCommonTest, ToGrpcTimeout) { Http::HeaderString value; Common::toGrpcTimeout(std::chrono::milliseconds(0UL), value); - EXPECT_STREQ("0m", value.c_str()); + EXPECT_EQ("0m", value.getStringView()); Common::toGrpcTimeout(std::chrono::milliseconds(1UL), value); - EXPECT_STREQ("1m", value.c_str()); + EXPECT_EQ("1m", value.getStringView()); Common::toGrpcTimeout(std::chrono::milliseconds(100000000UL), value); - EXPECT_STREQ("100000S", value.c_str()); + EXPECT_EQ("100000S", value.getStringView()); Common::toGrpcTimeout(std::chrono::milliseconds(100000000000UL), value); - EXPECT_STREQ("1666666M", value.c_str()); + EXPECT_EQ("1666666M", value.getStringView()); Common::toGrpcTimeout(std::chrono::milliseconds(9000000000000UL), value); - EXPECT_STREQ("2500000H", value.c_str()); + EXPECT_EQ("2500000H", value.getStringView()); Common::toGrpcTimeout(std::chrono::milliseconds(360000000000000UL), value); - EXPECT_STREQ("99999999H", value.c_str()); + EXPECT_EQ("99999999H", value.getStringView()); Common::toGrpcTimeout(std::chrono::milliseconds(UINT64_MAX), value); - EXPECT_STREQ("99999999H", value.c_str()); + EXPECT_EQ("99999999H", value.getStringView()); } TEST(GrpcCommonTest, ChargeStats) { @@ -135,71 +135,71 @@ TEST(GrpcCommonTest, PrepareHeaders) { Http::MessagePtr message = Common::prepareHeaders("cluster", "service_name", "method_name", absl::nullopt); - EXPECT_STREQ("POST", message->headers().Method()->value().c_str()); - EXPECT_STREQ("/service_name/method_name", message->headers().Path()->value().c_str()); - EXPECT_STREQ("cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/grpc", message->headers().ContentType()->value().c_str()); + EXPECT_EQ("POST", message->headers().Method()->value().getStringView()); + EXPECT_EQ("/service_name/method_name", message->headers().Path()->value().getStringView()); + EXPECT_EQ("cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/grpc", message->headers().ContentType()->value().getStringView()); } { Http::MessagePtr message = Common::prepareHeaders("cluster", "service_name", "method_name", absl::optional(1)); - EXPECT_STREQ("POST", message->headers().Method()->value().c_str()); - EXPECT_STREQ("/service_name/method_name", message->headers().Path()->value().c_str()); - EXPECT_STREQ("cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/grpc", message->headers().ContentType()->value().c_str()); - EXPECT_STREQ("1m", message->headers().GrpcTimeout()->value().c_str()); + EXPECT_EQ("POST", message->headers().Method()->value().getStringView()); + EXPECT_EQ("/service_name/method_name", message->headers().Path()->value().getStringView()); + EXPECT_EQ("cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/grpc", message->headers().ContentType()->value().getStringView()); + EXPECT_EQ("1m", message->headers().GrpcTimeout()->value().getStringView()); } { Http::MessagePtr message = Common::prepareHeaders("cluster", "service_name", "method_name", absl::optional(1)); - EXPECT_STREQ("POST", message->headers().Method()->value().c_str()); - EXPECT_STREQ("/service_name/method_name", message->headers().Path()->value().c_str()); - EXPECT_STREQ("cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/grpc", message->headers().ContentType()->value().c_str()); - EXPECT_STREQ("1000m", message->headers().GrpcTimeout()->value().c_str()); + EXPECT_EQ("POST", message->headers().Method()->value().getStringView()); + EXPECT_EQ("/service_name/method_name", message->headers().Path()->value().getStringView()); + EXPECT_EQ("cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/grpc", message->headers().ContentType()->value().getStringView()); + EXPECT_EQ("1000m", message->headers().GrpcTimeout()->value().getStringView()); } { Http::MessagePtr message = Common::prepareHeaders("cluster", "service_name", "method_name", absl::optional(1)); - EXPECT_STREQ("POST", message->headers().Method()->value().c_str()); - EXPECT_STREQ("/service_name/method_name", message->headers().Path()->value().c_str()); - EXPECT_STREQ("cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/grpc", message->headers().ContentType()->value().c_str()); - EXPECT_STREQ("60000m", message->headers().GrpcTimeout()->value().c_str()); + EXPECT_EQ("POST", message->headers().Method()->value().getStringView()); + EXPECT_EQ("/service_name/method_name", message->headers().Path()->value().getStringView()); + EXPECT_EQ("cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/grpc", message->headers().ContentType()->value().getStringView()); + EXPECT_EQ("60000m", message->headers().GrpcTimeout()->value().getStringView()); } { Http::MessagePtr message = Common::prepareHeaders("cluster", "service_name", "method_name", absl::optional(1)); - EXPECT_STREQ("POST", message->headers().Method()->value().c_str()); - EXPECT_STREQ("/service_name/method_name", message->headers().Path()->value().c_str()); - EXPECT_STREQ("cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/grpc", message->headers().ContentType()->value().c_str()); - EXPECT_STREQ("3600000m", message->headers().GrpcTimeout()->value().c_str()); + EXPECT_EQ("POST", message->headers().Method()->value().getStringView()); + EXPECT_EQ("/service_name/method_name", message->headers().Path()->value().getStringView()); + EXPECT_EQ("cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/grpc", message->headers().ContentType()->value().getStringView()); + EXPECT_EQ("3600000m", message->headers().GrpcTimeout()->value().getStringView()); } { Http::MessagePtr message = Common::prepareHeaders( "cluster", "service_name", "method_name", absl::optional(100000000)); - EXPECT_STREQ("POST", message->headers().Method()->value().c_str()); - EXPECT_STREQ("/service_name/method_name", message->headers().Path()->value().c_str()); - EXPECT_STREQ("cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/grpc", message->headers().ContentType()->value().c_str()); - EXPECT_STREQ("99999999H", message->headers().GrpcTimeout()->value().c_str()); + EXPECT_EQ("POST", message->headers().Method()->value().getStringView()); + EXPECT_EQ("/service_name/method_name", message->headers().Path()->value().getStringView()); + EXPECT_EQ("cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/grpc", message->headers().ContentType()->value().getStringView()); + EXPECT_EQ("99999999H", message->headers().GrpcTimeout()->value().getStringView()); } { Http::MessagePtr message = Common::prepareHeaders("cluster", "service_name", "method_name", absl::optional(100000000000)); - EXPECT_STREQ("POST", message->headers().Method()->value().c_str()); - EXPECT_STREQ("/service_name/method_name", message->headers().Path()->value().c_str()); - EXPECT_STREQ("cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/grpc", message->headers().ContentType()->value().c_str()); - EXPECT_STREQ("1666666M", message->headers().GrpcTimeout()->value().c_str()); + EXPECT_EQ("POST", message->headers().Method()->value().getStringView()); + EXPECT_EQ("/service_name/method_name", message->headers().Path()->value().getStringView()); + EXPECT_EQ("cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/grpc", message->headers().ContentType()->value().getStringView()); + EXPECT_EQ("1666666M", message->headers().GrpcTimeout()->value().getStringView()); } } diff --git a/test/common/http/async_client_impl_test.cc b/test/common/http/async_client_impl_test.cc index f5ae5fd98e078..c14523bcfa075 100644 --- a/test/common/http/async_client_impl_test.cc +++ b/test/common/http/async_client_impl_test.cc @@ -57,7 +57,7 @@ class AsyncClientImplTest : public testing::Test { bool end_stream) { EXPECT_CALL(callbacks, onHeaders_(_, end_stream)) .WillOnce(Invoke([code](HeaderMap& headers, bool) -> void { - EXPECT_EQ(std::to_string(code), headers.Status()->value().c_str()); + EXPECT_EQ(std::to_string(code), headers.Status()->value().getStringView()); })); } diff --git a/test/common/http/conn_manager_impl_test.cc b/test/common/http/conn_manager_impl_test.cc index 595c415246a83..dd6e61bcccf34 100644 --- a/test/common/http/conn_manager_impl_test.cc +++ b/test/common/http/conn_manager_impl_test.cc @@ -341,7 +341,7 @@ TEST_F(HttpConnectionManagerImplTest, HeaderOnlyRequestAndResponse) { .Times(2) .WillRepeatedly(Invoke([&](HeaderMap& headers, bool) -> FilterHeadersStatus { EXPECT_NE(nullptr, headers.ForwardedFor()); - EXPECT_STREQ("http", headers.ForwardedProto()->value().c_str()); + EXPECT_EQ("http", headers.ForwardedProto()->value().getStringView()); if (headers.Path()->value() == "/healthcheck") { filter->callbacks_->streamInfo().healthCheck(true); } @@ -406,7 +406,7 @@ TEST_F(HttpConnectionManagerImplTest, 100ContinueResponse) { EXPECT_CALL(*filter, decodeHeaders(_, true)) .WillRepeatedly(Invoke([&](HeaderMap& headers, bool) -> FilterHeadersStatus { EXPECT_NE(nullptr, headers.ForwardedFor()); - EXPECT_STREQ("http", headers.ForwardedProto()->value().c_str()); + EXPECT_EQ("http", headers.ForwardedProto()->value().getStringView()); return FilterHeadersStatus::StopIteration; })); @@ -552,7 +552,7 @@ TEST_F(HttpConnectionManagerImplTest, InvalidPathWithDualFilter) { EXPECT_CALL(*filter, encodeHeaders(_, true)); EXPECT_CALL(response_encoder_, encodeHeaders(_, true)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("404", headers.Status()->value().c_str()); + EXPECT_EQ("404", headers.Status()->value().getStringView()); })); EXPECT_CALL(*filter, onDestroy()); @@ -589,7 +589,7 @@ TEST_F(HttpConnectionManagerImplTest, PathFailedtoSanitize) { EXPECT_CALL(*filter, encodeHeaders(_, true)); EXPECT_CALL(response_encoder_, encodeHeaders(_, true)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("400", headers.Status()->value().c_str()); + EXPECT_EQ("400", headers.Status()->value().getStringView()); })); EXPECT_CALL(*filter, onDestroy()); @@ -615,7 +615,7 @@ TEST_F(HttpConnectionManagerImplTest, FilterShouldUseSantizedPath) { EXPECT_CALL(*filter, decodeHeaders(_, true)) .WillRepeatedly(Invoke([&](HeaderMap& header_map, bool) -> FilterHeadersStatus { - EXPECT_EQ(normalized_path, header_map.Path()->value().c_str()); + EXPECT_EQ(normalized_path, header_map.Path()->value().getStringView()); return FilterHeadersStatus::StopIteration; })); @@ -658,7 +658,7 @@ TEST_F(HttpConnectionManagerImplTest, RouteShouldUseSantizedPath) { EXPECT_CALL(*route_config_provider_.route_config_, route(_, _)) .WillOnce(Invoke([&](const Http::HeaderMap& header_map, uint64_t) { - EXPECT_EQ(normalized_path, header_map.Path()->value().c_str()); + EXPECT_EQ(normalized_path, header_map.Path()->value().getStringView()); return route; })); EXPECT_CALL(filter_factory_, createFilterChain(_)) @@ -791,7 +791,7 @@ TEST_F(HttpConnectionManagerImplTest, StartAndFinishSpanNormalFlowIngressDecorat // Verify decorator operation response header has been defined. EXPECT_CALL(encoder, encodeHeaders(_, true)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("testOp", headers.EnvoyDecoratorOperation()->value().c_str()); + EXPECT_EQ("testOp", headers.EnvoyDecoratorOperation()->value().getStringView()); })); Buffer::OwnedImpl fake_input("1234"); @@ -922,7 +922,7 @@ TEST_F(HttpConnectionManagerImplTest, StartAndFinishSpanNormalFlowEgressDecorato .WillOnce(Invoke([](HeaderMap& headers, bool) -> FilterHeadersStatus { EXPECT_NE(nullptr, headers.EnvoyDecoratorOperation()); // Verify that decorator operation has been set as request header. - EXPECT_STREQ("testOp", headers.EnvoyDecoratorOperation()->value().c_str()); + EXPECT_EQ("testOp", headers.EnvoyDecoratorOperation()->value().getStringView()); return FilterHeadersStatus::StopIteration; })); @@ -1314,7 +1314,7 @@ TEST_F(HttpConnectionManagerImplTest, NoPath) { EXPECT_CALL(encoder, encodeHeaders(_, true)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("404", headers.Status()->value().c_str()); + EXPECT_EQ("404", headers.Status()->value().getStringView()); })); Buffer::OwnedImpl fake_input("1234"); @@ -1365,7 +1365,7 @@ TEST_F(HttpConnectionManagerImplTest, PerStreamIdleTimeoutGlobal) { // 408 direct response after timeout. EXPECT_CALL(response_encoder_, encodeHeaders(_, false)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("408", headers.Status()->value().c_str()); + EXPECT_EQ("408", headers.Status()->value().getStringView()); })); std::string response_body; EXPECT_CALL(response_encoder_, encodeData(_, true)).WillOnce(AddBufferToString(&response_body)); @@ -1447,7 +1447,7 @@ TEST_F(HttpConnectionManagerImplTest, TestStreamIdleAccessLog) { // 408 direct response after timeout. EXPECT_CALL(response_encoder_, encodeHeaders(_, false)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("408", headers.Status()->value().c_str()); + EXPECT_EQ("408", headers.Status()->value().getStringView()); })); std::string response_body; @@ -1554,7 +1554,7 @@ TEST_F(HttpConnectionManagerImplTest, PerStreamIdleTimeoutAfterDownstreamHeaders // 408 direct response after timeout. EXPECT_CALL(response_encoder_, encodeHeaders(_, false)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("408", headers.Status()->value().c_str()); + EXPECT_EQ("408", headers.Status()->value().getStringView()); })); std::string response_body; EXPECT_CALL(response_encoder_, encodeData(_, true)).WillOnce(AddBufferToString(&response_body)); @@ -1626,7 +1626,7 @@ TEST_F(HttpConnectionManagerImplTest, PerStreamIdleTimeoutAfterDownstreamHeaders // 408 direct response after timeout. EXPECT_CALL(response_encoder_, encodeHeaders(_, false)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("408", headers.Status()->value().c_str()); + EXPECT_EQ("408", headers.Status()->value().getStringView()); })); std::string response_body; EXPECT_CALL(response_encoder_, encodeData(_, true)).WillOnce(AddBufferToString(&response_body)); @@ -1677,7 +1677,7 @@ TEST_F(HttpConnectionManagerImplTest, PerStreamIdleTimeoutAfterUpstreamHeaders) // 200 upstream response. EXPECT_CALL(response_encoder_, encodeHeaders(_, false)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("200", headers.Status()->value().c_str()); + EXPECT_EQ("200", headers.Status()->value().getStringView()); })); Buffer::OwnedImpl fake_input("1234"); @@ -1744,7 +1744,7 @@ TEST_F(HttpConnectionManagerImplTest, PerStreamIdleTimeoutAfterBidiData) { // 200 upstream response. EXPECT_CALL(response_encoder_, encodeHeaders(_, false)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("200", headers.Status()->value().c_str()); + EXPECT_EQ("200", headers.Status()->value().getStringView()); })); std::string response_body; @@ -1809,7 +1809,7 @@ TEST_F(HttpConnectionManagerImplTest, RequestTimeoutCallbackDisarmsAndReturns408 EXPECT_CALL(response_encoder_, encodeHeaders(_, false)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("408", headers.Status()->value().c_str()); + EXPECT_EQ("408", headers.Status()->value().getStringView()); })); EXPECT_CALL(response_encoder_, encodeData(_, true)).WillOnce(AddBufferToString(&response_body)); @@ -1989,7 +1989,7 @@ TEST_F(HttpConnectionManagerImplTest, RejectWebSocketOnNonWebSocketRoute) { EXPECT_CALL(encoder, encodeHeaders(_, true)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("403", headers.Status()->value().c_str()); + EXPECT_EQ("403", headers.Status()->value().getStringView()); })); Buffer::OwnedImpl fake_input("1234"); @@ -2019,7 +2019,7 @@ TEST_F(HttpConnectionManagerImplTest, FooUpgradeDrainClose) { EXPECT_CALL(encoder, encodeHeaders(_, false)) .WillOnce(Invoke([&](const HeaderMap& headers, bool) -> void { EXPECT_NE(nullptr, headers.Connection()); - EXPECT_STREQ("upgrade", headers.Connection()->value().c_str()); + EXPECT_EQ("upgrade", headers.Connection()->value().getStringView()); })); EXPECT_CALL(*filter, setDecoderFilterCallbacks(_)); @@ -2069,7 +2069,7 @@ TEST_F(HttpConnectionManagerImplTest, DrainClose) { EXPECT_CALL(*filter, decodeHeaders(_, true)) .WillOnce(Invoke([](HeaderMap& headers, bool) -> FilterHeadersStatus { EXPECT_NE(nullptr, headers.ForwardedFor()); - EXPECT_STREQ("https", headers.ForwardedProto()->value().c_str()); + EXPECT_EQ("https", headers.ForwardedProto()->value().getStringView()); return FilterHeadersStatus::StopIteration; })); @@ -2128,7 +2128,7 @@ TEST_F(HttpConnectionManagerImplTest, ResponseBeforeRequestComplete) { EXPECT_CALL(response_encoder_, encodeHeaders(_, true)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { EXPECT_NE(nullptr, headers.Server()); - EXPECT_STREQ("envoy-server-test", headers.Server()->value().c_str()); + EXPECT_EQ("envoy-server-test", headers.Server()->value().getStringView()); })); EXPECT_CALL(*decoder_filters_[0], onDestroy()); EXPECT_CALL(filter_callbacks_.connection_, @@ -2170,7 +2170,7 @@ TEST_F(HttpConnectionManagerImplTest, ResponseStartBeforeRequestComplete) { EXPECT_CALL(encoder, encodeHeaders(_, false)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { EXPECT_NE(nullptr, headers.Server()); - EXPECT_STREQ("", headers.Server()->value().c_str()); + EXPECT_EQ("", headers.Server()->value().getStringView()); })); filter->callbacks_->encodeHeaders(std::move(response_headers), false); @@ -3261,7 +3261,7 @@ TEST_F(HttpConnectionManagerImplTest, FilterHeadReply) { EXPECT_CALL(*encoder_filters_[0], encodeHeaders(_, true)) .WillOnce(Invoke([&](HeaderMap& headers, bool) -> FilterHeadersStatus { - EXPECT_STREQ("11", headers.ContentLength()->value().c_str()); + EXPECT_EQ("11", headers.ContentLength()->value().getStringView()); return FilterHeadersStatus::Continue; })); EXPECT_CALL(*encoder_filters_[0], encodeComplete()); @@ -3957,7 +3957,7 @@ TEST_F(HttpConnectionManagerImplTest, NoNewStreamWhenOverloaded) { // 503 direct response when overloaded. EXPECT_CALL(response_encoder_, encodeHeaders(_, false)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("503", headers.Status()->value().c_str()); + EXPECT_EQ("503", headers.Status()->value().getStringView()); })); std::string response_body; EXPECT_CALL(response_encoder_, encodeData(_, true)).WillOnce(AddBufferToString(&response_body)); @@ -3995,7 +3995,7 @@ TEST_F(HttpConnectionManagerImplTest, DisableKeepAliveWhenOverloaded) { EXPECT_CALL(response_encoder_, encodeHeaders(_, true)) .WillOnce(Invoke([](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ("close", headers.Connection()->value().c_str()); + EXPECT_EQ("close", headers.Connection()->value().getStringView()); })); Buffer::OwnedImpl fake_input("1234"); @@ -4016,7 +4016,7 @@ TEST_F(HttpConnectionManagerImplTest, OverlyLongHeadersRejected) { EXPECT_CALL(response_encoder_, encodeHeaders(_, true)) .WillOnce(Invoke([&response_code](const HeaderMap& headers, bool) -> void { - response_code = headers.Status()->value().c_str(); + response_code = std::string(headers.Status()->value().getStringView()); })); decoder->decodeHeaders(std::move(headers), true); conn_manager_->newStream(response_encoder_); diff --git a/test/common/http/conn_manager_utility_test.cc b/test/common/http/conn_manager_utility_test.cc index d1bc974e8b8c3..37f627e07a5ab 100644 --- a/test/common/http/conn_manager_utility_test.cc +++ b/test/common/http/conn_manager_utility_test.cc @@ -209,7 +209,7 @@ TEST_F(ConnectionManagerUtilityTest, SkipXffAppendPassThruUseRemoteAddress) { EXPECT_EQ((MutateRequestRet{"12.12.12.12:0", false}), callMutateRequestHeaders(headers, Protocol::Http2)); - EXPECT_STREQ("198.51.100.1", headers.ForwardedFor()->value().c_str()); + EXPECT_EQ("198.51.100.1", headers.ForwardedFor()->value().getStringView()); } // Verify internal request and XFF is set when we are using remote address and the address is diff --git a/test/common/http/header_map_impl_fuzz_test.cc b/test/common/http/header_map_impl_fuzz_test.cc index 4e8f07658add7..fbf7c621059a1 100644 --- a/test/common/http/header_map_impl_fuzz_test.cc +++ b/test/common/http/header_map_impl_fuzz_test.cc @@ -91,8 +91,8 @@ DEFINE_PROTO_FUZZER(const test::common::http::HeaderMapImplFuzzTestCase& input) auto* header_entry = header_map->get(Http::LowerCaseString(get_and_mutate.key())); if (header_entry != nullptr) { // Do some read-only stuff. - (void)strlen(header_entry->key().c_str()); - (void)strlen(header_entry->value().c_str()); + (void)strlen(std::string(header_entry->key().getStringView()).c_str()); + (void)strlen(std::string(header_entry->value().getStringView()).c_str()); (void)strlen(header_entry->value().buffer()); header_entry->key().empty(); header_entry->value().empty(); diff --git a/test/common/http/header_map_impl_test.cc b/test/common/http/header_map_impl_test.cc index 3962ed6ba0a14..f4fabb61145fd 100644 --- a/test/common/http/header_map_impl_test.cc +++ b/test/common/http/header_map_impl_test.cc @@ -18,8 +18,8 @@ TEST(HeaderStringTest, All) { { LowerCaseString static_string("hello"); HeaderString string(static_string); - EXPECT_STREQ("hello", string.c_str()); - EXPECT_EQ(static_string.get().c_str(), string.c_str()); + EXPECT_EQ("hello", string.getStringView()); + EXPECT_EQ(static_string.get(), string.getStringView()); EXPECT_EQ(5U, string.size()); } @@ -36,8 +36,8 @@ TEST(HeaderStringTest, All) { { std::string static_string("HELLO"); HeaderString string(static_string); - EXPECT_STREQ("HELLO", string.c_str()); - EXPECT_EQ(static_string.c_str(), string.c_str()); + EXPECT_EQ("HELLO", string.getStringView()); + EXPECT_EQ(static_string, string.getStringView()); EXPECT_EQ(5U, string.size()); } @@ -46,9 +46,9 @@ TEST(HeaderStringTest, All) { std::string static_string("HELLO"); HeaderString string1(static_string); HeaderString string2(std::move(string1)); - EXPECT_STREQ("HELLO", string2.c_str()); - EXPECT_EQ(static_string.c_str(), string1.c_str()); // NOLINT(bugprone-use-after-move) - EXPECT_EQ(static_string.c_str(), string2.c_str()); + EXPECT_EQ("HELLO", string2.getStringView()); + EXPECT_EQ(static_string, string1.getStringView()); // NOLINT(bugprone-use-after-move) + EXPECT_EQ(static_string, string2.getStringView()); EXPECT_EQ(5U, string1.size()); EXPECT_EQ(5U, string2.size()); } @@ -63,9 +63,9 @@ TEST(HeaderStringTest, All) { EXPECT_EQ(HeaderString::Type::Inline, string.type()); EXPECT_EQ(HeaderString::Type::Inline, string2.type()); string.append("world", 5); - EXPECT_STREQ("world", string.c_str()); + EXPECT_EQ("world", string.getStringView()); EXPECT_EQ(5UL, string.size()); - EXPECT_STREQ("hello", string2.c_str()); + EXPECT_EQ("hello", string2.getStringView()); EXPECT_EQ(5UL, string2.size()); } @@ -80,9 +80,9 @@ TEST(HeaderStringTest, All) { EXPECT_EQ(HeaderString::Type::Inline, string.type()); EXPECT_EQ(HeaderString::Type::Dynamic, string2.type()); string.append("b", 1); - EXPECT_STREQ("b", string.c_str()); + EXPECT_EQ("b", string.getStringView()); EXPECT_EQ(1UL, string.size()); - EXPECT_STREQ(large.c_str(), string2.c_str()); + EXPECT_EQ(large, string2.getStringView()); EXPECT_EQ(4096UL, string2.size()); } @@ -92,7 +92,7 @@ TEST(HeaderStringTest, All) { HeaderString string(static_string); string.setInteger(5); EXPECT_EQ(HeaderString::Type::Inline, string.type()); - EXPECT_STREQ("5", string.c_str()); + EXPECT_EQ("5", string.getStringView()); } // Static to inline string. @@ -101,7 +101,7 @@ TEST(HeaderStringTest, All) { HeaderString string(static_string); string.setCopy(static_string.c_str(), static_string.size()); EXPECT_EQ(HeaderString::Type::Inline, string.type()); - EXPECT_STREQ("HELLO", string.c_str()); + EXPECT_EQ("HELLO", string.getStringView()); } // Static clear() does nothing. @@ -111,7 +111,7 @@ TEST(HeaderStringTest, All) { EXPECT_EQ(HeaderString::Type::Reference, string.type()); string.clear(); EXPECT_EQ(HeaderString::Type::Reference, string.type()); - EXPECT_STREQ("HELLO", string.c_str()); + EXPECT_EQ("HELLO", string.getStringView()); } // Static to append. @@ -120,14 +120,14 @@ TEST(HeaderStringTest, All) { HeaderString string(static_string); EXPECT_EQ(HeaderString::Type::Reference, string.type()); string.append("a", 1); - EXPECT_STREQ("HELLOa", string.c_str()); + EXPECT_EQ("HELLOa", string.getStringView()); } // Copy inline { HeaderString string; string.setCopy("hello", 5); - EXPECT_STREQ("hello", string.c_str()); + EXPECT_EQ("hello", string.getStringView()); EXPECT_EQ(5U, string.size()); } @@ -136,8 +136,8 @@ TEST(HeaderStringTest, All) { HeaderString string; std::string large_value(4096, 'a'); string.setCopy(large_value.c_str(), large_value.size()); - EXPECT_STREQ(large_value.c_str(), string.c_str()); - EXPECT_NE(large_value.c_str(), string.c_str()); + EXPECT_EQ(large_value, string.getStringView()); + EXPECT_NE(large_value.c_str(), string.getStringView().data()); EXPECT_EQ(4096U, string.size()); } @@ -148,8 +148,8 @@ TEST(HeaderStringTest, All) { string.setCopy(large_value1.c_str(), large_value1.size()); std::string large_value2(2048, 'b'); string.setCopy(large_value2.c_str(), large_value2.size()); - EXPECT_STREQ(large_value2.c_str(), string.c_str()); - EXPECT_NE(large_value2.c_str(), string.c_str()); + EXPECT_EQ(large_value2, string.getStringView()); + EXPECT_NE(large_value2.c_str(), string.getStringView().data()); EXPECT_EQ(2048U, string.size()); } @@ -160,8 +160,8 @@ TEST(HeaderStringTest, All) { string.setCopy(large_value1.c_str(), large_value1.size()); std::string large_value2(16384, 'b'); string.setCopy(large_value2.c_str(), large_value2.size()); - EXPECT_STREQ(large_value2.c_str(), string.c_str()); - EXPECT_NE(large_value2.c_str(), string.c_str()); + EXPECT_EQ(large_value2, string.getStringView()); + EXPECT_NE(large_value2.c_str(), string.getStringView().data()); EXPECT_EQ(16384U, string.size()); } @@ -172,8 +172,8 @@ TEST(HeaderStringTest, All) { string.setCopy(large_value1.c_str(), large_value1.size()); std::string large_value2(16384, 'b'); string.setCopy(large_value2.c_str(), large_value2.size()); - EXPECT_STREQ(large_value2.c_str(), string.c_str()); - EXPECT_NE(large_value2.c_str(), string.c_str()); + EXPECT_EQ(large_value2, string.getStringView()); + EXPECT_NE(large_value2.c_str(), string.getStringView().data()); EXPECT_EQ(16384U, string.size()); } @@ -186,22 +186,22 @@ TEST(HeaderStringTest, All) { string.append("a", 1); EXPECT_EQ(HeaderString::Type::Dynamic, string.type()); test += 'a'; - EXPECT_STREQ(test.c_str(), string.c_str()); + EXPECT_EQ(test, string.getStringView()); } // Append into inline twice, then shift to dynamic. { HeaderString string; string.append("hello", 5); - EXPECT_STREQ("hello", string.c_str()); + EXPECT_EQ("hello", string.getStringView()); EXPECT_EQ(5U, string.size()); string.append("world", 5); - EXPECT_STREQ("helloworld", string.c_str()); + EXPECT_EQ("helloworld", string.getStringView()); EXPECT_EQ(10U, string.size()); std::string large(4096, 'a'); string.append(large.c_str(), large.size()); large = "helloworld" + large; - EXPECT_STREQ(large.c_str(), string.c_str()); + EXPECT_EQ(large, string.getStringView()); EXPECT_EQ(4106U, string.size()); } @@ -214,7 +214,7 @@ TEST(HeaderStringTest, All) { std::string large2 = large + large; string.append(large2.c_str(), large2.size()); large += large2; - EXPECT_STREQ(large.c_str(), string.c_str()); + EXPECT_EQ(large, string.getStringView()); EXPECT_EQ(384U, string.size()); } @@ -228,7 +228,7 @@ TEST(HeaderStringTest, All) { string.append(large2.c_str(), large2.size()); std::string large3(32, 'c'); string.append(large3.c_str(), large3.size()); - EXPECT_STREQ((large + large2 + large3).c_str(), string.c_str()); + EXPECT_EQ((large + large2 + large3), string.getStringView()); EXPECT_EQ(280U, string.size()); } @@ -236,7 +236,7 @@ TEST(HeaderStringTest, All) { { HeaderString string; string.setInteger(123456789); - EXPECT_STREQ("123456789", string.c_str()); + EXPECT_EQ("123456789", string.getStringView()); EXPECT_EQ(9U, string.size()); } @@ -246,7 +246,7 @@ TEST(HeaderStringTest, All) { std::string large(128, 'a'); string.append(large.c_str(), large.size()); string.setInteger(123456789); - EXPECT_STREQ("123456789", string.c_str()); + EXPECT_EQ("123456789", string.getStringView()); EXPECT_EQ(9U, string.size()); EXPECT_EQ(HeaderString::Type::Dynamic, string.type()); } @@ -256,17 +256,17 @@ TEST(HeaderStringTest, All) { const std::string static_string = "hello world"; HeaderString string; string.setReference(static_string); - EXPECT_EQ(string.c_str(), static_string.c_str()); + EXPECT_EQ(string.getStringView(), static_string); EXPECT_EQ(11U, string.size()); EXPECT_EQ(HeaderString::Type::Reference, string.type()); const std::string large(128, 'a'); string.setCopy(large.c_str(), large.size()); - EXPECT_NE(string.c_str(), large.c_str()); + EXPECT_NE(string.getStringView().data(), large.c_str()); EXPECT_EQ(HeaderString::Type::Dynamic, string.type()); string.setReference(static_string); - EXPECT_EQ(string.c_str(), static_string.c_str()); + EXPECT_EQ(string.getStringView(), static_string); EXPECT_EQ(11U, string.size()); EXPECT_EQ(HeaderString::Type::Reference, string.type()); } @@ -293,28 +293,28 @@ TEST(HeaderMapImplTest, InlineInsert) { headers.insertHost().value(std::string("hello")); EXPECT_FALSE(headers.empty()); EXPECT_EQ(1, headers.size()); - EXPECT_STREQ(":authority", headers.Host()->key().c_str()); - EXPECT_STREQ("hello", headers.Host()->value().c_str()); - EXPECT_STREQ("hello", headers.get(Headers::get().Host)->value().c_str()); + EXPECT_EQ(":authority", headers.Host()->key().getStringView()); + EXPECT_EQ("hello", headers.Host()->value().getStringView()); + EXPECT_EQ("hello", headers.get(Headers::get().Host)->value().getStringView()); } TEST(HeaderMapImplTest, MoveIntoInline) { HeaderMapImpl headers; HeaderString key; - key.setCopy(Headers::get().CacheControl.get().c_str(), Headers::get().CacheControl.get().size()); + key.setCopy(Headers::get().CacheControl.get()); HeaderString value; value.setCopy("hello", 5); headers.addViaMove(std::move(key), std::move(value)); - EXPECT_STREQ("cache-control", headers.CacheControl()->key().c_str()); - EXPECT_STREQ("hello", headers.CacheControl()->value().c_str()); + EXPECT_EQ("cache-control", headers.CacheControl()->key().getStringView()); + EXPECT_EQ("hello", headers.CacheControl()->value().getStringView()); HeaderString key2; key2.setCopy(Headers::get().CacheControl.get().c_str(), Headers::get().CacheControl.get().size()); HeaderString value2; value2.setCopy("there", 5); headers.addViaMove(std::move(key2), std::move(value2)); - EXPECT_STREQ("cache-control", headers.CacheControl()->key().c_str()); - EXPECT_STREQ("hello,there", headers.CacheControl()->value().c_str()); + EXPECT_EQ("cache-control", headers.CacheControl()->key().getStringView()); + EXPECT_EQ("hello,there", headers.CacheControl()->value().getStringView()); } TEST(HeaderMapImplTest, Remove) { @@ -324,7 +324,7 @@ TEST(HeaderMapImplTest, Remove) { LowerCaseString static_key("hello"); std::string ref_value("value"); headers.addReference(static_key, ref_value); - EXPECT_STREQ("value", headers.get(static_key)->value().c_str()); + EXPECT_EQ("value", headers.get(static_key)->value().getStringView()); EXPECT_EQ(HeaderString::Type::Reference, headers.get(static_key)->value().type()); EXPECT_EQ(1UL, headers.size()); EXPECT_FALSE(headers.empty()); @@ -335,7 +335,7 @@ TEST(HeaderMapImplTest, Remove) { // Add and remove by inline. headers.insertContentLength().value(5); - EXPECT_STREQ("5", headers.ContentLength()->value().c_str()); + EXPECT_EQ("5", headers.ContentLength()->value().getStringView()); EXPECT_EQ(1UL, headers.size()); EXPECT_FALSE(headers.empty()); headers.removeContentLength(); @@ -345,7 +345,7 @@ TEST(HeaderMapImplTest, Remove) { // Add inline and remove by name. headers.insertContentLength().value(5); - EXPECT_STREQ("5", headers.ContentLength()->value().c_str()); + EXPECT_EQ("5", headers.ContentLength()->value().getStringView()); EXPECT_EQ(1UL, headers.size()); EXPECT_FALSE(headers.empty()); headers.remove(Headers::get().ContentLength); @@ -385,7 +385,7 @@ TEST(HeaderMapImplTest, RemoveRegex) { // Add inline and remove by regex headers.insertContentLength().value(5); - EXPECT_STREQ("5", headers.ContentLength()->value().c_str()); + EXPECT_EQ("5", headers.ContentLength()->value().getStringView()); EXPECT_EQ(1UL, headers.size()); EXPECT_FALSE(headers.empty()); headers.removePrefix(LowerCaseString("content")); @@ -421,7 +421,8 @@ TEST(HeaderMapImplTest, SetRemovesAllValues) { headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -438,7 +439,8 @@ TEST(HeaderMapImplTest, SetRemovesAllValues) { headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -452,21 +454,21 @@ TEST(HeaderMapImplTest, DoubleInlineAdd) { const std::string bar("bar"); headers.addReference(Headers::get().ContentLength, foo); headers.addReference(Headers::get().ContentLength, bar); - EXPECT_STREQ("foo,bar", headers.ContentLength()->value().c_str()); + EXPECT_EQ("foo,bar", headers.ContentLength()->value().getStringView()); EXPECT_EQ(1UL, headers.size()); } { HeaderMapImpl headers; headers.addReferenceKey(Headers::get().ContentLength, "foo"); headers.addReferenceKey(Headers::get().ContentLength, "bar"); - EXPECT_STREQ("foo,bar", headers.ContentLength()->value().c_str()); + EXPECT_EQ("foo,bar", headers.ContentLength()->value().getStringView()); EXPECT_EQ(1UL, headers.size()); } { HeaderMapImpl headers; headers.addReferenceKey(Headers::get().ContentLength, 5); headers.addReferenceKey(Headers::get().ContentLength, 6); - EXPECT_STREQ("5,6", headers.ContentLength()->value().c_str()); + EXPECT_EQ("5,6", headers.ContentLength()->value().getStringView()); EXPECT_EQ(1UL, headers.size()); } { @@ -474,7 +476,7 @@ TEST(HeaderMapImplTest, DoubleInlineAdd) { const std::string foo("foo"); headers.addReference(Headers::get().ContentLength, foo); headers.addReferenceKey(Headers::get().ContentLength, 6); - EXPECT_STREQ("foo,6", headers.ContentLength()->value().c_str()); + EXPECT_EQ("foo,6", headers.ContentLength()->value().getStringView()); EXPECT_EQ(1UL, headers.size()); } } @@ -483,7 +485,7 @@ TEST(HeaderMapImplTest, DoubleInlineSet) { HeaderMapImpl headers; headers.setReferenceKey(Headers::get().ContentType, "blah"); headers.setReferenceKey(Headers::get().ContentType, "text/html"); - EXPECT_STREQ("text/html", headers.ContentType()->value().c_str()); + EXPECT_EQ("text/html", headers.ContentType()->value().getStringView()); EXPECT_EQ(1UL, headers.size()); } @@ -491,20 +493,20 @@ TEST(HeaderMapImplTest, AddReferenceKey) { HeaderMapImpl headers; LowerCaseString foo("hello"); headers.addReferenceKey(foo, "world"); - EXPECT_NE("world", headers.get(foo)->value().c_str()); - EXPECT_STREQ("world", headers.get(foo)->value().c_str()); + EXPECT_NE("world", headers.get(foo)->value().getStringView().data()); + EXPECT_EQ("world", headers.get(foo)->value().getStringView()); } TEST(HeaderMapImplTest, SetReferenceKey) { HeaderMapImpl headers; LowerCaseString foo("hello"); headers.setReferenceKey(foo, "world"); - EXPECT_NE("world", headers.get(foo)->value().c_str()); - EXPECT_STREQ("world", headers.get(foo)->value().c_str()); + EXPECT_NE("world", headers.get(foo)->value().getStringView().data()); + EXPECT_EQ("world", headers.get(foo)->value().getStringView()); headers.setReferenceKey(foo, "monde"); - EXPECT_NE("monde", headers.get(foo)->value().c_str()); - EXPECT_STREQ("monde", headers.get(foo)->value().c_str()); + EXPECT_NE("monde", headers.get(foo)->value().getStringView().data()); + EXPECT_EQ("monde", headers.get(foo)->value().getStringView()); } TEST(HeaderMapImplTest, AddCopy) { @@ -516,16 +518,16 @@ TEST(HeaderMapImplTest, AddCopy) { const HeaderString& value = headers.get(*lcKeyPtr)->value(); - EXPECT_STREQ("world", value.c_str()); + EXPECT_EQ("world", value.getStringView()); EXPECT_EQ(5UL, value.size()); lcKeyPtr.reset(); const HeaderString& value2 = headers.get(LowerCaseString("hello"))->value(); - EXPECT_STREQ("world", value2.c_str()); + EXPECT_EQ("world", value2.getStringView()); EXPECT_EQ(5UL, value2.size()); - EXPECT_EQ(value.c_str(), value2.c_str()); + EXPECT_EQ(value.getStringView(), value2.getStringView()); EXPECT_EQ(1UL, headers.size()); // Repeat with an int value. @@ -543,14 +545,14 @@ TEST(HeaderMapImplTest, AddCopy) { const HeaderString& value3 = headers.get(*lcKeyPtr)->value(); - EXPECT_STREQ("42", value3.c_str()); + EXPECT_EQ("42", value3.getStringView()); EXPECT_EQ(2UL, value3.size()); lcKeyPtr.reset(); const HeaderString& value4 = headers.get(LowerCaseString("hello"))->value(); - EXPECT_STREQ("42", value4.c_str()); + EXPECT_EQ("42", value4.getStringView()); EXPECT_EQ(2UL, value4.size()); EXPECT_EQ(1UL, headers.size()); @@ -558,22 +560,22 @@ TEST(HeaderMapImplTest, AddCopy) { LowerCaseString lcKey3(std::string("he") + "ll" + "o"); EXPECT_STREQ("hello", lcKey3.get().c_str()); - EXPECT_STREQ("42", headers.get(lcKey3)->value().c_str()); + EXPECT_EQ("42", headers.get(lcKey3)->value().getStringView()); EXPECT_EQ(2UL, headers.get(lcKey3)->value().size()); LowerCaseString cache_control("cache-control"); headers.addCopy(cache_control, "max-age=1345"); - EXPECT_STREQ("max-age=1345", headers.get(cache_control)->value().c_str()); - EXPECT_STREQ("max-age=1345", headers.CacheControl()->value().c_str()); + EXPECT_EQ("max-age=1345", headers.get(cache_control)->value().getStringView()); + EXPECT_EQ("max-age=1345", headers.CacheControl()->value().getStringView()); headers.addCopy(cache_control, "public"); - EXPECT_STREQ("max-age=1345,public", headers.get(cache_control)->value().c_str()); + EXPECT_EQ("max-age=1345,public", headers.get(cache_control)->value().getStringView()); headers.addCopy(cache_control, ""); - EXPECT_STREQ("max-age=1345,public", headers.get(cache_control)->value().c_str()); + EXPECT_EQ("max-age=1345,public", headers.get(cache_control)->value().getStringView()); headers.addCopy(cache_control, 123); - EXPECT_STREQ("max-age=1345,public,123", headers.get(cache_control)->value().c_str()); + EXPECT_EQ("max-age=1345,public,123", headers.get(cache_control)->value().getStringView()); headers.addCopy(cache_control, std::numeric_limits::max()); - EXPECT_STREQ("max-age=1345,public,123,18446744073709551615", - headers.get(cache_control)->value().c_str()); + EXPECT_EQ("max-age=1345,public,123,18446744073709551615", + headers.get(cache_control)->value().getStringView()); } TEST(HeaderMapImplTest, Equality) { @@ -593,7 +595,7 @@ TEST(HeaderMapImplTest, LargeCharInHeader) { LowerCaseString static_key("\x90hello"); std::string ref_value("value"); headers.addReference(static_key, ref_value); - EXPECT_STREQ("value", headers.get(static_key)->value().c_str()); + EXPECT_EQ("value", headers.get(static_key)->value().getStringView()); } TEST(HeaderMapImplTest, Iterate) { @@ -613,7 +615,8 @@ TEST(HeaderMapImplTest, Iterate) { EXPECT_CALL(cb, Call("foo", "bar")); headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -635,8 +638,9 @@ TEST(HeaderMapImplTest, IterateReverse) { // no "hello" headers.iterateReverse( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); - if ("foo" != std::string{header.key().c_str()}) { + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); + if (header.key().getStringView() != "foo") { return HeaderMap::Iterate::Continue; } else { return HeaderMap::Iterate::Break; @@ -661,7 +665,7 @@ TEST(HeaderMapImplTest, Lookup) { { const HeaderEntry* entry; EXPECT_EQ(HeaderMap::Lookup::Found, headers.lookup(Headers::get().ContentLength, &entry)); - EXPECT_STREQ("5", entry->value().c_str()); + EXPECT_EQ("5", entry->value().getStringView()); } // Lookup returns HeaderMap::Lookup::NotFound if a predefined inline header does not exist. @@ -675,17 +679,17 @@ TEST(HeaderMapImplTest, Lookup) { TEST(HeaderMapImplTest, Get) { { const TestHeaderMapImpl headers{{":path", "/"}, {"hello", "world"}}; - EXPECT_STREQ("/", headers.get(LowerCaseString(":path"))->value().c_str()); - EXPECT_STREQ("world", headers.get(LowerCaseString("hello"))->value().c_str()); + EXPECT_EQ("/", headers.get(LowerCaseString(":path"))->value().getStringView()); + EXPECT_EQ("world", headers.get(LowerCaseString("hello"))->value().getStringView()); EXPECT_EQ(nullptr, headers.get(LowerCaseString("foo"))); } { TestHeaderMapImpl headers{{":path", "/"}, {"hello", "world"}}; headers.get(LowerCaseString(":path"))->value(std::string("/new_path")); - EXPECT_STREQ("/new_path", headers.get(LowerCaseString(":path"))->value().c_str()); + EXPECT_EQ("/new_path", headers.get(LowerCaseString(":path"))->value().getStringView()); headers.get(LowerCaseString("hello"))->value(std::string("world2")); - EXPECT_STREQ("world2", headers.get(LowerCaseString("hello"))->value().c_str()); + EXPECT_EQ("world2", headers.get(LowerCaseString("hello"))->value().getStringView()); EXPECT_EQ(nullptr, headers.get(LowerCaseString("foo"))); } } @@ -720,7 +724,7 @@ TEST(HeaderMapImplTest, TestAppendHeader) { HeaderString value4(empty); HeaderMapImpl::appendToHeader(value4, " "); value4.setInteger(0); - EXPECT_STREQ("0", value4.c_str()); + EXPECT_EQ("0", value4.getStringView()); EXPECT_EQ(1U, value4.size()); } } @@ -768,7 +772,8 @@ TEST(HeaderMapImplTest, PseudoHeaderOrder) { headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -783,7 +788,8 @@ TEST(HeaderMapImplTest, PseudoHeaderOrder) { headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -799,7 +805,8 @@ TEST(HeaderMapImplTest, PseudoHeaderOrder) { headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -814,7 +821,8 @@ TEST(HeaderMapImplTest, PseudoHeaderOrder) { headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -830,7 +838,8 @@ TEST(HeaderMapImplTest, PseudoHeaderOrder) { headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -847,7 +856,8 @@ TEST(HeaderMapImplTest, PseudoHeaderOrder) { headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -863,7 +873,8 @@ TEST(HeaderMapImplTest, PseudoHeaderOrder) { headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -882,7 +893,8 @@ TEST(HeaderMapImplTest, PseudoHeaderOrder) { headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -905,7 +917,8 @@ TEST(HeaderMapImplTest, PseudoHeaderOrder) { headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -928,7 +941,8 @@ TEST(HeaderMapImplTest, PseudoHeaderOrder) { headers.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> HeaderMap::Iterate { - static_cast(cb_v)->Call(header.key().c_str(), header.value().c_str()); + static_cast(cb_v)->Call(std::string(header.key().getStringView()), + std::string(header.value().getStringView())); return HeaderMap::Iterate::Continue; }, &cb); @@ -942,13 +956,13 @@ TEST(HeaderMapImplTest, TestHeaderMapImplyCopy) { TestHeaderMapImpl foo; foo.addCopy(LowerCaseString("foo"), "bar"); auto headers = std::make_unique(foo); - EXPECT_STREQ("bar", headers->get(LowerCaseString("foo"))->value().c_str()); + EXPECT_EQ("bar", headers->get(LowerCaseString("foo"))->value().getStringView()); TestHeaderMapImpl baz{{"foo", "baz"}}; baz = *headers; - EXPECT_STREQ("bar", baz.get(LowerCaseString("foo"))->value().c_str()); + EXPECT_EQ("bar", baz.get(LowerCaseString("foo"))->value().getStringView()); const TestHeaderMapImpl& baz2 = baz; baz = baz2; - EXPECT_STREQ("bar", baz.get(LowerCaseString("foo"))->value().c_str()); + EXPECT_EQ("bar", baz.get(LowerCaseString("foo"))->value().getStringView()); } } // namespace Http diff --git a/test/common/http/header_utility_test.cc b/test/common/http/header_utility_test.cc index 0d8c82d134245..0163e9ea8a800 100644 --- a/test/common/http/header_utility_test.cc +++ b/test/common/http/header_utility_test.cc @@ -412,8 +412,8 @@ TEST(HeaderAddTest, HeaderAdd) { headers_to_add.iterate( [](const Http::HeaderEntry& entry, void* context) -> Http::HeaderMap::Iterate { TestHeaderMapImpl* headers = static_cast(context); - Http::LowerCaseString lower_key{entry.key().c_str()}; - EXPECT_STREQ(entry.value().c_str(), headers->get(lower_key)->value().c_str()); + Http::LowerCaseString lower_key{std::string(entry.key().getStringView())}; + EXPECT_EQ(entry.value().getStringView(), headers->get(lower_key)->value().getStringView()); return Http::HeaderMap::Iterate::Continue; }, &headers); diff --git a/test/common/http/utility_test.cc b/test/common/http/utility_test.cc index a0abcd3e8645c..e2e354c1da9a4 100644 --- a/test/common/http/utility_test.cc +++ b/test/common/http/utility_test.cc @@ -467,12 +467,12 @@ TEST(HttpUtility, SendLocalGrpcReply) { EXPECT_CALL(callbacks, encodeHeaders_(_, true)) .WillOnce(Invoke([&](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ(headers.Status()->value().c_str(), "200"); + EXPECT_EQ(headers.Status()->value().getStringView(), "200"); EXPECT_NE(headers.GrpcStatus(), nullptr); - EXPECT_EQ(headers.GrpcStatus()->value().c_str(), + EXPECT_EQ(headers.GrpcStatus()->value().getStringView(), std::to_string(enumToInt(Grpc::Status::GrpcStatus::Unknown))); EXPECT_NE(headers.GrpcMessage(), nullptr); - EXPECT_STREQ(headers.GrpcMessage()->value().c_str(), "large"); + EXPECT_EQ(headers.GrpcMessage()->value().getStringView(), "large"); })); Utility::sendLocalReply(true, callbacks, is_reset, Http::Code::PayloadTooLarge, "large", absl::nullopt, false); @@ -484,7 +484,7 @@ TEST(HttpUtility, RateLimitedGrpcStatus) { EXPECT_CALL(callbacks, encodeHeaders_(_, true)) .WillOnce(Invoke([&](const HeaderMap& headers, bool) -> void { EXPECT_NE(headers.GrpcStatus(), nullptr); - EXPECT_EQ(headers.GrpcStatus()->value().c_str(), + EXPECT_EQ(headers.GrpcStatus()->value().getStringView(), std::to_string(enumToInt(Grpc::Status::GrpcStatus::Unavailable))); })); Utility::sendLocalReply(true, callbacks, false, Http::Code::TooManyRequests, "", absl::nullopt, @@ -493,7 +493,7 @@ TEST(HttpUtility, RateLimitedGrpcStatus) { EXPECT_CALL(callbacks, encodeHeaders_(_, true)) .WillOnce(Invoke([&](const HeaderMap& headers, bool) -> void { EXPECT_NE(headers.GrpcStatus(), nullptr); - EXPECT_EQ(headers.GrpcStatus()->value().c_str(), + EXPECT_EQ(headers.GrpcStatus()->value().getStringView(), std::to_string(enumToInt(Grpc::Status::GrpcStatus::ResourceExhausted))); })); Utility::sendLocalReply( @@ -519,8 +519,8 @@ TEST(HttpUtility, SendLocalReplyHeadRequest) { bool is_reset = false; EXPECT_CALL(callbacks, encodeHeaders_(_, true)) .WillOnce(Invoke([&](const HeaderMap& headers, bool) -> void { - EXPECT_STREQ(headers.ContentLength()->value().c_str(), - fmt::format("{}", strlen("large")).c_str()); + EXPECT_EQ(headers.ContentLength()->value().getStringView(), + fmt::format("{}", strlen("large"))); })); Utility::sendLocalReply(false, callbacks, is_reset, Http::Code::PayloadTooLarge, "large", absl::nullopt, true); @@ -569,8 +569,8 @@ TEST(HttpUtility, TestPrepareHeaders) { Http::MessagePtr message = Utility::prepareHeaders(http_uri); - EXPECT_STREQ("/x/y/z", message->headers().Path()->value().c_str()); - EXPECT_STREQ("dns.name", message->headers().Host()->value().c_str()); + EXPECT_EQ("/x/y/z", message->headers().Path()->value().getStringView()); + EXPECT_EQ("dns.name", message->headers().Host()->value().getStringView()); } TEST(HttpUtility, QueryParamsToString) { diff --git a/test/common/router/header_formatter_test.cc b/test/common/router/header_formatter_test.cc index 13d47e42d3da7..cbc37857c76e8 100644 --- a/test/common/router/header_formatter_test.cc +++ b/test/common/router/header_formatter_test.cc @@ -676,15 +676,15 @@ match: { prefix: "/new_endpoint" } EXPECT_EQ("123456000, 1, 12, 123, 1234, 12345, 123456, 1234560, 12345600, 123456000", header_map.get_("x-request-start-range")); - typedef std::map CountMap; + typedef absl::flat_hash_map CountMap; CountMap counts; header_map.iterate( [](const Http::HeaderEntry& header, void* cb_v) -> Http::HeaderMap::Iterate { CountMap* m = static_cast(cb_v); - std::string key = std::string{header.key().c_str()}; + absl::string_view key = header.key().getStringView(); CountMap::iterator i = m->find(key); if (i == m->end()) { - m->insert({key, 1}); + m->insert({std::string(key), 1}); } else { i->second++; } diff --git a/test/common/router/router_test.cc b/test/common/router/router_test.cc index b51a005c111bc..431b80aecc9e4 100644 --- a/test/common/router/router_test.cc +++ b/test/common/router/router_test.cc @@ -491,7 +491,7 @@ TEST_F(RouterTest, AddCookie) { EXPECT_CALL(callbacks_, encodeHeaders_(_, _)) .WillOnce(Invoke([&](const Http::HeaderMap& headers, const bool) -> void { - EXPECT_EQ(std::string{headers.get(Http::Headers::get().SetCookie)->value().c_str()}, + EXPECT_EQ(std::string{headers.get(Http::Headers::get().SetCookie)->value().getStringView()}, "foo=\"" + cookie_value + "\"; Max-Age=1337; HttpOnly"); })); expectResponseTimerCreate(); @@ -538,7 +538,7 @@ TEST_F(RouterTest, AddCookieNoDuplicate) { EXPECT_CALL(callbacks_, encodeHeaders_(_, _)) .WillOnce(Invoke([&](const Http::HeaderMap& headers, const bool) -> void { - EXPECT_STREQ(headers.get(Http::Headers::get().SetCookie)->value().c_str(), "foo=baz"); + EXPECT_EQ(headers.get(Http::Headers::get().SetCookie)->value().getStringView(), "foo=baz"); })); expectResponseTimerCreate(); @@ -592,9 +592,9 @@ TEST_F(RouterTest, AddMultipleCookies) { headers.iterate( [](const Http::HeaderEntry& header, void* context) -> Http::HeaderMap::Iterate { - if (header.key().c_str() == Http::Headers::get().SetCookie.get().c_str()) { + if (header.key() == Http::Headers::get().SetCookie.get()) { static_cast*>(context)->Call( - std::string(header.value().c_str())); + std::string(header.value().getStringView())); } return Http::HeaderMap::Iterate::Continue; }, diff --git a/test/common/router/shadow_writer_impl_test.cc b/test/common/router/shadow_writer_impl_test.cc index d4b8682fa7697..245c67be85b31 100644 --- a/test/common/router/shadow_writer_impl_test.cc +++ b/test/common/router/shadow_writer_impl_test.cc @@ -34,7 +34,7 @@ class ShadowWriterImplTest : public testing::Test { Invoke([&](Http::MessagePtr& inner_message, Http::AsyncClient::Callbacks& callbacks, const Http::AsyncClient::RequestOptions&) -> Http::AsyncClient::Request* { EXPECT_EQ(message, inner_message); - EXPECT_EQ(shadowed_host, message->headers().Host()->value().c_str()); + EXPECT_EQ(shadowed_host, message->headers().Host()->value().getStringView()); callback_ = &callbacks; return &request; })); diff --git a/test/common/upstream/health_checker_impl_test.cc b/test/common/upstream/health_checker_impl_test.cc index aca25bf4bc82b..bff564d59491f 100644 --- a/test/common/upstream/health_checker_impl_test.cc +++ b/test/common/upstream/health_checker_impl_test.cc @@ -850,9 +850,10 @@ TEST_F(HttpHealthCheckerImplTest, ZeroRetryInterval) { EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_)); EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeHeaders(_, true)) .WillOnce(Invoke([&](const Http::HeaderMap& headers, bool) { - EXPECT_EQ(headers.Host()->value().c_str(), host); - EXPECT_EQ(headers.Path()->value().c_str(), path); - EXPECT_EQ(headers.Scheme()->value().c_str(), Http::Headers::get().SchemeValues.Http); + EXPECT_EQ(headers.Host()->value().getStringView(), host); + EXPECT_EQ(headers.Path()->value().getStringView(), path); + EXPECT_EQ(headers.Scheme()->value().getStringView(), + Http::Headers::get().SchemeValues.Http); })); health_checker_->start(); @@ -882,9 +883,10 @@ TEST_F(HttpHealthCheckerImplTest, SuccessServiceCheck) { EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_)); EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeHeaders(_, true)) .WillOnce(Invoke([&](const Http::HeaderMap& headers, bool) { - EXPECT_EQ(headers.Host()->value().c_str(), host); - EXPECT_EQ(headers.Path()->value().c_str(), path); - EXPECT_EQ(headers.Scheme()->value().c_str(), Http::Headers::get().SchemeValues.Http); + EXPECT_EQ(headers.Host()->value().getStringView(), host); + EXPECT_EQ(headers.Path()->value().getStringView(), path); + EXPECT_EQ(headers.Scheme()->value().getStringView(), + Http::Headers::get().SchemeValues.Http); })); health_checker_->start(); @@ -916,8 +918,8 @@ TEST_F(HttpHealthCheckerImplTest, SuccessServiceCheckWithCustomHostValue) { EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_)); EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeHeaders(_, true)) .WillOnce(Invoke([&](const Http::HeaderMap& headers, bool) { - EXPECT_EQ(headers.Host()->value().c_str(), host); - EXPECT_EQ(headers.Path()->value().c_str(), path); + EXPECT_EQ(headers.Host()->value().getStringView(), host); + EXPECT_EQ(headers.Path()->value().getStringView(), path); })); health_checker_->start(); @@ -977,23 +979,23 @@ TEST_F(HttpHealthCheckerImplTest, SuccessServiceCheckWithAdditionalHeaders) { EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_)); EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeHeaders(_, true)) .WillRepeatedly(Invoke([&](const Http::HeaderMap& headers, bool) { - EXPECT_EQ(headers.get(header_ok)->value().c_str(), value_ok); - EXPECT_EQ(headers.get(header_cool)->value().c_str(), value_cool); - EXPECT_EQ(headers.get(header_awesome)->value().c_str(), value_awesome); + EXPECT_EQ(headers.get(header_ok)->value().getStringView(), value_ok); + EXPECT_EQ(headers.get(header_cool)->value().getStringView(), value_cool); + EXPECT_EQ(headers.get(header_awesome)->value().getStringView(), value_awesome); - EXPECT_EQ(headers.UserAgent()->value().c_str(), value_user_agent); - EXPECT_EQ(headers.get(upstream_metadata)->value().c_str(), value_upstream_metadata); + EXPECT_EQ(headers.UserAgent()->value().getStringView(), value_user_agent); + EXPECT_EQ(headers.get(upstream_metadata)->value().getStringView(), value_upstream_metadata); - EXPECT_EQ(headers.get(protocol)->value().c_str(), value_protocol); - EXPECT_EQ(headers.get(downstream_remote_address_without_port)->value().c_str(), + EXPECT_EQ(headers.get(protocol)->value().getStringView(), value_protocol); + EXPECT_EQ(headers.get(downstream_remote_address_without_port)->value().getStringView(), value_downstream_remote_address_without_port); - EXPECT_EQ(headers.get(downstream_local_address)->value().c_str(), + EXPECT_EQ(headers.get(downstream_local_address)->value().getStringView(), value_downstream_local_address); - EXPECT_EQ(headers.get(downstream_local_address_without_port)->value().c_str(), + EXPECT_EQ(headers.get(downstream_local_address_without_port)->value().getStringView(), value_downstream_local_address_without_port); - EXPECT_NE(headers.get(start_time)->value().c_str(), current_start_time); - current_start_time = headers.get(start_time)->value().c_str(); + EXPECT_NE(headers.get(start_time)->value().getStringView(), current_start_time); + current_start_time = std::string(headers.get(start_time)->value().getStringView()); })); health_checker_->start(); @@ -1780,8 +1782,8 @@ TEST_F(HttpHealthCheckerImplTest, SuccessServiceCheckWithAltPort) { EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_)); EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeHeaders(_, true)) .WillOnce(Invoke([&](const Http::HeaderMap& headers, bool) { - EXPECT_EQ(headers.Host()->value().c_str(), host); - EXPECT_EQ(headers.Path()->value().c_str(), path); + EXPECT_EQ(headers.Host()->value().getStringView(), host); + EXPECT_EQ(headers.Path()->value().getStringView(), path); })); health_checker_->start(); @@ -2855,11 +2857,13 @@ class GrpcHealthCheckerImplTestBase { EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeHeaders(_, false)) .WillOnce(Invoke([&](const Http::HeaderMap& headers, bool) { EXPECT_EQ(Http::Headers::get().ContentTypeValues.Grpc, - headers.ContentType()->value().c_str()); - EXPECT_EQ(std::string("/grpc.health.v1.Health/Check"), headers.Path()->value().c_str()); - EXPECT_EQ(Http::Headers::get().SchemeValues.Http, headers.Scheme()->value().c_str()); + headers.ContentType()->value().getStringView()); + EXPECT_EQ(std::string("/grpc.health.v1.Health/Check"), + headers.Path()->value().getStringView()); + EXPECT_EQ(Http::Headers::get().SchemeValues.Http, + headers.Scheme()->value().getStringView()); EXPECT_NE(nullptr, headers.Method()); - EXPECT_EQ(expected_host, headers.Host()->value().c_str()); + EXPECT_EQ(expected_host, headers.Host()->value().getStringView()); })); EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeData(_, true)) .WillOnce(Invoke([&](Buffer::Instance& data, bool) { diff --git a/test/extensions/access_loggers/http_grpc/grpc_access_log_integration_test.cc b/test/extensions/access_loggers/http_grpc/grpc_access_log_integration_test.cc index c759bdd8856b7..0e3188e776839 100644 --- a/test/extensions/access_loggers/http_grpc/grpc_access_log_integration_test.cc +++ b/test/extensions/access_loggers/http_grpc/grpc_access_log_integration_test.cc @@ -67,10 +67,11 @@ class AccessLogIntegrationTest : public Grpc::GrpcClientIntegrationParamTest, AssertionResult waitForAccessLogRequest(const std::string& expected_request_msg_yaml) { envoy::service::accesslog::v2::StreamAccessLogsMessage request_msg; VERIFY_ASSERTION(access_log_request_->waitForGrpcMessage(*dispatcher_, request_msg)); - EXPECT_STREQ("POST", access_log_request_->headers().Method()->value().c_str()); - EXPECT_STREQ("/envoy.service.accesslog.v2.AccessLogService/StreamAccessLogs", - access_log_request_->headers().Path()->value().c_str()); - EXPECT_STREQ("application/grpc", access_log_request_->headers().ContentType()->value().c_str()); + EXPECT_EQ("POST", access_log_request_->headers().Method()->value().getStringView()); + EXPECT_EQ("/envoy.service.accesslog.v2.AccessLogService/StreamAccessLogs", + access_log_request_->headers().Path()->value().getStringView()); + EXPECT_EQ("application/grpc", + access_log_request_->headers().ContentType()->value().getStringView()); envoy::service::accesslog::v2::StreamAccessLogsMessage expected_request_msg; MessageUtil::loadFromYaml(expected_request_msg_yaml, expected_request_msg); @@ -140,7 +141,7 @@ TEST_P(AccessLogIntegrationTest, BasicAccessLogFlow) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("http"), "GET", "/notfound", "", downstream_protocol_, version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("404", response->headers().Status()->value().c_str()); + EXPECT_EQ("404", response->headers().Status()->value().getStringView()); ASSERT_TRUE(waitForAccessLogRequest(R"EOF( http_logs: log_entry: @@ -178,7 +179,7 @@ TEST_P(AccessLogIntegrationTest, BasicAccessLogFlow) { response = IntegrationUtil::makeSingleRequest(lookupPort("http"), "GET", "/notfound", "", downstream_protocol_, version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("404", response->headers().Status()->value().c_str()); + EXPECT_EQ("404", response->headers().Status()->value().getStringView()); ASSERT_TRUE(waitForAccessLogStream()); ASSERT_TRUE(waitForAccessLogRequest(fmt::format(R"EOF( identifier: diff --git a/test/extensions/filters/http/buffer/buffer_filter_integration_test.cc b/test/extensions/filters/http/buffer/buffer_filter_integration_test.cc index 49761fac28f5b..bb7dd5920f86c 100644 --- a/test/extensions/filters/http/buffer/buffer_filter_integration_test.cc +++ b/test/extensions/filters/http/buffer/buffer_filter_integration_test.cc @@ -53,7 +53,7 @@ TEST_P(BufferIntegrationTest, RouterRequestBufferLimitExceeded) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("413", response->headers().Status()->value().c_str()); + EXPECT_EQ("413", response->headers().Status()->value().getStringView()); } ConfigHelper::HttpModifierFunction overrideConfig(const std::string& json_config) { @@ -94,7 +94,7 @@ TEST_P(BufferIntegrationTest, RouteDisabled) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } TEST_P(BufferIntegrationTest, RouteOverride) { @@ -120,7 +120,7 @@ TEST_P(BufferIntegrationTest, RouteOverride) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } } // namespace diff --git a/test/extensions/filters/http/common/aws/signer_impl_test.cc b/test/extensions/filters/http/common/aws/signer_impl_test.cc index 67f990b3228b9..fe4991c66d9d5 100644 --- a/test/extensions/filters/http/common/aws/signer_impl_test.cc +++ b/test/extensions/filters/http/common/aws/signer_impl_test.cc @@ -82,12 +82,12 @@ TEST_F(SignerImplTest, SignDateHeader) { addPath("/"); signer_.sign(*message_); EXPECT_EQ(nullptr, message_->headers().get(SignatureHeaders::get().ContentSha256)); - EXPECT_STREQ("20180102T030400Z", - message_->headers().get(SignatureHeaders::get().Date)->value().c_str()); - EXPECT_STREQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " - "SignedHeaders=x-amz-date, " - "Signature=1310784f67248cab70d98b9404d601f30d8fe20bd1820560cce224f4131dc1cc", - message_->headers().Authorization()->value().c_str()); + EXPECT_EQ("20180102T030400Z", + message_->headers().get(SignatureHeaders::get().Date)->value().getStringView()); + EXPECT_EQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " + "SignedHeaders=x-amz-date, " + "Signature=1310784f67248cab70d98b9404d601f30d8fe20bd1820560cce224f4131dc1cc", + message_->headers().Authorization()->value().getStringView()); } // Verify we sign the security token header if the token is present in the credentials @@ -96,12 +96,13 @@ TEST_F(SignerImplTest, SignSecurityTokenHeader) { addMethod("GET"); addPath("/"); signer_.sign(*message_); - EXPECT_STREQ("token", - message_->headers().get(SignatureHeaders::get().SecurityToken)->value().c_str()); - EXPECT_STREQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " - "SignedHeaders=x-amz-date;x-amz-security-token, " - "Signature=ff1d9fa7e54a72677b5336df047bb1f1493f86b92099973bf62da3af852d1679", - message_->headers().Authorization()->value().c_str()); + EXPECT_EQ( + "token", + message_->headers().get(SignatureHeaders::get().SecurityToken)->value().getStringView()); + EXPECT_EQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " + "SignedHeaders=x-amz-date;x-amz-security-token, " + "Signature=ff1d9fa7e54a72677b5336df047bb1f1493f86b92099973bf62da3af852d1679", + message_->headers().Authorization()->value().getStringView()); } // Verify we sign the content header as the hashed empty string if the body is empty @@ -110,12 +111,13 @@ TEST_F(SignerImplTest, SignEmptyContentHeader) { addMethod("GET"); addPath("/"); signer_.sign(*message_, true); - EXPECT_STREQ(SignatureConstants::get().HashedEmptyString.c_str(), - message_->headers().get(SignatureHeaders::get().ContentSha256)->value().c_str()); - EXPECT_STREQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " - "SignedHeaders=x-amz-content-sha256;x-amz-date, " - "Signature=4ee6aa9355259c18133f150b139ea9aeb7969c9408ad361b2151f50a516afe42", - message_->headers().Authorization()->value().c_str()); + EXPECT_EQ( + SignatureConstants::get().HashedEmptyString, + message_->headers().get(SignatureHeaders::get().ContentSha256)->value().getStringView()); + EXPECT_EQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " + "SignedHeaders=x-amz-content-sha256;x-amz-date, " + "Signature=4ee6aa9355259c18133f150b139ea9aeb7969c9408ad361b2151f50a516afe42", + message_->headers().Authorization()->value().getStringView()); } // Verify we sign the content header correctly when we have a body @@ -125,12 +127,13 @@ TEST_F(SignerImplTest, SignContentHeader) { addPath("/"); setBody("test1234"); signer_.sign(*message_, true); - EXPECT_STREQ("937e8d5fbb48bd4949536cd65b8d35c426b80d2f830c5c308e2cdec422ae2244", - message_->headers().get(SignatureHeaders::get().ContentSha256)->value().c_str()); - EXPECT_STREQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " - "SignedHeaders=x-amz-content-sha256;x-amz-date, " - "Signature=4eab89c36f45f2032d6010ba1adab93f8510ddd6afe540821f3a05bb0253e27b", - message_->headers().Authorization()->value().c_str()); + EXPECT_EQ( + "937e8d5fbb48bd4949536cd65b8d35c426b80d2f830c5c308e2cdec422ae2244", + message_->headers().get(SignatureHeaders::get().ContentSha256)->value().getStringView()); + EXPECT_EQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " + "SignedHeaders=x-amz-content-sha256;x-amz-date, " + "Signature=4eab89c36f45f2032d6010ba1adab93f8510ddd6afe540821f3a05bb0253e27b", + message_->headers().Authorization()->value().getStringView()); } // Verify we sign some extra headers @@ -142,10 +145,10 @@ TEST_F(SignerImplTest, SignExtraHeaders) { addHeader("b", "b_value"); addHeader("c", "c_value"); signer_.sign(*message_); - EXPECT_STREQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " - "SignedHeaders=a;b;c;x-amz-date, " - "Signature=d5e025e1cf0d5af0d83110bc2ef1cafd2d9dca1dea9d7767f58308da64aa6558", - message_->headers().Authorization()->value().c_str()); + EXPECT_EQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " + "SignedHeaders=a;b;c;x-amz-date, " + "Signature=d5e025e1cf0d5af0d83110bc2ef1cafd2d9dca1dea9d7767f58308da64aa6558", + message_->headers().Authorization()->value().getStringView()); } // Verify signing a host header @@ -155,10 +158,10 @@ TEST_F(SignerImplTest, SignHostHeader) { addPath("/"); addHeader("host", "www.example.com"); signer_.sign(*message_); - EXPECT_STREQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " - "SignedHeaders=host;x-amz-date, " - "Signature=60216ee44dd651322ea10cc6747308dd30e582aaa773f6c1b1354e486385c021", - message_->headers().Authorization()->value().c_str()); + EXPECT_EQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " + "SignedHeaders=host;x-amz-date, " + "Signature=60216ee44dd651322ea10cc6747308dd30e582aaa773f6c1b1354e486385c021", + message_->headers().Authorization()->value().getStringView()); } } // namespace @@ -166,4 +169,4 @@ TEST_F(SignerImplTest, SignHostHeader) { } // namespace Common } // namespace HttpFilters } // namespace Extensions -} // namespace Envoy \ No newline at end of file +} // namespace Envoy diff --git a/test/extensions/filters/http/grpc_json_transcoder/grpc_json_transcoder_integration_test.cc b/test/extensions/filters/http/grpc_json_transcoder/grpc_json_transcoder_integration_test.cc index 6f8450b441d49..9117f17be78ac 100644 --- a/test/extensions/filters/http/grpc_json_transcoder/grpc_json_transcoder_integration_test.cc +++ b/test/extensions/filters/http/grpc_json_transcoder/grpc_json_transcoder_integration_test.cc @@ -136,8 +136,9 @@ class GrpcJsonTranscoderIntegrationTest response_headers.iterate( [](const Http::HeaderEntry& entry, void* context) -> Http::HeaderMap::Iterate { IntegrationStreamDecoder* response = static_cast(context); - Http::LowerCaseString lower_key{entry.key().c_str()}; - EXPECT_STREQ(entry.value().c_str(), response->headers().get(lower_key)->value().c_str()); + Http::LowerCaseString lower_key{std::string(entry.key().getStringView())}; + EXPECT_EQ(entry.value().getStringView(), + response->headers().get(lower_key)->value().getStringView()); return Http::HeaderMap::Iterate::Continue; }, response.get()); diff --git a/test/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter_test.cc b/test/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter_test.cc index b6af82749c8db..1854aaf2948b4 100644 --- a/test/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter_test.cc +++ b/test/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter_test.cc @@ -571,7 +571,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, TranscodingUnaryError) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)) .WillOnce(Invoke([](Http::HeaderMap& headers, bool end_stream) { - EXPECT_STREQ("400", headers.Status()->value().c_str()); + EXPECT_EQ("400", headers.Status()->value().getStringView()); EXPECT_FALSE(end_stream); })); EXPECT_CALL(decoder_callbacks_, encodeData(_, true)); diff --git a/test/extensions/filters/http/grpc_web/grpc_web_filter_test.cc b/test/extensions/filters/http/grpc_web/grpc_web_filter_test.cc index 70e6f51708b9a..bd52b270a517b 100644 --- a/test/extensions/filters/http/grpc_web/grpc_web_filter_test.cc +++ b/test/extensions/filters/http/grpc_web/grpc_web_filter_test.cc @@ -84,7 +84,7 @@ class GrpcWebFilterTest : public testing::TestWithParamvalue().c_str(), code); + StringUtil::atoull(std::string(headers.Status()->value().getStringView()).c_str(), code); EXPECT_EQ(static_cast(expected_code), code); })); EXPECT_CALL(decoder_callbacks_, encodeData(_, _)) @@ -94,12 +94,13 @@ class GrpcWebFilterTest : public testing::TestWithParamvalue().c_str()); + request_headers.ContentType()->value().getStringView()); // Ensure we never send content-length upstream EXPECT_EQ(nullptr, request_headers.ContentLength()); - EXPECT_EQ(Http::Headers::get().TEValues.Trailers, request_headers.TE()->value().c_str()); + EXPECT_EQ(Http::Headers::get().TEValues.Trailers, + request_headers.TE()->value().getStringView()); EXPECT_EQ(Http::Headers::get().GrpcAcceptEncodingValues.Default, - request_headers.GrpcAcceptEncoding()->value().c_str()); + request_headers.GrpcAcceptEncoding()->value().getStringView()); } GrpcWebFilter filter_; @@ -118,7 +119,7 @@ TEST_F(GrpcWebFilterTest, SupportedContentTypes) { request_headers.addCopy(Http::Headers::get().ContentType, content_type); EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); EXPECT_EQ(Http::Headers::get().ContentTypeValues.Grpc, - request_headers.ContentType()->value().c_str()); + request_headers.ContentType()->value().getStringView()); } } @@ -282,8 +283,8 @@ TEST_P(GrpcWebFilterTest, Unary) { request_trailers.addCopy(Http::Headers::get().GrpcStatus, "0"); request_trailers.addCopy(Http::Headers::get().GrpcMessage, "ok"); EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers)); - EXPECT_STREQ("0", request_trailers.GrpcStatus()->value().c_str()); - EXPECT_STREQ("ok", request_trailers.GrpcMessage()->value().c_str()); + EXPECT_EQ("0", request_trailers.GrpcStatus()->value().getStringView()); + EXPECT_EQ("ok", request_trailers.GrpcMessage()->value().getStringView()); // Tests response headers. Http::TestHeaderMapImpl response_headers; @@ -292,10 +293,10 @@ TEST_P(GrpcWebFilterTest, Unary) { EXPECT_EQ("200", response_headers.get_(Http::Headers::get().Status.get())); if (accept_binary_response()) { EXPECT_EQ(Http::Headers::get().ContentTypeValues.GrpcWebProto, - response_headers.ContentType()->value().c_str()); + response_headers.ContentType()->value().getStringView()); } else if (accept_text_response()) { EXPECT_EQ(Http::Headers::get().ContentTypeValues.GrpcWebTextProto, - response_headers.ContentType()->value().c_str()); + response_headers.ContentType()->value().getStringView()); } else { FAIL() << "Unsupported gRPC-Web request accept: " << request_accept(); } @@ -326,7 +327,7 @@ TEST_P(GrpcWebFilterTest, Unary) { EXPECT_EQ(std::string(B64_MESSAGE, B64_MESSAGE_SIZE), encoded_buffer.toString()); } else { FAIL() << "Unsupported gRPC-Web response content-type: " - << response_headers.ContentType()->value().c_str(); + << response_headers.ContentType()->value().getStringView(); } // Tests response trailers. @@ -343,7 +344,7 @@ TEST_P(GrpcWebFilterTest, Unary) { EXPECT_EQ(std::string(TRAILERS, TRAILERS_SIZE), Base64::decode(trailers_buffer.toString())); } else { FAIL() << "Unsupported gRPC-Web response content-type: " - << response_headers.ContentType()->value().c_str(); + << response_headers.ContentType()->value().getStringView(); } } diff --git a/test/extensions/filters/http/gzip/gzip_filter_integration_test.cc b/test/extensions/filters/http/gzip/gzip_filter_integration_test.cc index 4dae4bf226af0..09e210a39e60b 100644 --- a/test/extensions/filters/http/gzip/gzip_filter_integration_test.cc +++ b/test/extensions/filters/http/gzip/gzip_filter_integration_test.cc @@ -36,13 +36,13 @@ class GzipIntegrationTest : public testing::TestWithParamcomplete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); ASSERT_TRUE(response->headers().ContentEncoding() != nullptr); EXPECT_EQ(Http::Headers::get().ContentEncodingValues.Gzip, - response->headers().ContentEncoding()->value().c_str()); + response->headers().ContentEncoding()->value().getStringView()); ASSERT_TRUE(response->headers().TransferEncoding() != nullptr); EXPECT_EQ(Http::Headers::get().TransferEncodingValues.Chunked, - response->headers().TransferEncoding()->value().c_str()); + response->headers().TransferEncoding()->value().getStringView()); Buffer::OwnedImpl decompressed_response{}; const Buffer::OwnedImpl compressed_response{response->body()}; @@ -61,7 +61,7 @@ class GzipIntegrationTest : public testing::TestWithParamcomplete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); ASSERT_TRUE(response->headers().ContentEncoding() == nullptr); ASSERT_EQ(content_length, response->body().size()); EXPECT_EQ(response->body(), std::string(content_length, 'a')); @@ -173,8 +173,8 @@ TEST_P(GzipIntegrationTest, UpstreamResponseAlreadyEncoded) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - ASSERT_STREQ("br", response->headers().ContentEncoding()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + ASSERT_EQ("br", response->headers().ContentEncoding()->value().getStringView()); EXPECT_EQ(128U, response->body().size()); } @@ -197,7 +197,7 @@ TEST_P(GzipIntegrationTest, NotEnoughContentLength) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); ASSERT_TRUE(response->headers().ContentEncoding() == nullptr); EXPECT_EQ(10U, response->body().size()); } @@ -220,7 +220,7 @@ TEST_P(GzipIntegrationTest, EmptyResponse) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("204", response->headers().Status()->value().c_str()); + EXPECT_EQ("204", response->headers().Status()->value().getStringView()); ASSERT_TRUE(response->headers().ContentEncoding() == nullptr); EXPECT_EQ(0U, response->body().size()); } @@ -275,9 +275,9 @@ TEST_P(GzipIntegrationTest, AcceptanceFullConfigChunkedResponse) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - ASSERT_STREQ("gzip", response->headers().ContentEncoding()->value().c_str()); - ASSERT_STREQ("chunked", response->headers().TransferEncoding()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + ASSERT_EQ("gzip", response->headers().ContentEncoding()->value().getStringView()); + ASSERT_EQ("chunked", response->headers().TransferEncoding()->value().getStringView()); } /** @@ -299,8 +299,8 @@ TEST_P(GzipIntegrationTest, AcceptanceFullConfigVeryHeader) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - ASSERT_STREQ("gzip", response->headers().ContentEncoding()->value().c_str()); - ASSERT_STREQ("Cookie, Accept-Encoding", response->headers().Vary()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + ASSERT_EQ("gzip", response->headers().ContentEncoding()->value().getStringView()); + ASSERT_EQ("Cookie, Accept-Encoding", response->headers().Vary()->value().getStringView()); } } // namespace Envoy diff --git a/test/extensions/filters/http/health_check/health_check_test.cc b/test/extensions/filters/http/health_check/health_check_test.cc index cd4d05df1dd2c..bb1552ebe5369 100644 --- a/test/extensions/filters/http/health_check/health_check_test.cc +++ b/test/extensions/filters/http/health_check/health_check_test.cc @@ -111,7 +111,7 @@ TEST_F(HealthCheckFilterNoPassThroughTest, NotHcRequest) { Buffer::OwnedImpl body; EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(body, false)); EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(service_response)); - EXPECT_STREQ("true", service_response.EnvoyImmediateHealthCheckFail()->value().c_str()); + EXPECT_EQ("true", service_response.EnvoyImmediateHealthCheckFail()->value().getStringView()); } TEST_F(HealthCheckFilterNoPassThroughTest, ComputedHealth) { @@ -216,7 +216,8 @@ TEST_F(HealthCheckFilterNoPassThroughTest, HealthCheckFailedCallbackCalled) { .Times(1) .WillRepeatedly(Invoke([&](Http::HeaderMap& headers, bool end_stream) { filter_->encodeHeaders(headers, end_stream); - EXPECT_STREQ("cluster_name", headers.EnvoyUpstreamHealthCheckedCluster()->value().c_str()); + EXPECT_EQ("cluster_name", + headers.EnvoyUpstreamHealthCheckedCluster()->value().getStringView()); EXPECT_EQ(nullptr, headers.EnvoyImmediateHealthCheckFail()); })); @@ -240,8 +241,8 @@ TEST_F(HealthCheckFilterPassThroughTest, Ok) { Http::TestHeaderMapImpl service_hc_respnose{{":status", "200"}}; EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(service_hc_respnose, true)); - EXPECT_STREQ("cluster_name", - service_hc_respnose.EnvoyUpstreamHealthCheckedCluster()->value().c_str()); + EXPECT_EQ("cluster_name", + service_hc_respnose.EnvoyUpstreamHealthCheckedCluster()->value().getStringView()); } TEST_F(HealthCheckFilterPassThroughTest, OkWithContinue) { @@ -260,8 +261,8 @@ TEST_F(HealthCheckFilterPassThroughTest, OkWithContinue) { EXPECT_EQ(Http::FilterMetadataStatus::Continue, filter_->encodeMetadata(metadata_map)); Http::TestHeaderMapImpl service_hc_respnose{{":status", "200"}}; EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(service_hc_respnose, true)); - EXPECT_STREQ("cluster_name", - service_hc_respnose.EnvoyUpstreamHealthCheckedCluster()->value().c_str()); + EXPECT_EQ("cluster_name", + service_hc_respnose.EnvoyUpstreamHealthCheckedCluster()->value().getStringView()); } TEST_F(HealthCheckFilterPassThroughTest, Failed) { @@ -290,7 +291,8 @@ TEST_F(HealthCheckFilterCachingTest, CachedServiceUnavailableCallbackCalled) { .Times(1) .WillRepeatedly(Invoke([&](Http::HeaderMap& headers, bool end_stream) { filter_->encodeHeaders(headers, end_stream); - EXPECT_STREQ("cluster_name", headers.EnvoyUpstreamHealthCheckedCluster()->value().c_str()); + EXPECT_EQ("cluster_name", + headers.EnvoyUpstreamHealthCheckedCluster()->value().getStringView()); })); EXPECT_CALL(callbacks_.stream_info_, @@ -311,7 +313,8 @@ TEST_F(HealthCheckFilterCachingTest, CachedOkCallbackNotCalled) { .Times(1) .WillRepeatedly(Invoke([&](Http::HeaderMap& headers, bool end_stream) { filter_->encodeHeaders(headers, end_stream); - EXPECT_STREQ("cluster_name", headers.EnvoyUpstreamHealthCheckedCluster()->value().c_str()); + EXPECT_EQ("cluster_name", + headers.EnvoyUpstreamHealthCheckedCluster()->value().getStringView()); })); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, @@ -338,7 +341,8 @@ TEST_F(HealthCheckFilterCachingTest, All) { .Times(1) .WillRepeatedly(Invoke([&](Http::HeaderMap& headers, bool end_stream) { filter_->encodeHeaders(headers, end_stream); - EXPECT_STREQ("cluster_name", headers.EnvoyUpstreamHealthCheckedCluster()->value().c_str()); + EXPECT_EQ("cluster_name", + headers.EnvoyUpstreamHealthCheckedCluster()->value().getStringView()); })); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, filter_->decodeHeaders(request_headers_, true)); @@ -371,7 +375,8 @@ TEST_F(HealthCheckFilterCachingTest, DegradedHeader) { .Times(1) .WillRepeatedly(Invoke([&](Http::HeaderMap& headers, bool end_stream) { filter_->encodeHeaders(headers, end_stream); - EXPECT_STREQ("cluster_name", headers.EnvoyUpstreamHealthCheckedCluster()->value().c_str()); + EXPECT_EQ("cluster_name", + headers.EnvoyUpstreamHealthCheckedCluster()->value().getStringView()); })); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, filter_->decodeHeaders(request_headers_, true)); diff --git a/test/extensions/filters/http/jwt_authn/filter_integration_test.cc b/test/extensions/filters/http/jwt_authn/filter_integration_test.cc index c7c5d0ad2f026..4dade512bf24b 100644 --- a/test/extensions/filters/http/jwt_authn/filter_integration_test.cc +++ b/test/extensions/filters/http/jwt_authn/filter_integration_test.cc @@ -111,7 +111,7 @@ TEST_P(LocalJwksIntegrationTest, WithGoodToken) { upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, true); response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } // With local Jwks, this test verifies a request is rejected with an expired Jwt token. @@ -131,7 +131,7 @@ TEST_P(LocalJwksIntegrationTest, ExpiredToken) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("401", response->headers().Status()->value().c_str()); + EXPECT_EQ("401", response->headers().Status()->value().getStringView()); } TEST_P(LocalJwksIntegrationTest, MissingToken) { @@ -149,7 +149,7 @@ TEST_P(LocalJwksIntegrationTest, MissingToken) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("401", response->headers().Status()->value().c_str()); + EXPECT_EQ("401", response->headers().Status()->value().getStringView()); } TEST_P(LocalJwksIntegrationTest, ExpiredTokenHeadReply) { @@ -168,9 +168,9 @@ TEST_P(LocalJwksIntegrationTest, ExpiredTokenHeadReply) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("401", response->headers().Status()->value().c_str()); - EXPECT_STRNE("0", response->headers().ContentLength()->value().c_str()); - EXPECT_STREQ("", response->body().c_str()); + EXPECT_EQ("401", response->headers().Status()->value().getStringView()); + EXPECT_NE("0", response->headers().ContentLength()->value().getStringView()); + EXPECT_THAT(response->body(), ::testing::IsEmpty()); } // This test verifies a request is passed with a path that don't match any requirements. @@ -192,7 +192,7 @@ TEST_P(LocalJwksIntegrationTest, NoRequiresPath) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } // This test verifies JwtRequirement specified from filer state rules @@ -269,7 +269,7 @@ TEST_P(LocalJwksIntegrationTest, FilterStateRequirement) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_EQ(test.expected_status, response->headers().Status()->value().c_str()); + EXPECT_EQ(test.expected_status, response->headers().Status()->value().getStringView()); } } @@ -364,7 +364,7 @@ TEST_P(RemoteJwksIntegrationTest, WithGoodToken) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); cleanup(); } @@ -389,7 +389,7 @@ TEST_P(RemoteJwksIntegrationTest, FetchFailedJwks) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("401", response->headers().Status()->value().c_str()); + EXPECT_EQ("401", response->headers().Status()->value().getStringView()); cleanup(); } diff --git a/test/extensions/filters/http/lua/lua_integration_test.cc b/test/extensions/filters/http/lua/lua_integration_test.cc index 3b7d9b5adc9e1..8e72a0aef4f6f 100644 --- a/test/extensions/filters/http/lua/lua_integration_test.cc +++ b/test/extensions/filters/http/lua/lua_integration_test.cc @@ -156,32 +156,34 @@ name: envoy.lua encoder.encodeData(request_data2, true); waitForNextUpstreamRequest(); - EXPECT_STREQ("10", upstream_request_->headers() - .get(Http::LowerCaseString("request_body_size")) + EXPECT_EQ("10", upstream_request_->headers() + .get(Http::LowerCaseString("request_body_size")) + ->value() + .getStringView()); + + EXPECT_EQ("bar", upstream_request_->headers() + .get(Http::LowerCaseString("request_metadata_foo")) + ->value() + .getStringView()); + + EXPECT_EQ("bat", upstream_request_->headers() + .get(Http::LowerCaseString("request_metadata_baz")) + ->value() + .getStringView()); + EXPECT_EQ("false", upstream_request_->headers() + .get(Http::LowerCaseString("request_secure")) ->value() - .c_str()); - - EXPECT_STREQ("bar", upstream_request_->headers() - .get(Http::LowerCaseString("request_metadata_foo")) - ->value() - .c_str()); - - EXPECT_STREQ("bat", upstream_request_->headers() - .get(Http::LowerCaseString("request_metadata_baz")) - ->value() - .c_str()); - EXPECT_STREQ( - "false", - upstream_request_->headers().get(Http::LowerCaseString("request_secure"))->value().c_str()); - - EXPECT_STREQ( - "HTTP/1.1", - upstream_request_->headers().get(Http::LowerCaseString("request_protocol"))->value().c_str()); + .getStringView()); + + EXPECT_EQ("HTTP/1.1", upstream_request_->headers() + .get(Http::LowerCaseString("request_protocol")) + ->value() + .getStringView()); - EXPECT_STREQ("bar", upstream_request_->headers() - .get(Http::LowerCaseString("request_dynamic_metadata_value")) - ->value() - .c_str()); + EXPECT_EQ("bar", upstream_request_->headers() + .get(Http::LowerCaseString("request_dynamic_metadata_value")) + ->value() + .getStringView()); Http::TestHeaderMapImpl response_headers{{":status", "200"}, {"foo", "bar"}}; upstream_request_->encodeHeaders(response_headers, false); @@ -192,16 +194,21 @@ name: envoy.lua response->waitForEndStream(); - EXPECT_STREQ( - "7", response->headers().get(Http::LowerCaseString("response_body_size"))->value().c_str()); - EXPECT_STREQ( - "bar", - response->headers().get(Http::LowerCaseString("response_metadata_foo"))->value().c_str()); - EXPECT_STREQ( - "bat", - response->headers().get(Http::LowerCaseString("response_metadata_baz"))->value().c_str()); - EXPECT_STREQ("HTTP/1.1", - response->headers().get(Http::LowerCaseString("request_protocol"))->value().c_str()); + EXPECT_EQ("7", response->headers() + .get(Http::LowerCaseString("response_body_size")) + ->value() + .getStringView()); + EXPECT_EQ("bar", response->headers() + .get(Http::LowerCaseString("response_metadata_foo")) + ->value() + .getStringView()); + EXPECT_EQ("bat", response->headers() + .get(Http::LowerCaseString("response_metadata_baz")) + ->value() + .getStringView()); + EXPECT_EQ( + "HTTP/1.1", + response->headers().get(Http::LowerCaseString("request_protocol"))->value().getStringView()); EXPECT_EQ(nullptr, response->headers().get(Http::LowerCaseString("foo"))); cleanup(); @@ -249,13 +256,14 @@ name: envoy.lua lua_request_->encodeData(response_data1, true); waitForNextUpstreamRequest(); - EXPECT_STREQ( - "bar", - upstream_request_->headers().get(Http::LowerCaseString("upstream_foo"))->value().c_str()); - EXPECT_STREQ("4", upstream_request_->headers() - .get(Http::LowerCaseString("upstream_body_size")) - ->value() - .c_str()); + EXPECT_EQ("bar", upstream_request_->headers() + .get(Http::LowerCaseString("upstream_foo")) + ->value() + .getStringView()); + EXPECT_EQ("4", upstream_request_->headers() + .get(Http::LowerCaseString("upstream_body_size")) + ->value() + .getStringView()); upstream_request_->encodeHeaders(default_response_headers_, true); response->waitForEndStream(); @@ -308,7 +316,7 @@ name: envoy.lua cleanup(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("403", response->headers().Status()->value().c_str()); + EXPECT_EQ("403", response->headers().Status()->value().getStringView()); EXPECT_EQ("nope", response->body()); } @@ -341,7 +349,7 @@ name: envoy.lua cleanup(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } // Should survive from 30 calls when calling streamInfo():dynamicMetadata(). This is a regression @@ -374,7 +382,7 @@ name: envoy.lua response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } cleanup(); diff --git a/test/extensions/filters/http/rbac/rbac_filter_integration_test.cc b/test/extensions/filters/http/rbac/rbac_filter_integration_test.cc index d79359d41a067..345e7c32199d9 100644 --- a/test/extensions/filters/http/rbac/rbac_filter_integration_test.cc +++ b/test/extensions/filters/http/rbac/rbac_filter_integration_test.cc @@ -57,7 +57,7 @@ TEST_P(RBACIntegrationTest, Allowed) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } TEST_P(RBACIntegrationTest, Denied) { @@ -77,7 +77,7 @@ TEST_P(RBACIntegrationTest, Denied) { 1024); response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("403", response->headers().Status()->value().c_str()); + EXPECT_EQ("403", response->headers().Status()->value().getStringView()); } TEST_P(RBACIntegrationTest, DeniedWithPrefixRule) { @@ -104,7 +104,7 @@ TEST_P(RBACIntegrationTest, DeniedWithPrefixRule) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } TEST_P(RBACIntegrationTest, RbacPrefixRuleUseNormalizePath) { @@ -129,7 +129,7 @@ TEST_P(RBACIntegrationTest, RbacPrefixRuleUseNormalizePath) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("403", response->headers().Status()->value().c_str()); + EXPECT_EQ("403", response->headers().Status()->value().getStringView()); } TEST_P(RBACIntegrationTest, DeniedHeadReply) { @@ -149,10 +149,10 @@ TEST_P(RBACIntegrationTest, DeniedHeadReply) { 1024); response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("403", response->headers().Status()->value().c_str()); + EXPECT_EQ("403", response->headers().Status()->value().getStringView()); ASSERT_TRUE(response->headers().ContentLength()); - EXPECT_STRNE("0", response->headers().ContentLength()->value().c_str()); - EXPECT_STREQ("", response->body().c_str()); + EXPECT_NE("0", response->headers().ContentLength()->value().getStringView()); + EXPECT_THAT(response->body(), ::testing::IsEmpty()); } TEST_P(RBACIntegrationTest, RouteOverride) { @@ -188,7 +188,7 @@ TEST_P(RBACIntegrationTest, RouteOverride) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } } // namespace diff --git a/test/extensions/filters/http/squash/squash_filter_integration_test.cc b/test/extensions/filters/http/squash/squash_filter_integration_test.cc index ab2ee89f96b77..c6850028195da 100644 --- a/test/extensions/filters/http/squash/squash_filter_integration_test.cc +++ b/test/extensions/filters/http/squash/squash_filter_integration_test.cc @@ -133,8 +133,8 @@ TEST_P(SquashFilterIntegrationTest, TestHappyPath) { response->waitForEndStream(); - EXPECT_STREQ("POST", create_stream->headers().Method()->value().c_str()); - EXPECT_STREQ("/api/v2/debugattachment/", create_stream->headers().Path()->value().c_str()); + EXPECT_EQ("POST", create_stream->headers().Method()->value().getStringView()); + EXPECT_EQ("/api/v2/debugattachment/", create_stream->headers().Path()->value().getStringView()); // Make sure the env var was replaced ProtobufWkt::Struct actualbody; MessageUtil::loadFromJson(create_stream->body().toString(), actualbody); @@ -146,10 +146,11 @@ TEST_P(SquashFilterIntegrationTest, TestHappyPath) { EXPECT_TRUE(MessageDifferencer::Equals(expectedbody, actualbody)); // The second request should be for the created object - EXPECT_STREQ("GET", get_stream->headers().Method()->value().c_str()); - EXPECT_STREQ("/api/v2/debugattachment/oF8iVdiJs5", get_stream->headers().Path()->value().c_str()); + EXPECT_EQ("GET", get_stream->headers().Method()->value().getStringView()); + EXPECT_EQ("/api/v2/debugattachment/oF8iVdiJs5", + get_stream->headers().Path()->value().getStringView()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } TEST_P(SquashFilterIntegrationTest, ErrorAttaching) { @@ -163,7 +164,7 @@ TEST_P(SquashFilterIntegrationTest, ErrorAttaching) { response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } TEST_P(SquashFilterIntegrationTest, TimeoutAttaching) { @@ -179,7 +180,7 @@ TEST_P(SquashFilterIntegrationTest, TimeoutAttaching) { response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } TEST_P(SquashFilterIntegrationTest, ErrorNoSquashServer) { @@ -190,7 +191,7 @@ TEST_P(SquashFilterIntegrationTest, ErrorNoSquashServer) { response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } TEST_P(SquashFilterIntegrationTest, BadCreateResponse) { @@ -202,7 +203,7 @@ TEST_P(SquashFilterIntegrationTest, BadCreateResponse) { response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } TEST_P(SquashFilterIntegrationTest, BadGetResponse) { @@ -216,7 +217,7 @@ TEST_P(SquashFilterIntegrationTest, BadGetResponse) { response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } } // namespace Envoy diff --git a/test/extensions/filters/http/tap/tap_filter_integration_test.cc b/test/extensions/filters/http/tap/tap_filter_integration_test.cc index 524451ca9ff99..47706214017b3 100644 --- a/test/extensions/filters/http/tap/tap_filter_integration_test.cc +++ b/test/extensions/filters/http/tap/tap_filter_integration_test.cc @@ -86,7 +86,7 @@ class TapIntegrationTest : public testing::TestWithParammakeRequestWithBody(admin_request_headers, admin_request_yaml); admin_response_->waitForHeaders(); - EXPECT_STREQ("200", admin_response_->headers().Status()->value().c_str()); + EXPECT_EQ("200", admin_response_->headers().Status()->value().getStringView()); EXPECT_FALSE(admin_response_->complete()); } diff --git a/test/extensions/stats_sinks/metrics_service/metrics_service_integration_test.cc b/test/extensions/stats_sinks/metrics_service/metrics_service_integration_test.cc index 5dc5984308b28..3afded9772b7f 100644 --- a/test/extensions/stats_sinks/metrics_service/metrics_service_integration_test.cc +++ b/test/extensions/stats_sinks/metrics_service/metrics_service_integration_test.cc @@ -76,11 +76,11 @@ class MetricsServiceIntegrationTest : public Grpc::GrpcClientIntegrationParamTes while (!(known_counter_exists && known_gauge_exists && known_histogram_exists)) { envoy::service::metrics::v2::StreamMetricsMessage request_msg; VERIFY_ASSERTION(metrics_service_request_->waitForGrpcMessage(*dispatcher_, request_msg)); - EXPECT_STREQ("POST", metrics_service_request_->headers().Method()->value().c_str()); - EXPECT_STREQ("/envoy.service.metrics.v2.MetricsService/StreamMetrics", - metrics_service_request_->headers().Path()->value().c_str()); - EXPECT_STREQ("application/grpc", - metrics_service_request_->headers().ContentType()->value().c_str()); + EXPECT_EQ("POST", metrics_service_request_->headers().Method()->value().getStringView()); + EXPECT_EQ("/envoy.service.metrics.v2.MetricsService/StreamMetrics", + metrics_service_request_->headers().Path()->value().getStringView()); + EXPECT_EQ("application/grpc", + metrics_service_request_->headers().ContentType()->value().getStringView()); EXPECT_TRUE(request_msg.envoy_metrics_size() > 0); const Protobuf::RepeatedPtrField<::io::prometheus::client::MetricFamily>& envoy_metrics = request_msg.envoy_metrics(); diff --git a/test/extensions/tracers/datadog/datadog_tracer_impl_test.cc b/test/extensions/tracers/datadog/datadog_tracer_impl_test.cc index 2ddc885a59290..224f09c62c557 100644 --- a/test/extensions/tracers/datadog/datadog_tracer_impl_test.cc +++ b/test/extensions/tracers/datadog/datadog_tracer_impl_test.cc @@ -133,8 +133,9 @@ TEST_F(DatadogDriverTest, FlushSpansTimer) { const Http::AsyncClient::RequestOptions&) -> Http::AsyncClient::Request* { callback = &callbacks; - EXPECT_STREQ("fake_cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/msgpack", message->headers().ContentType()->value().c_str()); + EXPECT_EQ("fake_cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/msgpack", + message->headers().ContentType()->value().getStringView()); return &request; })); diff --git a/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc b/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc index 75a34c1acf9a8..baf365a636241 100644 --- a/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc +++ b/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc @@ -168,10 +168,11 @@ TEST_F(LightStepDriverTest, FlushSeveralSpans) { const Http::AsyncClient::RequestOptions&) -> Http::AsyncClient::Request* { callback = &callbacks; - EXPECT_STREQ("/lightstep.collector.CollectorService/Report", - message->headers().Path()->value().c_str()); - EXPECT_STREQ("fake_cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/grpc", message->headers().ContentType()->value().c_str()); + EXPECT_EQ("/lightstep.collector.CollectorService/Report", + message->headers().Path()->value().getStringView()); + EXPECT_EQ("fake_cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/grpc", + message->headers().ContentType()->value().getStringView()); return &request; })); @@ -230,10 +231,11 @@ TEST_F(LightStepDriverTest, FlushOneFailure) { const Http::AsyncClient::RequestOptions&) -> Http::AsyncClient::Request* { callback = &callbacks; - EXPECT_STREQ("/lightstep.collector.CollectorService/Report", - message->headers().Path()->value().c_str()); - EXPECT_STREQ("fake_cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/grpc", message->headers().ContentType()->value().c_str()); + EXPECT_EQ("/lightstep.collector.CollectorService/Report", + message->headers().Path()->value().getStringView()); + EXPECT_EQ("fake_cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/grpc", + message->headers().ContentType()->value().getStringView()); return &request; })); @@ -274,10 +276,11 @@ TEST_F(LightStepDriverTest, FlushOneInvalidResponse) { const Http::AsyncClient::RequestOptions&) -> Http::AsyncClient::Request* { callback = &callbacks; - EXPECT_STREQ("/lightstep.collector.CollectorService/Report", - message->headers().Path()->value().c_str()); - EXPECT_STREQ("fake_cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/grpc", message->headers().ContentType()->value().c_str()); + EXPECT_EQ("/lightstep.collector.CollectorService/Report", + message->headers().Path()->value().getStringView()); + EXPECT_EQ("fake_cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/grpc", + message->headers().ContentType()->value().getStringView()); return &request; })); @@ -352,10 +355,11 @@ TEST_F(LightStepDriverTest, FlushOneSpanGrpcFailure) { const Http::AsyncClient::RequestOptions&) -> Http::AsyncClient::Request* { callback = &callbacks; - EXPECT_STREQ("/lightstep.collector.CollectorService/Report", - message->headers().Path()->value().c_str()); - EXPECT_STREQ("fake_cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/grpc", message->headers().ContentType()->value().c_str()); + EXPECT_EQ("/lightstep.collector.CollectorService/Report", + message->headers().Path()->value().getStringView()); + EXPECT_EQ("fake_cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/grpc", + message->headers().ContentType()->value().getStringView()); return &request; })); @@ -429,7 +433,7 @@ TEST_F(LightStepDriverTest, SerializeAndDeserializeContext) { {Tracing::Reason::Sampling, true}); EXPECT_EQ(1U, stats_.counter("tracing.opentracing.span_context_extraction_error").value()); - std::string injected_ctx = request_headers_.OtSpanContext()->value().c_str(); + std::string injected_ctx(request_headers_.OtSpanContext()->value().getStringView()); EXPECT_FALSE(injected_ctx.empty()); // Supply empty context. @@ -440,7 +444,7 @@ TEST_F(LightStepDriverTest, SerializeAndDeserializeContext) { EXPECT_EQ(nullptr, request_headers_.OtSpanContext()); span->injectContext(request_headers_); - injected_ctx = request_headers_.OtSpanContext()->value().c_str(); + injected_ctx = std::string(request_headers_.OtSpanContext()->value().getStringView()); EXPECT_FALSE(injected_ctx.empty()); // Context can be parsed fine. @@ -454,7 +458,7 @@ TEST_F(LightStepDriverTest, SerializeAndDeserializeContext) { config_, request_headers_, operation_name_, start_time_, {Tracing::Reason::Sampling, true}); request_headers_.removeOtSpanContext(); span_with_parent->injectContext(request_headers_); - injected_ctx = request_headers_.OtSpanContext()->value().c_str(); + injected_ctx = std::string(request_headers_.OtSpanContext()->value().getStringView()); EXPECT_FALSE(injected_ctx.empty()); } } @@ -476,8 +480,10 @@ TEST_F(LightStepDriverTest, SpawnChild) { childViaHeaders->injectContext(base1); childViaSpawn->injectContext(base2); - std::string base1_context = Base64::decode(base1.OtSpanContext()->value().c_str()); - std::string base2_context = Base64::decode(base2.OtSpanContext()->value().c_str()); + std::string base1_context = + Base64::decode(std::string(base1.OtSpanContext()->value().getStringView())); + std::string base2_context = + Base64::decode(std::string(base2.OtSpanContext()->value().getStringView())); EXPECT_FALSE(base1_context.empty()); EXPECT_FALSE(base2_context.empty()); diff --git a/test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc b/test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc index e538860b509f1..c918f38172073 100644 --- a/test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc +++ b/test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc @@ -145,9 +145,10 @@ TEST_F(ZipkinDriverTest, FlushSeveralSpans) { const Http::AsyncClient::RequestOptions&) -> Http::AsyncClient::Request* { callback = &callbacks; - EXPECT_STREQ("/api/v1/spans", message->headers().Path()->value().c_str()); - EXPECT_STREQ("fake_cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/json", message->headers().ContentType()->value().c_str()); + EXPECT_EQ("/api/v1/spans", message->headers().Path()->value().getStringView()); + EXPECT_EQ("fake_cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/json", + message->headers().ContentType()->value().getStringView()); return &request; })); @@ -195,9 +196,10 @@ TEST_F(ZipkinDriverTest, FlushOneSpanReportFailure) { const Http::AsyncClient::RequestOptions&) -> Http::AsyncClient::Request* { callback = &callbacks; - EXPECT_STREQ("/api/v1/spans", message->headers().Path()->value().c_str()); - EXPECT_STREQ("fake_cluster", message->headers().Host()->value().c_str()); - EXPECT_STREQ("application/json", message->headers().ContentType()->value().c_str()); + EXPECT_EQ("/api/v1/spans", message->headers().Path()->value().getStringView()); + EXPECT_EQ("fake_cluster", message->headers().Host()->value().getStringView()); + EXPECT_EQ("application/json", + message->headers().ContentType()->value().getStringView()); return &request; })); @@ -633,9 +635,9 @@ TEST_F(ZipkinDriverTest, DuplicatedHeader) { Tracing::SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, {Tracing::Reason::Sampling, false}); - typedef std::function DupCallback; - DupCallback dup_callback = [](const std::string& key) -> bool { - static std::unordered_map dup; + typedef std::function DupCallback; + DupCallback dup_callback = [](absl::string_view key) -> bool { + static absl::flat_hash_map dup; if (dup.find(key) == dup.end()) { dup[key] = true; return false; @@ -647,7 +649,7 @@ TEST_F(ZipkinDriverTest, DuplicatedHeader) { span->injectContext(request_headers_); request_headers_.iterate( [](const Http::HeaderEntry& header, void* cb) -> Http::HeaderMap::Iterate { - EXPECT_FALSE(static_cast(cb)->operator()(header.key().c_str())); + EXPECT_FALSE(static_cast(cb)->operator()(header.key().getStringView())); return Http::HeaderMap::Iterate::Continue; }, &dup_callback); diff --git a/test/extensions/transport_sockets/tls/integration/ssl_integration_test.cc b/test/extensions/transport_sockets/tls/integration/ssl_integration_test.cc index e95899d2cfdb1..f15651ecfe026 100644 --- a/test/extensions/transport_sockets/tls/integration/ssl_integration_test.cc +++ b/test/extensions/transport_sockets/tls/integration/ssl_integration_test.cc @@ -170,7 +170,7 @@ TEST_P(SslIntegrationTest, AdminCertEndpoint) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("admin"), "GET", "/certs", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } // Validate certificate selection across different certificate types and client TLS versions. @@ -410,7 +410,7 @@ TEST_P(SslTapIntegrationTest, TwoRequestsWithBinaryProto) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_EQ(128, upstream_request_->bodyLength()); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(256, response->body().size()); checkStats(); envoy::api::v2::core::Address expected_local_address; @@ -448,7 +448,7 @@ TEST_P(SslTapIntegrationTest, TwoRequestsWithBinaryProto) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_EQ(128, upstream_request_->bodyLength()); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(256, response->body().size()); checkStats(); codec_client_->close(); diff --git a/test/fuzz/utility.h b/test/fuzz/utility.h index afa0e24415bb1..28d6b73f96a90 100644 --- a/test/fuzz/utility.h +++ b/test/fuzz/utility.h @@ -42,8 +42,8 @@ inline test::fuzz::Headers toHeaders(const Http::HeaderMap& headers) { headers.iterate( [](const Http::HeaderEntry& header, void* ctxt) -> Http::HeaderMap::Iterate { auto* fuzz_header = static_cast(ctxt)->add_headers(); - fuzz_header->set_key(header.key().c_str()); - fuzz_header->set_value(header.value().c_str()); + fuzz_header->set_key(std::string(header.key().getStringView())); + fuzz_header->set_value(std::string(header.value().getStringView())); return Http::HeaderMap::Iterate::Continue; }, &fuzz_headers); diff --git a/test/integration/cds_integration_test.cc b/test/integration/cds_integration_test.cc index f70fc5d175834..9ebce9094c624 100644 --- a/test/integration/cds_integration_test.cc +++ b/test/integration/cds_integration_test.cc @@ -149,7 +149,7 @@ TEST_P(CdsIntegrationTest, CdsClusterUpDownUp) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("http"), "GET", "/cluster1", "", downstream_protocol_, version_, "foo.com"); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); cleanupUpstreamAndDownstream(); codec_client_->waitForDisconnect(); @@ -261,7 +261,7 @@ TEST_P(DeltaCdsIntegrationTest, CdsClusterUpDownUp) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("http"), "GET", "/cluster1", "", downstream_protocol_, version_, "foo.com"); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); cleanupUpstreamAndDownstream(); codec_client_->waitForDisconnect(); diff --git a/test/integration/hds_integration_test.cc b/test/integration/hds_integration_test.cc index dd8fe59451747..b8acab50c4424 100644 --- a/test/integration/hds_integration_test.cc +++ b/test/integration/hds_integration_test.cc @@ -79,19 +79,19 @@ class HdsIntegrationTest : public testing::TestWithParamwaitForEndStream(*dispatcher_)); host_upstream_->set_allow_unexpected_disconnects(true); - EXPECT_STREQ(host_stream_->headers().Path()->value().c_str(), "/healthcheck"); - EXPECT_STREQ(host_stream_->headers().Method()->value().c_str(), "GET"); - EXPECT_STREQ(host_stream_->headers().Host()->value().c_str(), "anna"); + EXPECT_EQ(host_stream_->headers().Path()->value().getStringView(), "/healthcheck"); + EXPECT_EQ(host_stream_->headers().Method()->value().getStringView(), "GET"); + EXPECT_EQ(host_stream_->headers().Host()->value().getStringView(), "anna"); - if (cluster2 != "") { + if (!cluster2.empty()) { ASSERT_TRUE(host2_upstream_->waitForHttpConnection(*dispatcher_, host2_fake_connection_)); ASSERT_TRUE(host2_fake_connection_->waitForNewStream(*dispatcher_, host2_stream_)); ASSERT_TRUE(host2_stream_->waitForEndStream(*dispatcher_)); host2_upstream_->set_allow_unexpected_disconnects(true); - EXPECT_STREQ(host2_stream_->headers().Path()->value().c_str(), "/healthcheck"); - EXPECT_STREQ(host2_stream_->headers().Method()->value().c_str(), "GET"); - EXPECT_STREQ(host2_stream_->headers().Host()->value().c_str(), cluster2.c_str()); + EXPECT_EQ(host2_stream_->headers().Path()->value().getStringView(), "/healthcheck"); + EXPECT_EQ(host2_stream_->headers().Method()->value().getStringView(), "GET"); + EXPECT_EQ(host2_stream_->headers().Host()->value().getStringView(), cluster2); } } diff --git a/test/integration/http2_integration_test.cc b/test/integration/http2_integration_test.cc index c8275e762b8c2..44da6c4eab022 100644 --- a/test/integration/http2_integration_test.cc +++ b/test/integration/http2_integration_test.cc @@ -422,10 +422,10 @@ TEST_P(Http2IntegrationTest, GrpcRouterNotFound) { lookupPort("http"), "POST", "/service/notfound", "", downstream_protocol_, version_, "host", Http::Headers::get().ContentTypeValues.Grpc); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(Http::Headers::get().ContentTypeValues.Grpc, - response->headers().ContentType()->value().c_str()); - EXPECT_STREQ("12", response->headers().GrpcStatus()->value().c_str()); + response->headers().ContentType()->value().getStringView()); + EXPECT_EQ("12", response->headers().GrpcStatus()->value().getStringView()); } TEST_P(Http2IntegrationTest, GrpcRetry) { testGrpcRetry(); } @@ -477,7 +477,7 @@ TEST_P(Http2IntegrationTest, GoAway) { codec_client_->close(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } TEST_P(Http2IntegrationTest, Trailers) { testTrailers(1024, 2048); } @@ -511,9 +511,9 @@ TEST_P(Http2IntegrationTest, GrpcRequestTimeout) { {"content-type", "application/grpc"}}); response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_NE(response->headers().GrpcStatus(), nullptr); - EXPECT_STREQ("14", response->headers().GrpcStatus()->value().c_str()); // Service Unavailable + EXPECT_EQ("14", response->headers().GrpcStatus()->value().getStringView()); // Service Unavailable EXPECT_LT(0, test_server_->counter("cluster.cluster_0.upstream_rq_timeout")->value()); } @@ -580,7 +580,7 @@ TEST_P(Http2IntegrationTest, IdleTimeoutWithSimultaneousRequests) { EXPECT_TRUE(upstream_request2->complete()); EXPECT_EQ(request2_bytes, upstream_request2->bodyLength()); EXPECT_TRUE(response2->complete()); - EXPECT_STREQ("200", response2->headers().Status()->value().c_str()); + EXPECT_EQ("200", response2->headers().Status()->value().getStringView()); EXPECT_EQ(request2_bytes, response2->body().size()); // Validate that idle time is not kicked in. @@ -594,7 +594,7 @@ TEST_P(Http2IntegrationTest, IdleTimeoutWithSimultaneousRequests) { EXPECT_TRUE(upstream_request1->complete()); EXPECT_EQ(request1_bytes, upstream_request1->bodyLength()); EXPECT_TRUE(response1->complete()); - EXPECT_STREQ("200", response1->headers().Status()->value().c_str()); + EXPECT_EQ("200", response1->headers().Status()->value().getStringView()); EXPECT_EQ(request1_bytes, response1->body().size()); // Do not send any requests and validate idle timeout kicks in after both the requests are done. @@ -700,7 +700,7 @@ void Http2IntegrationTest::simultaneousRequest(int32_t request1_bytes, int32_t r EXPECT_TRUE(upstream_request2->complete()); EXPECT_EQ(request2_bytes, upstream_request2->bodyLength()); EXPECT_TRUE(response2->complete()); - EXPECT_STREQ("200", response2->headers().Status()->value().c_str()); + EXPECT_EQ("200", response2->headers().Status()->value().getStringView()); EXPECT_EQ(request2_bytes, response2->body().size()); // Respond to request 1 @@ -710,7 +710,7 @@ void Http2IntegrationTest::simultaneousRequest(int32_t request1_bytes, int32_t r EXPECT_TRUE(upstream_request1->complete()); EXPECT_EQ(request1_bytes, upstream_request1->bodyLength()); EXPECT_TRUE(response1->complete()); - EXPECT_STREQ("200", response1->headers().Status()->value().c_str()); + EXPECT_EQ("200", response1->headers().Status()->value().getStringView()); EXPECT_EQ(request2_bytes, response1->body().size()); // Cleanup both downstream and upstream @@ -897,10 +897,10 @@ TEST_P(Http2RingHashIntegrationTest, CookieRoutingNoCookieNoTtl) { {":scheme", "http"}, {":authority", "host"}}, [&](IntegrationStreamDecoder& response) { - EXPECT_STREQ("200", response.headers().Status()->value().c_str()); + EXPECT_EQ("200", response.headers().Status()->value().getStringView()); EXPECT_TRUE(response.headers().get(Http::Headers::get().SetCookie) == nullptr); - served_by.insert( - response.headers().get(Http::LowerCaseString("x-served-by"))->value().c_str()); + served_by.insert(std::string( + response.headers().get(Http::LowerCaseString("x-served-by"))->value().getStringView())); }); EXPECT_EQ(served_by.size(), num_upstreams_); } @@ -927,8 +927,9 @@ TEST_P(Http2RingHashIntegrationTest, CookieRoutingNoCookieWithNonzeroTtlSet) { {":scheme", "http"}, {":authority", "host"}}, [&](IntegrationStreamDecoder& response) { - EXPECT_STREQ("200", response.headers().Status()->value().c_str()); - std::string value = response.headers().get(Http::Headers::get().SetCookie)->value().c_str(); + EXPECT_EQ("200", response.headers().Status()->value().getStringView()); + std::string value( + response.headers().get(Http::Headers::get().SetCookie)->value().getStringView()); set_cookies.insert(value); EXPECT_THAT(value, MatchesRegex("foo=.*; Max-Age=15; HttpOnly")); }); @@ -957,8 +958,9 @@ TEST_P(Http2RingHashIntegrationTest, CookieRoutingNoCookieWithZeroTtlSet) { {":scheme", "http"}, {":authority", "host"}}, [&](IntegrationStreamDecoder& response) { - EXPECT_STREQ("200", response.headers().Status()->value().c_str()); - std::string value = response.headers().get(Http::Headers::get().SetCookie)->value().c_str(); + EXPECT_EQ("200", response.headers().Status()->value().getStringView()); + std::string value( + response.headers().get(Http::Headers::get().SetCookie)->value().getStringView()); set_cookies.insert(value); EXPECT_THAT(value, MatchesRegex("^foo=.*$")); }); @@ -987,10 +989,10 @@ TEST_P(Http2RingHashIntegrationTest, CookieRoutingWithCookieNoTtl) { {":scheme", "http"}, {":authority", "host"}}, [&](IntegrationStreamDecoder& response) { - EXPECT_STREQ("200", response.headers().Status()->value().c_str()); + EXPECT_EQ("200", response.headers().Status()->value().getStringView()); EXPECT_TRUE(response.headers().get(Http::Headers::get().SetCookie) == nullptr); - served_by.insert( - response.headers().get(Http::LowerCaseString("x-served-by"))->value().c_str()); + served_by.insert(std::string( + response.headers().get(Http::LowerCaseString("x-served-by"))->value().getStringView())); }); EXPECT_EQ(served_by.size(), 1); } @@ -1018,10 +1020,10 @@ TEST_P(Http2RingHashIntegrationTest, CookieRoutingWithCookieWithTtlSet) { {":scheme", "http"}, {":authority", "host"}}, [&](IntegrationStreamDecoder& response) { - EXPECT_STREQ("200", response.headers().Status()->value().c_str()); + EXPECT_EQ("200", response.headers().Status()->value().getStringView()); EXPECT_TRUE(response.headers().get(Http::Headers::get().SetCookie) == nullptr); - served_by.insert( - response.headers().get(Http::LowerCaseString("x-served-by"))->value().c_str()); + served_by.insert(std::string( + response.headers().get(Http::LowerCaseString("x-served-by"))->value().getStringView())); }); EXPECT_EQ(served_by.size(), 1); } diff --git a/test/integration/http2_upstream_integration_test.cc b/test/integration/http2_upstream_integration_test.cc index a872a3fc3f23b..0dd3ab6a66463 100644 --- a/test/integration/http2_upstream_integration_test.cc +++ b/test/integration/http2_upstream_integration_test.cc @@ -175,7 +175,7 @@ void Http2UpstreamIntegrationTest::simultaneousRequest(uint32_t request1_bytes, EXPECT_TRUE(upstream_request2->complete()); EXPECT_EQ(request2_bytes, upstream_request2->bodyLength()); EXPECT_TRUE(response2->complete()); - EXPECT_STREQ("200", response2->headers().Status()->value().c_str()); + EXPECT_EQ("200", response2->headers().Status()->value().getStringView()); EXPECT_EQ(response2_bytes, response2->body().size()); // Respond to request 1 @@ -185,7 +185,7 @@ void Http2UpstreamIntegrationTest::simultaneousRequest(uint32_t request1_bytes, EXPECT_TRUE(upstream_request1->complete()); EXPECT_EQ(request1_bytes, upstream_request1->bodyLength()); EXPECT_TRUE(response1->complete()); - EXPECT_STREQ("200", response1->headers().Status()->value().c_str()); + EXPECT_EQ("200", response1->headers().Status()->value().getStringView()); EXPECT_EQ(response1_bytes, response1->body().size()); } @@ -230,11 +230,11 @@ void Http2UpstreamIntegrationTest::manySimultaneousRequests(uint32_t request_byt responses[i]->waitForEndStream(); if (i % 2 != 0) { EXPECT_TRUE(responses[i]->complete()); - EXPECT_STREQ("200", responses[i]->headers().Status()->value().c_str()); + EXPECT_EQ("200", responses[i]->headers().Status()->value().getStringView()); EXPECT_EQ(response_bytes[i], responses[i]->body().length()); } else { // Upstream stream reset. - EXPECT_STREQ("503", responses[i]->headers().Status()->value().c_str()); + EXPECT_EQ("503", responses[i]->headers().Status()->value().getStringView()); } } } diff --git a/test/integration/http_integration.cc b/test/integration/http_integration.cc index 4c9bb7b550946..d6cc94c337e23 100644 --- a/test/integration/http_integration.cc +++ b/test/integration/http_integration.cc @@ -340,7 +340,7 @@ void HttpIntegrationTest::checkSimpleRequestSuccess(uint64_t expected_request_si EXPECT_EQ(expected_request_size, upstream_request_->bodyLength()); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(expected_response_size, response->body().size()); } @@ -394,7 +394,7 @@ void HttpIntegrationTest::testRouterNotFound() { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("http"), "GET", "/notfound", "", downstream_protocol_, version_); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("404", response->headers().Status()->value().c_str()); + EXPECT_EQ("404", response->headers().Status()->value().getStringView()); } // Change the default route to be restrictive, and send a POST to an alternate route. @@ -405,7 +405,7 @@ void HttpIntegrationTest::testRouterNotFoundWithBody() { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("http"), "POST", "/notfound", "foo", downstream_protocol_, version_); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("404", response->headers().Status()->value().c_str()); + EXPECT_EQ("404", response->headers().Status()->value().getStringView()); } void HttpIntegrationTest::testRouterUpstreamDisconnectBeforeRequestComplete() { @@ -433,7 +433,7 @@ void HttpIntegrationTest::testRouterUpstreamDisconnectBeforeRequestComplete() { EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); EXPECT_EQ("upstream connect error or disconnect/reset before headers. reset reason: connection " "termination", response->body()); @@ -461,7 +461,7 @@ void HttpIntegrationTest::testRouterUpstreamDisconnectBeforeResponseComplete( EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_FALSE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(0U, response->body().size()); } @@ -523,7 +523,7 @@ void HttpIntegrationTest::testRouterDownstreamDisconnectBeforeResponseComplete( EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_FALSE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(512U, response->body().size()); } @@ -557,7 +557,7 @@ void HttpIntegrationTest::testRouterUpstreamResponseBeforeRequestComplete() { EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(512U, response->body().size()); } @@ -590,7 +590,7 @@ void HttpIntegrationTest::testRetry() { EXPECT_EQ(1024U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(512U, response->body().size()); } @@ -614,7 +614,10 @@ void HttpIntegrationTest::testRetryAttemptCountHeader() { waitForNextUpstreamRequest(); upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "503"}}, false); - EXPECT_EQ(atoi(upstream_request_->headers().EnvoyAttemptCount()->value().c_str()), 1); + EXPECT_EQ( + atoi(std::string(upstream_request_->headers().EnvoyAttemptCount()->value().getStringView()) + .c_str()), + 1); if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP1) { ASSERT_TRUE(fake_upstream_connection_->waitForDisconnect()); @@ -623,7 +626,10 @@ void HttpIntegrationTest::testRetryAttemptCountHeader() { ASSERT_TRUE(upstream_request_->waitForReset()); } waitForNextUpstreamRequest(); - EXPECT_EQ(atoi(upstream_request_->headers().EnvoyAttemptCount()->value().c_str()), 2); + EXPECT_EQ( + atoi(std::string(upstream_request_->headers().EnvoyAttemptCount()->value().getStringView()) + .c_str()), + 2); upstream_request_->encodeHeaders(default_response_headers_, false); upstream_request_->encodeData(512, true); @@ -632,7 +638,7 @@ void HttpIntegrationTest::testRetryAttemptCountHeader() { EXPECT_EQ(1024U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(512U, response->body().size()); } @@ -673,7 +679,7 @@ void HttpIntegrationTest::testGrpcRetry() { EXPECT_EQ(1024U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(512U, response->body().size()); if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP2) { EXPECT_THAT(*response->trailers(), HeaderMapEqualRef(&response_trailers)); @@ -706,8 +712,8 @@ void HttpIntegrationTest::testEnvoyHandling100Continue(bool additional_continue_ if (via.empty()) { EXPECT_EQ(nullptr, upstream_request_->headers().get(Http::Headers::get().Via)); } else { - EXPECT_STREQ(via.c_str(), - upstream_request_->headers().get(Http::Headers::get().Via)->value().c_str()); + EXPECT_EQ(via, + upstream_request_->headers().get(Http::Headers::get().Via)->value().getStringView()); } if (additional_continue_from_upstream) { @@ -721,13 +727,13 @@ void HttpIntegrationTest::testEnvoyHandling100Continue(bool additional_continue_ response->waitForEndStream(); ASSERT_TRUE(response->complete()); ASSERT(response->continue_headers() != nullptr); - EXPECT_STREQ("100", response->continue_headers()->Status()->value().c_str()); + EXPECT_EQ("100", response->continue_headers()->Status()->value().getStringView()); EXPECT_EQ(nullptr, response->continue_headers()->Via()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); if (via.empty()) { EXPECT_EQ(nullptr, response->headers().Via()); } else { - EXPECT_STREQ(via.c_str(), response->headers().Via()->value().c_str()); + EXPECT_EQ(via.c_str(), response->headers().Via()->value().getStringView()); } } @@ -788,9 +794,9 @@ void HttpIntegrationTest::testEnvoyProxying100Continue(bool continue_before_upst response->waitForEndStream(); EXPECT_TRUE(response->complete()); ASSERT(response->continue_headers() != nullptr); - EXPECT_STREQ("100", response->continue_headers()->Status()->value().c_str()); + EXPECT_EQ("100", response->continue_headers()->Status()->value().getStringView()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } void HttpIntegrationTest::testTwoRequests(bool network_backup) { @@ -822,7 +828,7 @@ void HttpIntegrationTest::testTwoRequests(bool network_backup) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_EQ(1024U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(512U, response->body().size()); // Request 2. @@ -835,7 +841,7 @@ void HttpIntegrationTest::testTwoRequests(bool network_backup) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_EQ(512U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(1024U, response->body().size()); } @@ -864,7 +870,7 @@ void HttpIntegrationTest::testLargeRequestHeaders(uint32_t size, uint32_t max_si if (downstream_protocol_ == Http::CodecClient::Type::HTTP1) { codec_client_->waitForDisconnect(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("431", response->headers().Status()->value().c_str()); + EXPECT_EQ("431", response->headers().Status()->value().getStringView()); } else { response->waitForReset(); codec_client_->close(); @@ -872,7 +878,7 @@ void HttpIntegrationTest::testLargeRequestHeaders(uint32_t size, uint32_t max_si } else { auto response = sendRequestAndWaitForResponse(big_headers, 0, default_response_headers_, 0); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } } @@ -914,7 +920,7 @@ void HttpIntegrationTest::testDownstreamResetBeforeResponseComplete() { EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_FALSE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(512U, response->body().size()); } @@ -946,7 +952,7 @@ void HttpIntegrationTest::testTrailers(uint64_t request_size, uint64_t response_ } EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(response_size, response->body().size()); if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP2) { EXPECT_THAT(*response->trailers(), HeaderMapEqualRef(&response_trailers)); diff --git a/test/integration/idle_timeout_integration_test.cc b/test/integration/idle_timeout_integration_test.cc index edaa2e363cc83..f23dec2b295a6 100644 --- a/test/integration/idle_timeout_integration_test.cc +++ b/test/integration/idle_timeout_integration_test.cc @@ -170,7 +170,7 @@ TEST_P(IdleTimeoutIntegrationTest, PerStreamIdleTimeoutAfterDownstreamHeaders) { EXPECT_FALSE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("408", response->headers().Status()->value().c_str()); + EXPECT_EQ("408", response->headers().Status()->value().getStringView()); EXPECT_EQ("stream timeout", response->body()); } @@ -183,9 +183,9 @@ TEST_P(IdleTimeoutIntegrationTest, PerStreamIdleTimeoutHeadRequestAfterDownstrea EXPECT_FALSE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("408", response->headers().Status()->value().c_str()); - EXPECT_STREQ(fmt::format("{}", strlen("stream timeout")).c_str(), - response->headers().ContentLength()->value().c_str()); + EXPECT_EQ("408", response->headers().Status()->value().getStringView()); + EXPECT_EQ(fmt::format("{}", strlen("stream timeout")), + response->headers().ContentLength()->value().getStringView()); EXPECT_EQ("", response->body()); } @@ -200,7 +200,7 @@ TEST_P(IdleTimeoutIntegrationTest, GlobalPerStreamIdleTimeoutAfterDownstreamHead EXPECT_FALSE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("408", response->headers().Status()->value().c_str()); + EXPECT_EQ("408", response->headers().Status()->value().getStringView()); EXPECT_EQ("stream timeout", response->body()); } @@ -217,7 +217,7 @@ TEST_P(IdleTimeoutIntegrationTest, PerStreamIdleTimeoutAfterDownstreamHeadersAnd EXPECT_FALSE(upstream_request_->complete()); EXPECT_EQ(1U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("408", response->headers().Status()->value().c_str()); + EXPECT_EQ("408", response->headers().Status()->value().getStringView()); EXPECT_EQ("stream timeout", response->body()); } @@ -233,7 +233,7 @@ TEST_P(IdleTimeoutIntegrationTest, PerStreamIdleTimeoutAfterUpstreamHeaders) { EXPECT_FALSE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_FALSE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ("", response->body()); } @@ -266,7 +266,7 @@ TEST_P(IdleTimeoutIntegrationTest, PerStreamIdleTimeoutAfterBidiData) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_EQ(1U, upstream_request_->bodyLength()); EXPECT_FALSE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ("aa", response->body()); } @@ -296,7 +296,7 @@ TEST_P(IdleTimeoutIntegrationTest, RequestTimeoutTriggersOnBodilessPost) { EXPECT_FALSE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("408", response->headers().Status()->value().c_str()); + EXPECT_EQ("408", response->headers().Status()->value().getStringView()); EXPECT_EQ("request timeout", response->body()); } @@ -312,7 +312,7 @@ TEST_P(IdleTimeoutIntegrationTest, RequestTimeoutUnconfiguredDoesNotTriggerOnBod EXPECT_FALSE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("408", response->headers().Status()->value().c_str()); + EXPECT_EQ("408", response->headers().Status()->value().getStringView()); EXPECT_NE("request timeout", response->body()); } @@ -370,7 +370,7 @@ TEST_P(IdleTimeoutIntegrationTest, RequestTimeoutIsNotDisarmedByEncode100Continu EXPECT_FALSE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("408", response->headers().Status()->value().c_str()); + EXPECT_EQ("408", response->headers().Status()->value().getStringView()); EXPECT_EQ("request timeout", response->body()); } diff --git a/test/integration/integration_admin_test.cc b/test/integration/integration_admin_test.cc index 2ce9f3b73b347..688d6fcd8be70 100644 --- a/test/integration/integration_admin_test.cc +++ b/test/integration/integration_admin_test.cc @@ -28,27 +28,27 @@ TEST_P(IntegrationAdminTest, HealthCheck) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("http"), "POST", "/healthcheck", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "POST", "/healthcheck/fail", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); response = IntegrationUtil::makeSingleRequest(lookupPort("http"), "GET", "/healthcheck", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "POST", "/healthcheck/ok", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); response = IntegrationUtil::makeSingleRequest(lookupPort("http"), "GET", "/healthcheck", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } TEST_P(IntegrationAdminTest, HealthCheckWithBufferFilter) { @@ -58,7 +58,7 @@ TEST_P(IntegrationAdminTest, HealthCheckWithBufferFilter) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("http"), "GET", "/healthcheck", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } TEST_P(IntegrationAdminTest, AdminLogging) { @@ -67,25 +67,25 @@ TEST_P(IntegrationAdminTest, AdminLogging) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("admin"), "POST", "/logging", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); // Bad level response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "POST", "/logging?level=blah", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("404", response->headers().Status()->value().c_str()); + EXPECT_EQ("404", response->headers().Status()->value().getStringView()); // Bad logger response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "POST", "/logging?blah=info", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("404", response->headers().Status()->value().c_str()); + EXPECT_EQ("404", response->headers().Status()->value().getStringView()); // This is going to stomp over custom log levels that are set on the command line. response = IntegrationUtil::makeSingleRequest( lookupPort("admin"), "POST", "/logging?level=warning", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); for (const Logger::Logger& logger : Logger::Registry::loggers()) { EXPECT_EQ("warning", logger.levelString()); } @@ -93,7 +93,7 @@ TEST_P(IntegrationAdminTest, AdminLogging) { response = IntegrationUtil::makeSingleRequest( lookupPort("admin"), "POST", "/logging?assert=trace", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(spdlog::level::trace, Logger::Registry::getLog(Logger::Id::assert).level()); spdlog::string_view_t level_name = spdlog::level::level_string_views[default_log_level_]; @@ -101,7 +101,7 @@ TEST_P(IntegrationAdminTest, AdminLogging) { fmt::format("/logging?level={}", level_name), "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); for (const Logger::Logger& logger : Logger::Registry::loggers()) { EXPECT_EQ(level_name, logger.levelString()); } @@ -109,12 +109,12 @@ TEST_P(IntegrationAdminTest, AdminLogging) { namespace { -const char* ContentType(const BufferingStreamDecoderPtr& response) { +std::string ContentType(const BufferingStreamDecoderPtr& response) { const Http::HeaderEntry* entry = response->headers().ContentType(); if (entry == nullptr) { return "(null)"; } - return entry->value().c_str(); + return std::string(entry->value().getStringView()); } } // namespace @@ -125,84 +125,84 @@ TEST_P(IntegrationAdminTest, Admin) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("admin"), "GET", "/notfound", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("404", response->headers().Status()->value().c_str()); - EXPECT_STREQ("text/plain; charset=UTF-8", ContentType(response)); + EXPECT_EQ("404", response->headers().Status()->value().getStringView()); + EXPECT_EQ("text/plain; charset=UTF-8", ContentType(response)); EXPECT_NE(std::string::npos, response->body().find("invalid path. admin commands are:")) << response->body(); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/help", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("text/plain; charset=UTF-8", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("text/plain; charset=UTF-8", ContentType(response)); EXPECT_NE(std::string::npos, response->body().find("admin commands are:")) << response->body(); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("text/html; charset=UTF-8", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("text/html; charset=UTF-8", ContentType(response)); EXPECT_NE(std::string::npos, response->body().find("Envoy Admin")) << response->body(); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/server_info", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("application/json", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("application/json", ContentType(response)); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/stats", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("text/plain; charset=UTF-8", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("text/plain; charset=UTF-8", ContentType(response)); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/stats?usedonly", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("text/plain; charset=UTF-8", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("text/plain; charset=UTF-8", ContentType(response)); // Testing a filter with no matches response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/stats?filter=foo", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("text/plain; charset=UTF-8", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("text/plain; charset=UTF-8", ContentType(response)); // Testing a filter with matches response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/stats?filter=server", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("text/plain; charset=UTF-8", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("text/plain; charset=UTF-8", ContentType(response)); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/stats?filter=server&usedonly", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("text/plain; charset=UTF-8", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("text/plain; charset=UTF-8", ContentType(response)); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/stats?format=json&usedonly", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("application/json", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("application/json", ContentType(response)); validateStatsJson(response->body(), 0); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/stats?format=blah", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("404", response->headers().Status()->value().c_str()); - EXPECT_STREQ("text/plain; charset=UTF-8", ContentType(response)); + EXPECT_EQ("404", response->headers().Status()->value().getStringView()); + EXPECT_EQ("text/plain; charset=UTF-8", ContentType(response)); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/stats?format=json", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("application/json", ContentType(response)); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("application/json", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); validateStatsJson(response->body(), 1); // Filtering stats by a regex with one match should return just that match. @@ -210,8 +210,8 @@ TEST_P(IntegrationAdminTest, Admin) { "/stats?format=json&filter=^server\\.version$", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("application/json", ContentType(response)); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("application/json", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); validateStatsJson(response->body(), 0); EXPECT_THAT(response->body(), testing::Eq("{\"stats\":[{\"name\":\"server.version\",\"value\":0}]}")); @@ -221,8 +221,8 @@ TEST_P(IntegrationAdminTest, Admin) { "/stats?format=json&filter=server\\.version", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("application/json", ContentType(response)); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("application/json", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); validateStatsJson(response->body(), 0); EXPECT_THAT(response->body(), testing::Eq("{\"stats\":[{\"name\":\"server.version\",\"value\":0}]}")); @@ -233,15 +233,15 @@ TEST_P(IntegrationAdminTest, Admin) { "/stats?format=json&filter=not_intended_to_appear", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("application/json", ContentType(response)); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("application/json", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); validateStatsJson(response->body(), 0); EXPECT_THAT(response->body(), testing::Eq("{\"stats\":[]}")); response = IntegrationUtil::makeSingleRequest( lookupPort("admin"), "GET", "/stats?format=prometheus", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_THAT(response->body(), testing::HasSubstr( "envoy_http_downstream_rq_xx{envoy_response_code_class=\"4\",envoy_http_conn_" @@ -260,7 +260,7 @@ TEST_P(IntegrationAdminTest, Admin) { response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/stats/prometheus", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_THAT(response->body(), testing::HasSubstr( "envoy_http_downstream_rq_xx{envoy_response_code_class=\"4\",envoy_http_conn_" @@ -279,51 +279,51 @@ TEST_P(IntegrationAdminTest, Admin) { response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/clusters", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_THAT(response->body(), testing::HasSubstr("added_via_api")); - EXPECT_STREQ("text/plain; charset=UTF-8", ContentType(response)); + EXPECT_EQ("text/plain; charset=UTF-8", ContentType(response)); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "POST", "/cpuprofiler", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("400", response->headers().Status()->value().c_str()); - EXPECT_STREQ("text/plain; charset=UTF-8", ContentType(response)); + EXPECT_EQ("400", response->headers().Status()->value().getStringView()); + EXPECT_EQ("text/plain; charset=UTF-8", ContentType(response)); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/hot_restart_version", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("text/plain; charset=UTF-8", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("text/plain; charset=UTF-8", ContentType(response)); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "POST", "/reset_counters", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("text/plain; charset=UTF-8", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("text/plain; charset=UTF-8", ContentType(response)); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/certs", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("application/json", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("application/json", ContentType(response)); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/runtime", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("application/json", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("application/json", ContentType(response)); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/runtime?format=json", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("application/json", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("application/json", ContentType(response)); response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/listeners", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("application/json", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("application/json", ContentType(response)); Json::ObjectSharedPtr json = Json::Factory::loadFromString(response->body()); std::vector listener_info = json->asObjectArray(); @@ -339,8 +339,8 @@ TEST_P(IntegrationAdminTest, Admin) { response = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/config_dump", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("application/json", ContentType(response)); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("application/json", ContentType(response)); json = Json::Factory::loadFromString(response->body()); size_t index = 0; const std::string expected_types[] = { @@ -386,7 +386,7 @@ TEST_P(IntegrationAdminTest, AdminOnDestroyCallbacks) { lookupPort("admin"), "GET", "/foo/bar", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); // Check that the added callback was invoked. EXPECT_EQ(test, false); @@ -405,15 +405,15 @@ TEST_P(IntegrationAdminTest, AdminCpuProfilerStart) { lookupPort("admin"), "POST", "/cpuprofiler?enable=y", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); #ifdef PROFILER_AVAILABLE - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); #else - EXPECT_STREQ("500", response->headers().Status()->value().c_str()); + EXPECT_EQ("500", response->headers().Status()->value().getStringView()); #endif response = IntegrationUtil::makeSingleRequest( lookupPort("admin"), "POST", "/cpuprofiler?enable=n", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } class IntegrationAdminIpv4Ipv6Test : public testing::Test, public HttpIntegrationTest { @@ -442,7 +442,7 @@ TEST_F(IntegrationAdminIpv4Ipv6Test, Ipv4Ipv6Listen) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("admin"), "GET", "/server_info", "", downstreamProtocol(), version_); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } } @@ -467,7 +467,7 @@ class StatsMatcherIntegrationTest response_ = IntegrationUtil::makeSingleRequest(lookupPort("admin"), "GET", "/stats", "", downstreamProtocol(), version_); ASSERT_TRUE(response_->complete()); - EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ("200", response_->headers().Status()->value().getStringView()); } BufferingStreamDecoderPtr response_; diff --git a/test/integration/integration_test.cc b/test/integration/integration_test.cc index dd7406282aba9..0611b2da8e989 100644 --- a/test/integration/integration_test.cc +++ b/test/integration/integration_test.cc @@ -84,12 +84,12 @@ TEST_P(IntegrationTest, RouterDirectResponse) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("http"), "GET", "/", "", downstream_protocol_, version_, "direct.example.com"); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("example-value", response->headers() - .get(Envoy::Http::LowerCaseString("x-additional-header")) - ->value() - .c_str()); - EXPECT_STREQ("text/html", response->headers().ContentType()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("example-value", response->headers() + .get(Envoy::Http::LowerCaseString("x-additional-header")) + ->value() + .getStringView()); + EXPECT_EQ("text/html", response->headers().ContentType()->value().getStringView()); EXPECT_EQ(body, response->body()); } @@ -191,7 +191,7 @@ TEST_P(IntegrationTest, UpstreamDisconnectWithTwoRequests) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); test_server_->waitForCounterGe("cluster.cluster_0.upstream_cx_total", 1); test_server_->waitForCounterGe("cluster.cluster_0.upstream_rq_200", 1); @@ -206,7 +206,7 @@ TEST_P(IntegrationTest, UpstreamDisconnectWithTwoRequests) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_TRUE(response2->complete()); - EXPECT_STREQ("200", response2->headers().Status()->value().c_str()); + EXPECT_EQ("200", response2->headers().Status()->value().getStringView()); test_server_->waitForCounterGe("cluster.cluster_0.upstream_cx_total", 2); test_server_->waitForCounterGe("cluster.cluster_0.upstream_rq_200", 2); } @@ -352,9 +352,11 @@ TEST_P(IntegrationTest, TestInlineHeaders) { EXPECT_EQ(upstream_headers->Host()->value(), "foo.com"); EXPECT_EQ(upstream_headers->CacheControl()->value(), "public,123"); ASSERT_TRUE(upstream_headers->get(Envoy::Http::LowerCaseString("foo")) != nullptr); - EXPECT_STREQ("bar", upstream_headers->get(Envoy::Http::LowerCaseString("foo"))->value().c_str()); + EXPECT_EQ("bar", + upstream_headers->get(Envoy::Http::LowerCaseString("foo"))->value().getStringView()); ASSERT_TRUE(upstream_headers->get(Envoy::Http::LowerCaseString("eep")) != nullptr); - EXPECT_STREQ("baz", upstream_headers->get(Envoy::Http::LowerCaseString("eep"))->value().c_str()); + EXPECT_EQ("baz", + upstream_headers->get(Envoy::Http::LowerCaseString("eep"))->value().getStringView()); } // Verify for HTTP/1.0 a keep-alive header results in no connection: close. @@ -387,7 +389,7 @@ TEST_P(IntegrationTest, NoHost) { response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("400", response->headers().Status()->value().c_str()); + EXPECT_EQ("400", response->headers().Status()->value().getStringView()); } TEST_P(IntegrationTest, BadPath) { @@ -490,7 +492,7 @@ TEST_P(IntegrationTest, UpstreamProtocolError) { codec_client_->waitForDisconnect(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); } TEST_P(IntegrationTest, TestHead) { @@ -670,7 +672,7 @@ TEST_P(IntegrationTest, TestDelayedConnectionTeardownOnGracefulClose) { response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("413", response->headers().Status()->value().c_str()); + EXPECT_EQ("413", response->headers().Status()->value().getStringView()); // With no delayed close processing, Envoy will close the connection immediately after flushing // and this should instead return true. EXPECT_FALSE(codec_client_->waitForDisconnect(std::chrono::milliseconds(500))); @@ -776,7 +778,7 @@ TEST_P(IntegrationTest, NoConnectionPoolsFree) { response->waitForEndStream(); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); test_server_->waitForCounterGe("cluster.cluster_0.upstream_rq_503", 1); EXPECT_EQ(test_server_->counter("cluster.cluster_0.upstream_cx_pool_overflow")->value(), 1); diff --git a/test/integration/load_stats_integration_test.cc b/test/integration/load_stats_integration_test.cc index 8d722aa94a38a..a7ebcc237a35f 100644 --- a/test/integration/load_stats_integration_test.cc +++ b/test/integration/load_stats_integration_test.cc @@ -248,10 +248,11 @@ class LoadStatsIntegrationTest : public testing::TestWithParamheaders().Method()->value().c_str()); - EXPECT_STREQ("/envoy.service.load_stats.v2.LoadReportingService/StreamLoadStats", - loadstats_stream_->headers().Path()->value().c_str()); - EXPECT_STREQ("application/grpc", loadstats_stream_->headers().ContentType()->value().c_str()); + EXPECT_EQ("POST", loadstats_stream_->headers().Method()->value().getStringView()); + EXPECT_EQ("/envoy.service.load_stats.v2.LoadReportingService/StreamLoadStats", + loadstats_stream_->headers().Path()->value().getStringView()); + EXPECT_EQ("application/grpc", + loadstats_stream_->headers().ContentType()->value().getStringView()); } while (!TestUtility::assertRepeatedPtrFieldEqual(expected_cluster_stats, loadstats_request.cluster_stats())); } @@ -274,8 +275,8 @@ class LoadStatsIntegrationTest : public testing::TestWithParambodyLength()); ASSERT_TRUE(response_->complete()); - EXPECT_STREQ(std::to_string(response_code).c_str(), - response_->headers().Status()->value().c_str()); + EXPECT_EQ(std::to_string(response_code), + response_->headers().Status()->value().getStringView()); EXPECT_EQ(response_size_, response_->body().size()); } @@ -583,7 +584,7 @@ TEST_P(LoadStatsIntegrationTest, Dropped) { initiateClientConnection(); response_->waitForEndStream(); ASSERT_TRUE(response_->complete()); - EXPECT_STREQ("503", response_->headers().Status()->value().c_str()); + EXPECT_EQ("503", response_->headers().Status()->value().getStringView()); cleanupUpstreamAndDownstream(); waitForLoadStatsRequest({}, 1); diff --git a/test/integration/overload_integration_test.cc b/test/integration/overload_integration_test.cc index 27c9818f4a949..f3084936c7025 100644 --- a/test/integration/overload_integration_test.cc +++ b/test/integration/overload_integration_test.cc @@ -72,7 +72,7 @@ TEST_P(OverloadIntegrationTest, CloseStreamsWhenOverloaded) { response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); EXPECT_EQ("envoy overloaded", response->body()); codec_client_->close(); @@ -81,7 +81,7 @@ TEST_P(OverloadIntegrationTest, CloseStreamsWhenOverloaded) { response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); EXPECT_EQ("envoy overloaded", response->body()); codec_client_->close(); @@ -95,7 +95,7 @@ TEST_P(OverloadIntegrationTest, CloseStreamsWhenOverloaded) { EXPECT_TRUE(upstream_request_->complete()); EXPECT_EQ(0U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(0U, response->body().size()); } @@ -118,8 +118,8 @@ TEST_P(OverloadIntegrationTest, DisableKeepaliveWhenOverloaded) { codec_client_->waitForDisconnect(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); - EXPECT_STREQ("close", response->headers().Connection()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + EXPECT_EQ("close", response->headers().Connection()->value().getStringView()); // Deactivate overload state and check that keepalive is not disabled updateResource(0.7); @@ -129,7 +129,7 @@ TEST_P(OverloadIntegrationTest, DisableKeepaliveWhenOverloaded) { response = sendRequestAndWaitForResponse(request_headers, 1, default_response_headers_, 1); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(nullptr, response->headers().Connection()); } @@ -156,7 +156,7 @@ TEST_P(OverloadIntegrationTest, StopAcceptingConnectionsWhenOverloaded) { response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); EXPECT_EQ("envoy overloaded", response->body()); codec_client_->close(); } diff --git a/test/integration/protocol_integration_test.cc b/test/integration/protocol_integration_test.cc index 5515391c010a8..e3171f40ce0b1 100644 --- a/test/integration/protocol_integration_test.cc +++ b/test/integration/protocol_integration_test.cc @@ -113,7 +113,7 @@ TEST_P(DownstreamProtocolIntegrationTest, RouterClusterNotFound404) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("http"), "GET", "/unknown", "", downstream_protocol_, version_, "foo.com"); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("404", response->headers().Status()->value().c_str()); + EXPECT_EQ("404", response->headers().Status()->value().getStringView()); } // Add a route that uses unknown cluster (expect 503 Service Unavailable). @@ -128,7 +128,7 @@ TEST_P(DownstreamProtocolIntegrationTest, RouterClusterNotFound503) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("http"), "GET", "/unknown", "", downstream_protocol_, version_, "foo.com"); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); } // Add a route which redirects HTTP to HTTPS, and verify Envoy sends a 301 @@ -141,9 +141,9 @@ TEST_P(ProtocolIntegrationTest, RouterRedirect) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("http"), "GET", "/foo", "", downstream_protocol_, version_, "www.redirect.com"); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("301", response->headers().Status()->value().c_str()); - EXPECT_STREQ("https://www.redirect.com/foo", - response->headers().get(Http::Headers::get().Location)->value().c_str()); + EXPECT_EQ("301", response->headers().Status()->value().getStringView()); + EXPECT_EQ("https://www.redirect.com/foo", + response->headers().get(Http::Headers::get().Location)->value().getStringView()); } // Add a health check filter and verify correct computation of health based on upstream status. @@ -163,7 +163,7 @@ name: envoy.health_check response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); } // Add a health check filter and verify correct computation of health based on upstream status. @@ -183,7 +183,7 @@ name: envoy.health_check response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); } TEST_P(ProtocolIntegrationTest, AddEncodedTrailers) { @@ -201,12 +201,12 @@ config: {} response->waitForEndStream(); if (upstreamProtocol() == FakeHttpConnection::Type::HTTP2) { - EXPECT_STREQ("decode", upstream_request_->trailers()->GrpcMessage()->value().c_str()); + EXPECT_EQ("decode", upstream_request_->trailers()->GrpcMessage()->value().getStringView()); } EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); if (downstream_protocol_ == Http::CodecClient::Type::HTTP2) { - EXPECT_STREQ("encode", response->trailers()->GrpcMessage()->value().c_str()); + EXPECT_EQ("encode", response->trailers()->GrpcMessage()->value().getStringView()); } } @@ -222,7 +222,7 @@ TEST_P(ProtocolIntegrationTest, DrainClose) { codec_client_->waitForDisconnect(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); if (downstream_protocol_ == Http::CodecClient::Type::HTTP2) { EXPECT_TRUE(codec_client_->sawGoAway()); } @@ -259,7 +259,7 @@ TEST_P(ProtocolIntegrationTest, Retry) { EXPECT_EQ(1024U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(512U, response->body().size()); } @@ -282,7 +282,10 @@ TEST_P(DownstreamProtocolIntegrationTest, RetryAttemptCountHeader) { waitForNextUpstreamRequest(); upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "503"}}, false); - EXPECT_EQ(atoi(upstream_request_->headers().EnvoyAttemptCount()->value().c_str()), 1); + EXPECT_EQ( + atoi(std::string(upstream_request_->headers().EnvoyAttemptCount()->value().getStringView()) + .c_str()), + 1); if (fake_upstreams_[0]->httpType() == FakeHttpConnection::Type::HTTP1) { ASSERT_TRUE(fake_upstream_connection_->waitForDisconnect()); @@ -291,7 +294,10 @@ TEST_P(DownstreamProtocolIntegrationTest, RetryAttemptCountHeader) { ASSERT_TRUE(upstream_request_->waitForReset()); } waitForNextUpstreamRequest(); - EXPECT_EQ(atoi(upstream_request_->headers().EnvoyAttemptCount()->value().c_str()), 2); + EXPECT_EQ( + atoi(std::string(upstream_request_->headers().EnvoyAttemptCount()->value().getStringView()) + .c_str()), + 2); upstream_request_->encodeHeaders(default_response_headers_, false); upstream_request_->encodeData(512, true); @@ -300,7 +306,7 @@ TEST_P(DownstreamProtocolIntegrationTest, RetryAttemptCountHeader) { EXPECT_EQ(1024U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(512U, response->body().size()); } @@ -378,7 +384,7 @@ TEST_P(DownstreamProtocolIntegrationTest, RetryPriority) { EXPECT_EQ(1024U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(512U, response->body().size()); } @@ -436,7 +442,7 @@ TEST_P(DownstreamProtocolIntegrationTest, RetryHostPredicateFilter) { EXPECT_EQ(1024U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(512U, response->body().size()); } @@ -464,7 +470,7 @@ TEST_P(ProtocolIntegrationTest, RetryHittingBufferLimit) { EXPECT_EQ(66560U, upstream_request_->bodyLength()); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); } // Test hitting the dynamo filter with too many request bytes to buffer. Ensure the connection @@ -497,7 +503,7 @@ TEST_P(DownstreamProtocolIntegrationTest, HittingDecoderFilterLimit) { ASSERT_TRUE(response->complete()); } if (response->complete()) { - EXPECT_STREQ("413", response->headers().Status()->value().c_str()); + EXPECT_EQ("413", response->headers().Status()->value().getStringView()); } } @@ -528,7 +534,7 @@ TEST_P(DownstreamProtocolIntegrationTest, HittingEncoderFilterLimit) { response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("500", response->headers().Status()->value().c_str()); + EXPECT_EQ("500", response->headers().Status()->value().getStringView()); } TEST_P(ProtocolIntegrationTest, EnvoyHandling100Continue) { testEnvoyHandling100Continue(); } @@ -562,7 +568,7 @@ TEST_P(DownstreamProtocolIntegrationTest, ValidZeroLengthContent) { auto response = sendRequestAndWaitForResponse(request_headers, 0, default_response_headers_, 0); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } TEST_P(DownstreamProtocolIntegrationTest, InvalidContentLength) { @@ -586,7 +592,7 @@ TEST_P(DownstreamProtocolIntegrationTest, InvalidContentLength) { if (downstream_protocol_ == Http::CodecClient::Type::HTTP1) { ASSERT_TRUE(response->complete()); - EXPECT_STREQ("400", response->headers().Status()->value().c_str()); + EXPECT_EQ("400", response->headers().Status()->value().getStringView()); } else { ASSERT_TRUE(response->reset()); EXPECT_EQ(Http::StreamResetReason::RemoteReset, response->reset_reason()); @@ -612,7 +618,7 @@ TEST_P(DownstreamProtocolIntegrationTest, MultipleContentLengths) { if (downstream_protocol_ == Http::CodecClient::Type::HTTP1) { ASSERT_TRUE(response->complete()); - EXPECT_STREQ("400", response->headers().Status()->value().c_str()); + EXPECT_EQ("400", response->headers().Status()->value().getStringView()); } else { ASSERT_TRUE(response->reset()); EXPECT_EQ(Http::StreamResetReason::RemoteReset, response->reset_reason()); @@ -645,7 +651,7 @@ name: encode-headers-only } EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); EXPECT_EQ(0, response->body().size()); } @@ -668,7 +674,7 @@ name: decode-headers-only response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); EXPECT_EQ(128, response->body().size()); } @@ -703,7 +709,7 @@ name: passthrough-filter } EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); EXPECT_EQ(0, response->body().size()); } @@ -732,7 +738,7 @@ name: passthrough-filter response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); EXPECT_EQ(128, response->body().size()); } @@ -769,7 +775,7 @@ name: decode-headers-only response->waitForEndStream(); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); EXPECT_EQ(0, upstream_request_->body().length()); } diff --git a/test/integration/ratelimit_integration_test.cc b/test/integration/ratelimit_integration_test.cc index 2f12f8f606d20..0315dc8779705 100644 --- a/test/integration/ratelimit_integration_test.cc +++ b/test/integration/ratelimit_integration_test.cc @@ -82,10 +82,11 @@ class RatelimitIntegrationTest : public Grpc::GrpcClientIntegrationParamTest, RELEASE_ASSERT(result, result.message()); result = ratelimit_request_->waitForEndStream(*dispatcher_); RELEASE_ASSERT(result, result.message()); - EXPECT_STREQ("POST", ratelimit_request_->headers().Method()->value().c_str()); - EXPECT_STREQ("/envoy.service.ratelimit.v2.RateLimitService/ShouldRateLimit", - ratelimit_request_->headers().Path()->value().c_str()); - EXPECT_STREQ("application/grpc", ratelimit_request_->headers().ContentType()->value().c_str()); + EXPECT_EQ("POST", ratelimit_request_->headers().Method()->value().getStringView()); + EXPECT_EQ("/envoy.service.ratelimit.v2.RateLimitService/ShouldRateLimit", + ratelimit_request_->headers().Path()->value().getStringView()); + EXPECT_EQ("application/grpc", + ratelimit_request_->headers().ContentType()->value().getStringView()); envoy::service::ratelimit::v2::RateLimitRequest expected_request_msg; expected_request_msg.set_domain("some_domain"); @@ -112,15 +113,15 @@ class RatelimitIntegrationTest : public Grpc::GrpcClientIntegrationParamTest, EXPECT_EQ(request_size_, upstream_request_->bodyLength()); EXPECT_TRUE(response_->complete()); - EXPECT_STREQ("200", response_->headers().Status()->value().c_str()); + EXPECT_EQ("200", response_->headers().Status()->value().getStringView()); EXPECT_EQ(response_size_, response_->body().size()); } void waitForFailedUpstreamResponse(uint32_t response_code) { response_->waitForEndStream(); EXPECT_TRUE(response_->complete()); - EXPECT_STREQ(std::to_string(response_code).c_str(), - response_->headers().Status()->value().c_str()); + EXPECT_EQ(std::to_string(response_code), + response_->headers().Status()->value().getStringView()); } void sendRateLimitResponse(envoy::service::ratelimit::v2::RateLimitResponse_Code code, @@ -134,8 +135,8 @@ class RatelimitIntegrationTest : public Grpc::GrpcClientIntegrationParamTest, auto header = static_cast(context) ->mutable_headers() ->Add(); - header->set_key(h.key().c_str()); - header->set_value(h.value().c_str()); + header->set_key(std::string(h.key().getStringView())); + header->set_value(std::string(h.value().getStringView())); return Http::HeaderMap::Iterate::Continue; }, &response_msg); @@ -209,8 +210,8 @@ TEST_P(RatelimitIntegrationTest, OkWithHeaders) { ratelimit_headers.iterate( [](const Http::HeaderEntry& entry, void* context) -> Http::HeaderMap::Iterate { IntegrationStreamDecoder* response = static_cast(context); - Http::LowerCaseString lower_key{entry.key().c_str()}; - EXPECT_STREQ(entry.value().c_str(), response->headers().get(lower_key)->value().c_str()); + Http::LowerCaseString lower_key{std::string(entry.key().getStringView())}; + EXPECT_EQ(entry.value(), response->headers().get(lower_key)->value().getStringView()); return Http::HeaderMap::Iterate::Continue; }, response_.get()); @@ -247,8 +248,8 @@ TEST_P(RatelimitIntegrationTest, OverLimitWithHeaders) { ratelimit_headers.iterate( [](const Http::HeaderEntry& entry, void* context) -> Http::HeaderMap::Iterate { IntegrationStreamDecoder* response = static_cast(context); - Http::LowerCaseString lower_key{entry.key().c_str()}; - EXPECT_STREQ(entry.value().c_str(), response->headers().get(lower_key)->value().c_str()); + Http::LowerCaseString lower_key{std::string(entry.key().getStringView())}; + EXPECT_EQ(entry.value(), response->headers().get(lower_key)->value().getStringView()); return Http::HeaderMap::Iterate::Continue; }, response_.get()); diff --git a/test/integration/redirect_integration_test.cc b/test/integration/redirect_integration_test.cc index e1a614557fc1c..dce879ecdb151 100644 --- a/test/integration/redirect_integration_test.cc +++ b/test/integration/redirect_integration_test.cc @@ -31,7 +31,7 @@ TEST_P(RedirectIntegrationTest, RedirectNotConfigured) { codec_client_ = makeHttpConnection(lookupPort("http")); auto response = sendRequestAndWaitForResponse(default_request_headers_, 0, redirect_response_, 0); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("302", response->headers().Status()->value().c_str()); + EXPECT_EQ("302", response->headers().Status()->value().getStringView()); } // Now test a route with redirects configured on in pass-through mode. @@ -41,7 +41,7 @@ TEST_P(RedirectIntegrationTest, InternalRedirectPassedThrough) { codec_client_ = makeHttpConnection(lookupPort("http")); default_request_headers_.insertHost().value("pass.through.internal.redirect", 30); auto response = sendRequestAndWaitForResponse(default_request_headers_, 0, redirect_response_, 0); - EXPECT_STREQ("302", response->headers().Status()->value().c_str()); + EXPECT_EQ("302", response->headers().Status()->value().getStringView()); EXPECT_EQ( 0, test_server_->counter("cluster.cluster_0.upstream_internal_redirect_failed_total")->value()); @@ -67,17 +67,17 @@ TEST_P(RedirectIntegrationTest, BasicInternalRedirect) { waitForNextUpstreamRequest(); ASSERT(upstream_request_->headers().EnvoyOriginalUrl() != nullptr); - EXPECT_STREQ("http://handle.internal.redirect/test/long/url", - upstream_request_->headers().EnvoyOriginalUrl()->value().c_str()); - EXPECT_STREQ("/new/url", upstream_request_->headers().Path()->value().c_str()); - EXPECT_STREQ("authority2", upstream_request_->headers().Host()->value().c_str()); - EXPECT_STREQ("via_value", upstream_request_->headers().Via()->value().c_str()); + EXPECT_EQ("http://handle.internal.redirect/test/long/url", + upstream_request_->headers().EnvoyOriginalUrl()->value().getStringView()); + EXPECT_EQ("/new/url", upstream_request_->headers().Path()->value().getStringView()); + EXPECT_EQ("authority2", upstream_request_->headers().Host()->value().getStringView()); + EXPECT_EQ("via_value", upstream_request_->headers().Via()->value().getStringView()); upstream_request_->encodeHeaders(default_response_headers_, true); response->waitForEndStream(); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); EXPECT_EQ(1, test_server_->counter("cluster.cluster_0.upstream_internal_redirect_succeeded_total") ->value()); } @@ -92,7 +92,7 @@ TEST_P(RedirectIntegrationTest, InvalidRedirect) { codec_client_ = makeHttpConnection(lookupPort("http")); default_request_headers_.insertHost().value("handle.internal.redirect", 24); auto response = sendRequestAndWaitForResponse(default_request_headers_, 0, redirect_response_, 0); - EXPECT_STREQ("302", response->headers().Status()->value().c_str()); + EXPECT_EQ("302", response->headers().Status()->value().getStringView()); EXPECT_EQ( 1, test_server_->counter("cluster.cluster_0.upstream_internal_redirect_failed_total")->value()); diff --git a/test/integration/sds_dynamic_integration_test.cc b/test/integration/sds_dynamic_integration_test.cc index a8cc23cafaa08..0ce8217ec06f8 100644 --- a/test/integration/sds_dynamic_integration_test.cc +++ b/test/integration/sds_dynamic_integration_test.cc @@ -410,7 +410,7 @@ TEST_P(SdsDynamicUpstreamIntegrationTest, WrongSecretFirst) { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( lookupPort("http"), "GET", "/test/long/url", "", downstream_protocol_, version_); ASSERT_TRUE(response->complete()); - EXPECT_STREQ("503", response->headers().Status()->value().c_str()); + EXPECT_EQ("503", response->headers().Status()->value().getStringView()); // To flush out the reset connection from the first request in upstream. FakeRawConnectionPtr fake_upstream_connection; diff --git a/test/integration/server.cc b/test/integration/server.cc index de0fef7425d1b..463837fe0bfcb 100644 --- a/test/integration/server.cc +++ b/test/integration/server.cc @@ -200,7 +200,7 @@ IntegrationTestServerImpl::~IntegrationTestServerImpl() { BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest( admin_address, "POST", "/quitquitquit", "", Http::CodecClient::Type::HTTP1); EXPECT_TRUE(response->complete()); - EXPECT_STREQ("200", response->headers().Status()->value().c_str()); + EXPECT_EQ("200", response->headers().Status()->value().getStringView()); } } diff --git a/test/integration/websocket_integration_test.cc b/test/integration/websocket_integration_test.cc index d4b55d31e826d..ffe8f683ea3c6 100644 --- a/test/integration/websocket_integration_test.cc +++ b/test/integration/websocket_integration_test.cc @@ -45,7 +45,7 @@ void WebsocketIntegrationTest::validateUpgradeRequestHeaders( const Http::HeaderMap& original_request_headers) { Http::TestHeaderMapImpl proxied_request_headers(original_proxied_request_headers); if (proxied_request_headers.ForwardedProto()) { - ASSERT_STREQ(proxied_request_headers.ForwardedProto()->value().c_str(), "http"); + ASSERT_EQ(proxied_request_headers.ForwardedProto()->value().getStringView(), "http"); proxied_request_headers.removeForwardedProto(); } @@ -55,7 +55,7 @@ void WebsocketIntegrationTest::validateUpgradeRequestHeaders( proxied_request_headers.removeEnvoyExpectedRequestTimeoutMs(); if (proxied_request_headers.Scheme()) { - ASSERT_STREQ(proxied_request_headers.Scheme()->value().c_str(), "http"); + ASSERT_EQ(proxied_request_headers.Scheme()->value().getStringView(), "http"); } else { proxied_request_headers.insertScheme().value().append("http", 4); } @@ -74,7 +74,7 @@ void WebsocketIntegrationTest::validateUpgradeResponseHeaders( // Check for and remove headers added by default for HTTP responses. ASSERT_TRUE(proxied_response_headers.Date() != nullptr); ASSERT_TRUE(proxied_response_headers.Server() != nullptr); - ASSERT_STREQ(proxied_response_headers.Server()->value().c_str(), "envoy"); + ASSERT_EQ(proxied_response_headers.Server()->value().getStringView(), "envoy"); proxied_response_headers.removeDate(); proxied_response_headers.removeServer(); @@ -93,7 +93,7 @@ void WebsocketIntegrationTest::commonValidate(Http::HeaderMap& proxied_headers, // If no content length is specified, the HTTP1 codec will add a chunked encoding header. if (original_headers.ContentLength() == nullptr && proxied_headers.TransferEncoding() != nullptr) { - ASSERT_STREQ(proxied_headers.TransferEncoding()->value().c_str(), "chunked"); + ASSERT_EQ(proxied_headers.TransferEncoding()->value().getStringView(), "chunked"); proxied_headers.removeTransferEncoding(); } if (proxied_headers.Connection() != nullptr && @@ -369,7 +369,7 @@ TEST_P(WebsocketIntegrationTest, WebsocketCustomFilterChain) { response_ = std::move(encoder_decoder.second); codec_client_->sendData(encoder_decoder.first, large_req_str, false); response_->waitForEndStream(); - EXPECT_STREQ("413", response_->headers().Status()->value().c_str()); + EXPECT_EQ("413", response_->headers().Status()->value().getStringView()); waitForClientDisconnectOrReset(); codec_client_->close(); } @@ -386,7 +386,7 @@ TEST_P(WebsocketIntegrationTest, WebsocketCustomFilterChain) { response_ = std::move(encoder_decoder.second); codec_client_->sendData(encoder_decoder.first, large_req_str, false); response_->waitForEndStream(); - EXPECT_STREQ("413", response_->headers().Status()->value().c_str()); + EXPECT_EQ("413", response_->headers().Status()->value().getStringView()); waitForClientDisconnectOrReset(); codec_client_->close(); } diff --git a/test/integration/xfcc_integration_test.cc b/test/integration/xfcc_integration_test.cc index 410f74cd7756d..d352a3a3836eb 100644 --- a/test/integration/xfcc_integration_test.cc +++ b/test/integration/xfcc_integration_test.cc @@ -159,8 +159,8 @@ void XfccIntegrationTest::testRequestAndResponseWithXfccHeader(std::string previ if (expected_xfcc.empty()) { EXPECT_EQ(nullptr, upstream_request_->headers().ForwardedClientCert()); } else { - EXPECT_STREQ(expected_xfcc.c_str(), - upstream_request_->headers().ForwardedClientCert()->value().c_str()); + EXPECT_EQ(expected_xfcc, + upstream_request_->headers().ForwardedClientCert()->value().getStringView()); } upstream_request_->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, true); response->waitForEndStream(); diff --git a/test/test_common/printers.cc b/test/test_common/printers.cc index 23aa6cb82d3e9..c6573e80a5853 100644 --- a/test/test_common/printers.cc +++ b/test/test_common/printers.cc @@ -12,7 +12,8 @@ void PrintTo(const HeaderMapImpl& headers, std::ostream* os) { headers.iterate( [](const HeaderEntry& header, void* context) -> HeaderMap::Iterate { std::ostream* os = static_cast(context); - *os << "{'" << header.key().c_str() << "','" << header.value().c_str() << "'}"; + *os << "{'" << header.key().getStringView() << "','" << header.value().getStringView() + << "'}"; return HeaderMap::Iterate::Continue; }, os); diff --git a/test/test_common/utility.cc b/test/test_common/utility.cc index 3589718497169..f77209822b07e 100644 --- a/test/test_common/utility.cc +++ b/test/test_common/utility.cc @@ -82,8 +82,8 @@ bool TestUtility::headerMapEqualIgnoreOrder(const Http::HeaderMap& lhs, [](const Http::HeaderEntry& header, void* context) -> Http::HeaderMap::Iterate { State* state = static_cast(context); const Http::HeaderEntry* entry = - state->lhs.get(Http::LowerCaseString(std::string(header.key().c_str()))); - if (entry == nullptr || (entry->value() != header.value().c_str())) { + state->lhs.get(Http::LowerCaseString(std::string(header.key().getStringView()))); + if (entry == nullptr || (entry->value() != header.value().getStringView())) { state->equal = false; return Http::HeaderMap::Iterate::Break; } @@ -371,7 +371,7 @@ std::string TestHeaderMapImpl::get_(const LowerCaseString& key) { if (!header) { return EMPTY_STRING; } else { - return header->value().c_str(); + return std::string(header->value().getStringView()); } } diff --git a/test/test_common/utility.h b/test/test_common/utility.h index 7318664e40f33..650160733bda7 100644 --- a/test/test_common/utility.h +++ b/test/test_common/utility.h @@ -466,7 +466,8 @@ class TestHeaderMapImpl : public HeaderMapImpl { p.iterate( [](const HeaderEntry& header, void* context) -> HeaderMap::Iterate { std::ostream* local_os = static_cast(context); - *local_os << header.key().c_str() << " " << header.value().c_str() << std::endl; + *local_os << header.key().getStringView() << " " << header.value().getStringView() + << std::endl; return HeaderMap::Iterate::Continue; }, &os);