diff --git a/mobile/library/cc/BUILD b/mobile/library/cc/BUILD index 163646756e8e..ba06a1e3b58c 100644 --- a/mobile/library/cc/BUILD +++ b/mobile/library/cc/BUILD @@ -59,48 +59,21 @@ envoy_cc_library( envoy_cc_library( name = "envoy_engine_cc_lib_no_stamp", srcs = [ - "bridge_utility.cc", "engine.cc", - "headers.cc", - "headers_builder.cc", "key_value_store.cc", - "request_headers.cc", - "request_headers_builder.cc", - "request_method.cc", - "request_trailers.cc", - "request_trailers_builder.cc", - "response_headers.cc", - "response_headers_builder.cc", - "response_trailers.cc", - "response_trailers_builder.cc", - "retry_policy.cc", "stream.cc", "stream_client.cc", "stream_prototype.cc", "string_accessor.cc", ], hdrs = [ - "bridge_utility.h", "direct_response_testing.h", "engine.h", - "headers.h", - "headers_builder.h", "key_value_store.h", - "request_headers.h", - "request_headers_builder.h", - "request_method.h", - "request_trailers.h", - "request_trailers_builder.h", - "response_headers.h", - "response_headers_builder.h", - "response_trailers.h", - "response_trailers_builder.h", - "retry_policy.h", "stream.h", "stream_client.h", "stream_prototype.h", "string_accessor.h", - "trailers.h", ], external_deps = ["abseil_optional"], repository = "@envoy", diff --git a/mobile/library/cc/bridge_utility.cc b/mobile/library/cc/bridge_utility.cc deleted file mode 100644 index 886598d5fee2..000000000000 --- a/mobile/library/cc/bridge_utility.cc +++ /dev/null @@ -1,27 +0,0 @@ -#include "bridge_utility.h" - -#include "library/common/data/utility.h" - -namespace Envoy { -namespace Platform { - -RawHeaderMap envoyHeadersAsRawHeaderMap(envoy_headers raw_headers) { - RawHeaderMap headers; - for (auto i = 0; i < raw_headers.length; i++) { - auto key = Data::Utility::copyToString(raw_headers.entries[i].key); - auto value = Data::Utility::copyToString(raw_headers.entries[i].value); - - if (!headers.contains(key)) { - headers.emplace(key, std::vector()); - } - headers[key].push_back(value); - } - // free instead of release_envoy_headers - // because we already free each envoy_data individually - // during calls to envoy_data_as_string - release_envoy_headers(raw_headers); - return headers; -} - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/bridge_utility.h b/mobile/library/cc/bridge_utility.h deleted file mode 100644 index 6a88f1641eaa..000000000000 --- a/mobile/library/cc/bridge_utility.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "library/cc/headers.h" -#include "library/common/types/c_types.h" - -namespace Envoy { -namespace Platform { - -RawHeaderMap envoyHeadersAsRawHeaderMap(envoy_headers raw_headers); - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/headers.cc b/mobile/library/cc/headers.cc deleted file mode 100644 index dd8c5f10a0bc..000000000000 --- a/mobile/library/cc/headers.cc +++ /dev/null @@ -1,23 +0,0 @@ -#include "library/cc/headers.h" - -namespace Envoy { -namespace Platform { - -Headers::const_iterator Headers::begin() const { - return Headers::const_iterator(allHeaders().begin()); -} - -Headers::const_iterator Headers::end() const { return Headers::const_iterator(allHeaders().end()); } - -const std::vector& Headers::operator[](absl::string_view key) const { - return headers_.at(key); -} - -const RawHeaderMap& Headers::allHeaders() const { return headers_; } - -bool Headers::contains(const std::string& key) const { return headers_.contains(key); } - -Headers::Headers(const RawHeaderMap& headers) : headers_(headers) {} - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/headers.h b/mobile/library/cc/headers.h deleted file mode 100644 index ed7b5c3eb2e9..000000000000 --- a/mobile/library/cc/headers.h +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include -#include - -#include "absl/container/flat_hash_map.h" - -namespace Envoy { -namespace Platform { - -using RawHeaderMap = absl::flat_hash_map>; - -class Headers { -public: - class const_iterator { - public: - const_iterator(RawHeaderMap::const_iterator position) : position_(position){}; - - using iterator_category = RawHeaderMap::const_iterator::iterator_category; - using value_type = std::string; - using reference = const value_type&; - using pointer = const value_type*; - using difference_type = std::ptrdiff_t; - - reference operator*() const { return position_->first; } - pointer operator->() { return &position_->first; } - - const_iterator& operator++() { - position_++; - return *this; - } - const_iterator operator++(int) { - auto tmp = *this; - ++(*this); - return tmp; - } - - friend bool operator==(const const_iterator& a, const const_iterator& b) { - return a.position_ == b.position_; - } - friend bool operator!=(const const_iterator& a, const const_iterator& b) { - return a.position_ != b.position_; - } - - private: - RawHeaderMap::const_iterator position_; - }; - - virtual ~Headers() {} - - const_iterator begin() const; - const_iterator end() const; - - const std::vector& operator[](absl::string_view key) const; - const RawHeaderMap& allHeaders() const; - bool contains(const std::string& key) const; - -protected: - Headers(const RawHeaderMap& headers); - -private: - RawHeaderMap headers_; -}; - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/headers_builder.cc b/mobile/library/cc/headers_builder.cc deleted file mode 100644 index 55595a22b0f3..000000000000 --- a/mobile/library/cc/headers_builder.cc +++ /dev/null @@ -1,44 +0,0 @@ -#include "library/cc/headers_builder.h" - -namespace Envoy { -namespace Platform { - -HeadersBuilder& HeadersBuilder::add(std::string name, std::string value) { - if (isRestrictedHeader(name)) { - return *this; - } - headers_[std::move(name)].push_back(std::move(value)); - return *this; -} - -HeadersBuilder& HeadersBuilder::set(std::string name, std::vector values) { - if (isRestrictedHeader(name)) { - return *this; - } - headers_[std::move(name)] = std::move(values); - return *this; -} - -HeadersBuilder& HeadersBuilder::remove(absl::string_view name) { - if (isRestrictedHeader(name)) { - return *this; - } - headers_.erase(name); - return *this; -} - -HeadersBuilder::HeadersBuilder() {} - -HeadersBuilder& HeadersBuilder::internalSet(std::string name, std::vector values) { - headers_[std::move(name)] = std::move(values); - return *this; -} - -const RawHeaderMap& HeadersBuilder::allHeaders() const { return headers_; } - -bool HeadersBuilder::isRestrictedHeader(absl::string_view name) const { - return name.find(':') == 0 || name.find("x-envoy-mobile") == 0; -} - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/headers_builder.h b/mobile/library/cc/headers_builder.h deleted file mode 100644 index 06a1aa9fefdf..000000000000 --- a/mobile/library/cc/headers_builder.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "headers.h" - -namespace Envoy { -namespace Platform { - -class HeadersBuilder { -public: - virtual ~HeadersBuilder() {} - - HeadersBuilder& add(std::string name, std::string value); - HeadersBuilder& set(std::string name, std::vector values); - HeadersBuilder& remove(absl::string_view name); - -protected: - HeadersBuilder(); - HeadersBuilder& internalSet(std::string name, std::vector values); - const RawHeaderMap& allHeaders() const; - -private: - bool isRestrictedHeader(absl::string_view name) const; - - RawHeaderMap headers_; -}; - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/request_headers.cc b/mobile/library/cc/request_headers.cc deleted file mode 100644 index 1257e0e621a0..000000000000 --- a/mobile/library/cc/request_headers.cc +++ /dev/null @@ -1,29 +0,0 @@ -#include "library/cc/request_headers.h" - -namespace Envoy { -namespace Platform { - -RequestMethod RequestHeaders::requestMethod() const { - return requestMethodFromString((*this)[":method"][0]); -} - -const std::string& RequestHeaders::scheme() const { return (*this)[":scheme"][0]; } - -const std::string& RequestHeaders::authority() const { return (*this)[":authority"][0]; } - -const std::string& RequestHeaders::path() const { return (*this)[":path"][0]; } - -absl::optional RequestHeaders::retryPolicy() const { - return absl::optional(RetryPolicy::fromRawHeaderMap(allHeaders())); -} - -RequestHeadersBuilder RequestHeaders::toRequestHeadersBuilder() const { - RequestHeadersBuilder builder(requestMethod(), scheme(), authority(), path()); - for (const auto& pair : allHeaders()) { - builder.set(pair.first, pair.second); - } - return builder; -} - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/request_headers.h b/mobile/library/cc/request_headers.h deleted file mode 100644 index 1a88c10f4f2d..000000000000 --- a/mobile/library/cc/request_headers.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include - -#include "absl/types/optional.h" -#include "library/cc/headers.h" -#include "library/cc/request_headers_builder.h" -#include "library/cc/request_method.h" -#include "library/cc/retry_policy.h" - -namespace Envoy { -namespace Platform { - -class RequestHeadersBuilder; - -class RequestHeaders : public Headers { -public: - RequestMethod requestMethod() const; - const std::string& scheme() const; - const std::string& authority() const; - const std::string& path() const; - absl::optional retryPolicy() const; - - RequestHeadersBuilder toRequestHeadersBuilder() const; - -private: - RequestHeaders(RawHeaderMap headers) : Headers(std::move(headers)) {} - - friend class RequestHeadersBuilder; -}; - -using RequestHeadersSharedPtr = std::shared_ptr; - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/request_headers_builder.cc b/mobile/library/cc/request_headers_builder.cc deleted file mode 100644 index ca1193acfdc1..000000000000 --- a/mobile/library/cc/request_headers_builder.cc +++ /dev/null @@ -1,42 +0,0 @@ -#include "request_headers_builder.h" - -#include "source/common/http/utility.h" - -namespace Envoy { -namespace Platform { - -RequestHeadersBuilder::RequestHeadersBuilder(RequestMethod request_method, std::string scheme, - std::string authority, std::string path) { - initialize(request_method, std::move(scheme), std::move(authority), std::move(path)); -} - -RequestHeadersBuilder::RequestHeadersBuilder(RequestMethod request_method, absl::string_view url) { - Envoy::Http::Utility::Url parsed_url; - if (!parsed_url.initialize(url, /*is_connect_request=*/false)) { - initialize(request_method, "", "", ""); - return; - } - initialize(request_method, std::string(parsed_url.scheme()), - std::string(parsed_url.hostAndPort()), std::string(parsed_url.pathAndQueryParams())); -} - -void RequestHeadersBuilder::initialize(RequestMethod request_method, std::string scheme, - std::string authority, std::string path) { - internalSet(":method", {std::string(requestMethodToString(request_method))}); - internalSet(":scheme", {std::move(scheme)}); - internalSet(":authority", {std::move(authority)}); - internalSet(":path", {std::move(path)}); -} - -RequestHeadersBuilder& RequestHeadersBuilder::addRetryPolicy(const RetryPolicy& retry_policy) { - const RawHeaderMap retry_policy_headers = retry_policy.asRawHeaderMap(); - for (const auto& pair : retry_policy_headers) { - internalSet(pair.first, pair.second); - } - return *this; -} - -RequestHeaders RequestHeadersBuilder::build() const { return RequestHeaders(allHeaders()); } - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/request_headers_builder.h b/mobile/library/cc/request_headers_builder.h deleted file mode 100644 index db565ce2a83a..000000000000 --- a/mobile/library/cc/request_headers_builder.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include - -#include "library/cc/headers_builder.h" -#include "library/cc/request_headers.h" -#include "library/cc/request_method.h" -#include "retry_policy.h" - -namespace Envoy { -namespace Platform { - -class RequestHeaders; -struct RetryPolicy; - -class RequestHeadersBuilder : public HeadersBuilder { -public: - RequestHeadersBuilder(RequestMethod request_method, std::string scheme, std::string authority, - std::string path); - RequestHeadersBuilder(RequestMethod request_method, absl::string_view url); - - RequestHeadersBuilder& addRetryPolicy(const RetryPolicy& retry_policy); - - RequestHeaders build() const; - -private: - void initialize(RequestMethod request_method, std::string scheme, std::string authority, - std::string path); -}; - -using RequestHeadersBuilderSharedPtr = std::shared_ptr; - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/request_method.cc b/mobile/library/cc/request_method.cc deleted file mode 100644 index 5fe3913be8cc..000000000000 --- a/mobile/library/cc/request_method.cc +++ /dev/null @@ -1,46 +0,0 @@ -#include "request_method.h" - -#include - -#include "source/common/common/assert.h" - -#include "absl/strings/string_view.h" - -namespace Envoy { -namespace Platform { - -namespace { - -const std::pair REQUEST_METHOD_LOOKUP[]{ - {RequestMethod::DELETE, "DELETE"}, {RequestMethod::GET, "GET"}, - {RequestMethod::HEAD, "HEAD"}, {RequestMethod::OPTIONS, "OPTIONS"}, - {RequestMethod::PATCH, "PATCH"}, {RequestMethod::POST, "POST"}, - {RequestMethod::PUT, "PUT"}, {RequestMethod::TRACE, "TRACE"}, -}; - -} // namespace - -absl::string_view requestMethodToString(RequestMethod method) { - for (const auto& pair : REQUEST_METHOD_LOOKUP) { - if (pair.first == method) { - return pair.second; - } - } - - IS_ENVOY_BUG("unknown method"); - return ""; -} - -RequestMethod requestMethodFromString(absl::string_view str) { - for (const auto& pair : REQUEST_METHOD_LOOKUP) { - if (pair.second == str) { - return pair.first; - } - } - - IS_ENVOY_BUG("unknown method"); - return REQUEST_METHOD_LOOKUP[0].first; -} - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/request_method.h b/mobile/library/cc/request_method.h deleted file mode 100644 index de248151b533..000000000000 --- a/mobile/library/cc/request_method.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "absl/strings/string_view.h" - -namespace Envoy { -namespace Platform { - -enum RequestMethod { - DELETE, - GET, - HEAD, - OPTIONS, - PATCH, - POST, - PUT, - TRACE, -}; - -absl::string_view requestMethodToString(RequestMethod method); -RequestMethod requestMethodFromString(absl::string_view str); - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/request_trailers.cc b/mobile/library/cc/request_trailers.cc deleted file mode 100644 index 6aac02c3dc80..000000000000 --- a/mobile/library/cc/request_trailers.cc +++ /dev/null @@ -1,15 +0,0 @@ -#include "request_trailers.h" - -namespace Envoy { -namespace Platform { - -RequestTrailersBuilder RequestTrailers::toRequestTrailersBuilder() const { - RequestTrailersBuilder builder; - for (const auto& pair : allHeaders()) { - builder.set(pair.first, pair.second); - } - return builder; -} - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/request_trailers.h b/mobile/library/cc/request_trailers.h deleted file mode 100644 index bf3cb548c1db..000000000000 --- a/mobile/library/cc/request_trailers.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "library/cc/request_trailers_builder.h" -#include "library/cc/trailers.h" - -namespace Envoy { -namespace Platform { - -class RequestTrailersBuilder; - -class RequestTrailers : public Trailers { -public: - RequestTrailersBuilder toRequestTrailersBuilder() const; - -private: - RequestTrailers(RawHeaderMap headers) : Trailers(std::move(headers)) {} - - friend class RequestTrailersBuilder; -}; - -using RequestTrailersSharedPtr = std::shared_ptr; - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/request_trailers_builder.cc b/mobile/library/cc/request_trailers_builder.cc deleted file mode 100644 index eb4a3f144426..000000000000 --- a/mobile/library/cc/request_trailers_builder.cc +++ /dev/null @@ -1,9 +0,0 @@ -#include "library/cc/request_trailers_builder.h" - -namespace Envoy { -namespace Platform { - -RequestTrailers RequestTrailersBuilder::build() const { return RequestTrailers(allHeaders()); } - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/request_trailers_builder.h b/mobile/library/cc/request_trailers_builder.h deleted file mode 100644 index 77df313df198..000000000000 --- a/mobile/library/cc/request_trailers_builder.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "library/cc/headers_builder.h" -#include "library/cc/request_trailers.h" - -namespace Envoy { -namespace Platform { - -class RequestTrailers; - -class RequestTrailersBuilder : public HeadersBuilder { -public: - RequestTrailersBuilder() : HeadersBuilder() {} - - RequestTrailers build() const; -}; - -using RequestTrailersBuilderSharedPtr = std::shared_ptr; - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/response_headers.cc b/mobile/library/cc/response_headers.cc deleted file mode 100644 index dadac12c53ae..000000000000 --- a/mobile/library/cc/response_headers.cc +++ /dev/null @@ -1,25 +0,0 @@ -#include "library/cc/response_headers.h" - -namespace Envoy { -namespace Platform { - -int ResponseHeaders::httpStatus() const { - if (!contains(":status")) { - return 0; - } - return stoi((*this)[":status"][0]); -} - -ResponseHeadersBuilder ResponseHeaders::toResponseHeadersBuilder() { - ResponseHeadersBuilder builder; - if (contains(":status")) { - builder.addHttpStatus(httpStatus()); - } - for (const auto& pair : allHeaders()) { - builder.set(pair.first, pair.second); - } - return builder; -} - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/response_headers.h b/mobile/library/cc/response_headers.h deleted file mode 100644 index 34f4d11c955e..000000000000 --- a/mobile/library/cc/response_headers.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "library/cc/headers.h" -#include "library/cc/response_headers_builder.h" - -namespace Envoy { -namespace Platform { - -class ResponseHeadersBuilder; - -class ResponseHeaders : public Headers { -public: - int httpStatus() const; - - ResponseHeadersBuilder toResponseHeadersBuilder(); - -private: - ResponseHeaders(RawHeaderMap headers) : Headers(std::move(headers)) {} - - friend class ResponseHeadersBuilder; -}; - -using ResponseHeadersSharedPtr = std::shared_ptr; - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/response_headers_builder.cc b/mobile/library/cc/response_headers_builder.cc deleted file mode 100644 index a92887e59f8c..000000000000 --- a/mobile/library/cc/response_headers_builder.cc +++ /dev/null @@ -1,17 +0,0 @@ -#include "library/cc/response_headers_builder.h" - -namespace Envoy { -namespace Platform { - -ResponseHeadersBuilder& ResponseHeadersBuilder::addHttpStatus(int status) { - internalSet(":status", std::vector{std::to_string(status)}); - return *this; -} - -ResponseHeadersSharedPtr ResponseHeadersBuilder::build() const { - ResponseHeaders* headers = new ResponseHeaders(allHeaders()); - return ResponseHeadersSharedPtr(headers); -} - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/response_headers_builder.h b/mobile/library/cc/response_headers_builder.h deleted file mode 100644 index 8b33c4cd719d..000000000000 --- a/mobile/library/cc/response_headers_builder.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "library/cc/headers_builder.h" -#include "library/cc/response_headers.h" - -namespace Envoy { -namespace Platform { - -class ResponseHeaders; -using ResponseHeadersSharedPtr = std::shared_ptr; - -class ResponseHeadersBuilder : public HeadersBuilder { -public: - ResponseHeadersBuilder() {} - - ResponseHeadersBuilder& addHttpStatus(int status); - ResponseHeadersSharedPtr build() const; -}; - -using ResponseHeadersBuilderSharedPtr = std::shared_ptr; - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/response_trailers.cc b/mobile/library/cc/response_trailers.cc deleted file mode 100644 index 47869d8a6193..000000000000 --- a/mobile/library/cc/response_trailers.cc +++ /dev/null @@ -1,15 +0,0 @@ -#include "library/cc/response_trailers.h" - -namespace Envoy { -namespace Platform { - -ResponseTrailersBuilder ResponseTrailers::toResponseTrailersBuilder() { - ResponseTrailersBuilder builder; - for (const auto& pair : allHeaders()) { - builder.set(pair.first, pair.second); - } - return builder; -} - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/response_trailers.h b/mobile/library/cc/response_trailers.h deleted file mode 100644 index 8e4a61713a77..000000000000 --- a/mobile/library/cc/response_trailers.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "library/cc/response_trailers_builder.h" -#include "library/cc/trailers.h" - -namespace Envoy { -namespace Platform { - -class ResponseTrailersBuilder; - -class ResponseTrailers : public Trailers { -public: - ResponseTrailersBuilder toResponseTrailersBuilder(); - -private: - ResponseTrailers(RawHeaderMap trailers) : Trailers(std::move(trailers)) {} - - friend class ResponseTrailersBuilder; -}; - -using ResponseTrailersSharedPtr = std::shared_ptr; - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/response_trailers_builder.cc b/mobile/library/cc/response_trailers_builder.cc deleted file mode 100644 index 0ec526f23a80..000000000000 --- a/mobile/library/cc/response_trailers_builder.cc +++ /dev/null @@ -1,12 +0,0 @@ -#include "library/cc/response_trailers_builder.h" - -namespace Envoy { -namespace Platform { - -ResponseTrailersSharedPtr ResponseTrailersBuilder::build() const { - ResponseTrailers* trailers = new ResponseTrailers(allHeaders()); - return ResponseTrailersSharedPtr(trailers); -} - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/response_trailers_builder.h b/mobile/library/cc/response_trailers_builder.h deleted file mode 100644 index 668b5593180b..000000000000 --- a/mobile/library/cc/response_trailers_builder.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "library/cc/headers_builder.h" -#include "library/cc/response_trailers.h" - -namespace Envoy { -namespace Platform { - -class ResponseTrailers; -using ResponseTrailersSharedPtr = std::shared_ptr; - -class ResponseTrailersBuilder : public HeadersBuilder { -public: - ResponseTrailersBuilder() {} - - ResponseTrailersSharedPtr build() const; -}; - -using ResponseTrailersBuilderSharedPtr = std::shared_ptr; - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/retry_policy.cc b/mobile/library/cc/retry_policy.cc deleted file mode 100644 index c24642a52bc6..000000000000 --- a/mobile/library/cc/retry_policy.cc +++ /dev/null @@ -1,78 +0,0 @@ -#include "library/cc/retry_policy.h" - -namespace Envoy { -namespace Platform { - -RawHeaderMap RetryPolicy::asRawHeaderMap() const { - RawHeaderMap outbound_headers{ - {"x-envoy-max-retries", {std::to_string(max_retry_count)}}, - {"x-envoy-upstream-rq-timeout-ms", {std::to_string(total_upstream_timeout_ms.value_or(0))}}, - }; - - if (per_try_timeout_ms.has_value()) { - outbound_headers["x-envoy-upstream-rq-per-try-timeout-ms"] = - std::vector{std::to_string(per_try_timeout_ms.value())}; - } - - std::vector retry_on_copy; - retry_on_copy.reserve(retry_on.size()); - for (const auto& retry_rule : retry_on) { - retry_on_copy.push_back(retry_rule); - } - - if (!retry_status_codes.empty()) { - retry_on_copy.push_back("retriable-status-codes"); - std::vector retry_status_codes_copy; - retry_status_codes_copy.reserve(retry_status_codes.size()); - for (const auto& status_code : retry_status_codes) { - retry_status_codes_copy.push_back(std::to_string(status_code)); - } - outbound_headers["x-envoy-retriable-status-codes"] = retry_status_codes_copy; - } - - if (!retry_on.empty()) { - outbound_headers["x-envoy-retry-on"] = retry_on_copy; - } - - return outbound_headers; -} - -RetryPolicy RetryPolicy::fromRawHeaderMap(const RawHeaderMap& headers) { - RetryPolicy retry_policy; - - if (headers.contains("x-envoy-max-retries")) { - retry_policy.max_retry_count = std::stoi(headers.at("x-envoy-max-retries")[0]); - } - - if (headers.contains("x-envoy-upstream-rq-timeout-ms")) { - retry_policy.total_upstream_timeout_ms = - std::stoi(headers.at("x-envoy-upstream-rq-timeout-ms")[0]); - } - - if (headers.contains("x-envoy-upstream-rq-per-try-timeout-ms")) { - retry_policy.per_try_timeout_ms = - std::stoi(headers.at("x-envoy-upstream-rq-per-try-timeout-ms")[0]); - } - - bool has_retriable_status_codes = false; - if (headers.contains("x-envoy-retry-on")) { - for (const auto& retry_rule_str : headers.at("x-envoy-retry-on")) { - if (retry_rule_str == "retriable-status_codes") { - has_retriable_status_codes = true; - continue; - } - retry_policy.retry_on.push_back(retry_rule_str); - } - } - - if (has_retriable_status_codes && headers.contains("x-envoy-retriable-status-codes")) { - for (const auto& status_code_str : headers.at("x-envoy-retriable-status-codes")) { - retry_policy.retry_status_codes.push_back(std::stoi(status_code_str)); - } - } - - return retry_policy; -} - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/retry_policy.h b/mobile/library/cc/retry_policy.h deleted file mode 100644 index edfd91379869..000000000000 --- a/mobile/library/cc/retry_policy.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include - -#include "absl/types/optional.h" -#include "library/cc/headers.h" -#include "library/cc/request_headers.h" - -namespace Envoy { -namespace Platform { - -class RequestHeaders; - -struct RetryPolicy { - int max_retry_count; - std::vector retry_on; - std::vector retry_status_codes; - absl::optional per_try_timeout_ms; - absl::optional total_upstream_timeout_ms; - - RawHeaderMap asRawHeaderMap() const; - static RetryPolicy fromRawHeaderMap(const RawHeaderMap& headers); -}; - -using RetryPolicySharedPtr = std::shared_ptr; - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/cc/trailers.h b/mobile/library/cc/trailers.h deleted file mode 100644 index ba60592b7b43..000000000000 --- a/mobile/library/cc/trailers.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "library/cc/headers.h" - -namespace Envoy { -namespace Platform { - -class Trailers : public Headers { -public: - Trailers(const RawHeaderMap& headers) : Headers(headers) {} -}; - -} // namespace Platform -} // namespace Envoy diff --git a/mobile/library/common/extensions/filters/http/local_error/BUILD b/mobile/library/common/extensions/filters/http/local_error/BUILD index 3c3b8248a208..ebd849217293 100644 --- a/mobile/library/common/extensions/filters/http/local_error/BUILD +++ b/mobile/library/common/extensions/filters/http/local_error/BUILD @@ -22,7 +22,6 @@ envoy_cc_extension( deps = [ ":filter_cc_proto", "//library/common/http:header_utility_lib", - "//library/common/http:internal_headers_lib", "//library/common/types:c_types_lib", "@envoy//envoy/http:codes_interface", "@envoy//envoy/http:filter_interface", diff --git a/mobile/library/common/extensions/filters/http/network_configuration/BUILD b/mobile/library/common/extensions/filters/http/network_configuration/BUILD index 2360408a9028..743db28725fb 100644 --- a/mobile/library/common/extensions/filters/http/network_configuration/BUILD +++ b/mobile/library/common/extensions/filters/http/network_configuration/BUILD @@ -23,7 +23,6 @@ envoy_cc_extension( ":filter_cc_proto", "//library/common/api:external_api_lib", "//library/common/http:header_utility_lib", - "//library/common/http:internal_headers_lib", "//library/common/network:connectivity_manager_lib", "//library/common/network:proxy_api_lib", "//library/common/network:proxy_resolver_interface_lib", diff --git a/mobile/library/common/extensions/filters/http/platform_bridge/BUILD b/mobile/library/common/extensions/filters/http/platform_bridge/BUILD index b6d20209859c..7b2a9622d743 100644 --- a/mobile/library/common/extensions/filters/http/platform_bridge/BUILD +++ b/mobile/library/common/extensions/filters/http/platform_bridge/BUILD @@ -31,7 +31,6 @@ envoy_cc_extension( "//library/common/bridge:utility_lib", "//library/common/data:utility_lib", "//library/common/http:header_utility_lib", - "//library/common/http:internal_headers_lib", "//library/common/stream_info:extra_stream_info_lib", "//library/common/types:c_types_lib", "@envoy//envoy/common:scope_tracker_interface", diff --git a/mobile/library/common/extensions/filters/http/platform_bridge/filter.cc b/mobile/library/common/extensions/filters/http/platform_bridge/filter.cc index 6d374cfc62ae..ac27ada6e586 100644 --- a/mobile/library/common/extensions/filters/http/platform_bridge/filter.cc +++ b/mobile/library/common/extensions/filters/http/platform_bridge/filter.cc @@ -1,12 +1,9 @@ #include "library/common/extensions/filters/http/platform_bridge/filter.h" -#include "envoy/server/filter_config.h" - #include "source/common/buffer/buffer_impl.h" #include "source/common/common/assert.h" #include "source/common/common/dump_state_utils.h" #include "source/common/common/scope_tracker.h" -#include "source/common/common/utility.h" #include "library/common/api/external.h" #include "library/common/bridge/utility.h" @@ -14,7 +11,6 @@ #include "library/common/data/utility.h" #include "library/common/extensions/filters/http/platform_bridge/c_type_definitions.h" #include "library/common/http/header_utility.h" -#include "library/common/http/headers.h" #include "library/common/stream_info/extra_stream_info.h" namespace Envoy { @@ -509,7 +505,7 @@ Http::FilterHeadersStatus PlatformBridgeFilter::encodeHeaders(Http::ResponseHead // Presence of internal error header indicates an error that should be surfaced as an // error callback (rather than an HTTP response). - const auto error_code_header = headers.get(Http::InternalHeaders::get().ErrorCode); + const auto error_code_header = headers.get(Http::LowerCaseString("x-internal-error-code")); if (error_code_header.empty()) { // No error, so delegate to base implementation for request and response path. return response_filter_base_->onHeaders(headers, end_stream); @@ -524,7 +520,7 @@ Http::FilterHeadersStatus PlatformBridgeFilter::encodeHeaders(Http::ResponseHead RELEASE_ASSERT(parsed_code, "parse error reading error code"); envoy_data error_message = envoy_nodata; - const auto error_message_header = headers.get(Http::InternalHeaders::get().ErrorMessage); + const auto error_message_header = headers.get(Http::LowerCaseString("x-internal-error-message")); if (!error_message_header.empty()) { error_message = Data::Utility::copyToBridgeData(error_message_header[0]->value().getStringView()); diff --git a/mobile/library/common/extensions/filters/http/socket_tag/BUILD b/mobile/library/common/extensions/filters/http/socket_tag/BUILD index 60045880c279..6b7e50503d87 100644 --- a/mobile/library/common/extensions/filters/http/socket_tag/BUILD +++ b/mobile/library/common/extensions/filters/http/socket_tag/BUILD @@ -21,7 +21,6 @@ envoy_cc_extension( repository = "@envoy", deps = [ ":filter_cc_proto", - "//library/common/http:internal_headers_lib", "//library/common/network:socket_tag_socket_option_lib", "//library/common/types:c_types_lib", "@envoy//envoy/http:codes_interface", diff --git a/mobile/library/common/http/BUILD b/mobile/library/common/http/BUILD index 8df8c651b643..49e7c223ed72 100644 --- a/mobile/library/common/http/BUILD +++ b/mobile/library/common/http/BUILD @@ -62,14 +62,3 @@ envoy_cc_library( "@envoy//source/extensions/http/header_formatters/preserve_case:preserve_case_formatter", ], ) - -envoy_cc_library( - name = "internal_headers_lib", - hdrs = ["headers.h"], - repository = "@envoy", - deps = [ - "@envoy//envoy/http:header_map_interface", - "@envoy//source/common/singleton:const_singleton", - "@envoy//source/common/singleton:threadsafe_singleton", - ], -) diff --git a/mobile/library/common/http/headers.h b/mobile/library/common/http/headers.h deleted file mode 100644 index 85786eea48dd..000000000000 --- a/mobile/library/common/http/headers.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "envoy/http/header_map.h" - -namespace Envoy { -namespace Http { - -/** - * Constant HTTP headers used internally for in-band signalling in the request/response path. - */ -class InternalHeaderValues { -public: - const LowerCaseString ErrorCode{"x-internal-error-code"}; - const LowerCaseString ErrorMessage{"x-internal-error-message"}; -}; - -using InternalHeaders = ConstSingleton; - -} // namespace Http -} // namespace Envoy diff --git a/mobile/test/cc/integration/lifetimes_test.cc b/mobile/test/cc/integration/lifetimes_test.cc index 6e3111aacacc..fc057d7396f3 100644 --- a/mobile/test/cc/integration/lifetimes_test.cc +++ b/mobile/test/cc/integration/lifetimes_test.cc @@ -4,7 +4,6 @@ #include "absl/synchronization/notification.h" #include "gtest/gtest.h" #include "library/cc/engine_builder.h" -#include "library/cc/request_headers.h" #include "library/common/engine_types.h" #include "library/common/http/header_utility.h" diff --git a/mobile/test/cc/unit/BUILD b/mobile/test/cc/unit/BUILD index d63465680b5b..53ef9a35620e 100644 --- a/mobile/test/cc/unit/BUILD +++ b/mobile/test/cc/unit/BUILD @@ -27,16 +27,6 @@ envoy_cc_test( ], ) -envoy_cc_test( - name = "request_headers_builder_test", - srcs = ["request_headers_builder_test.cc"], - repository = "@envoy", - deps = [ - "//library/cc:envoy_engine_cc_lib_no_stamp", - "@envoy_build_config//:extension_registry", - ], -) - envoy_cc_test( name = "fetch_client_test", srcs = ["fetch_client_test.cc"], diff --git a/mobile/test/cc/unit/request_headers_builder_test.cc b/mobile/test/cc/unit/request_headers_builder_test.cc deleted file mode 100644 index ce55a3e8a4b3..000000000000 --- a/mobile/test/cc/unit/request_headers_builder_test.cc +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include - -#include "gtest/gtest.h" -#include "library/cc/request_headers_builder.h" - -namespace Envoy { -namespace Platform { -namespace { - -TEST(RequestHeadersBuilderTest, ConstructsFromPieces) { - RequestHeadersBuilder builder(RequestMethod::POST, "https", "www.example.com", "/"); - RequestHeaders headers = builder.build(); - EXPECT_EQ(RequestMethod::POST, headers.requestMethod()); - EXPECT_EQ("https", headers.scheme()); - EXPECT_EQ("www.example.com", headers.authority()); - EXPECT_EQ("/", headers.path()); -} - -TEST(RequestHeadersBuilderTest, ConstructsFromUrl) { - RequestHeadersBuilder builder(RequestMethod::POST, "https://www.example.com/"); - RequestHeaders headers = builder.build(); - EXPECT_EQ(RequestMethod::POST, headers.requestMethod()); - EXPECT_EQ("https", headers.scheme()); - EXPECT_EQ("www.example.com", headers.authority()); - EXPECT_EQ("/", headers.path()); -} - -TEST(RequestHeadersBuilderTest, ConstructsFromInvalidUrl) { - RequestHeadersBuilder builder(RequestMethod::POST, "root@example.com"); - RequestHeaders headers = builder.build(); - EXPECT_EQ(RequestMethod::POST, headers.requestMethod()); - EXPECT_EQ("", headers.scheme()); - EXPECT_EQ("", headers.authority()); - EXPECT_EQ("", headers.path()); -} - -TEST(RequestHeadersBuilderTest, AddHeader) { - RequestHeadersBuilder builder(RequestMethod::POST, "root@example.com"); - builder.add("foo", "bar"); - RequestHeaders headers = builder.build(); - EXPECT_EQ(RequestMethod::POST, headers.requestMethod()); - ASSERT_TRUE(headers.contains("foo")); - EXPECT_EQ("bar", headers["foo"][0]); -} - -TEST(RequestHeadersBuilderTest, AddAndRemoveHeader) { - RequestHeadersBuilder builder(RequestMethod::POST, "root@example.com"); - builder.add("foo", "bar"); - builder.remove("foo"); - RequestHeaders headers = builder.build(); - EXPECT_EQ(RequestMethod::POST, headers.requestMethod()); - ASSERT_FALSE(headers.contains("foo")); -} - -} // namespace -} // namespace Platform -} // namespace Envoy diff --git a/mobile/test/common/http/filters/test_remote_response/BUILD b/mobile/test/common/http/filters/test_remote_response/BUILD index ef75ddc881a9..5b6b44643d54 100644 --- a/mobile/test/common/http/filters/test_remote_response/BUILD +++ b/mobile/test/common/http/filters/test_remote_response/BUILD @@ -22,7 +22,6 @@ envoy_cc_library( deps = [ ":filter_cc_proto", "//library/common/http:header_utility_lib", - "//library/common/http:internal_headers_lib", "//library/common/types:c_types_lib", "@envoy//envoy/http:codes_interface", "@envoy//envoy/http:filter_interface",