remove value policy from core (#1917)
This commit is contained in:
parent
b6c354f435
commit
d6cd0af3cc
@ -427,59 +427,4 @@ namespace Azure { namespace Core { namespace Http { namespace Policies {
|
||||
Context const& ctx) const override;
|
||||
};
|
||||
|
||||
namespace _internal {
|
||||
/**
|
||||
* @brief #Azure::Core::Http::Policies::_internal::ValuePolicy options.
|
||||
*/
|
||||
struct ValueOptions
|
||||
{
|
||||
CaseInsensitiveMap HeaderValues;
|
||||
std::map<std::string, std::string> QueryValues;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Value policy.
|
||||
*
|
||||
* @details Applies key-value pair values to each HTTP request (either HTTP headers or query
|
||||
* parameters).
|
||||
*/
|
||||
class ValuePolicy : public HttpPolicy {
|
||||
private:
|
||||
ValueOptions m_options;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a #Azure::Core::Http::Policies::_internal::ValuePolicy with the
|
||||
* #Azure::Core::Http::Policies::_internal::ValueOptions provided.
|
||||
* @param options #Azure::Core::Http::Policies::_internal::ValueOptions.
|
||||
*/
|
||||
explicit ValuePolicy(ValueOptions options) : m_options(std::move(options)) {}
|
||||
|
||||
std::unique_ptr<HttpPolicy> Clone() const override
|
||||
{
|
||||
return std::make_unique<ValuePolicy>(*this);
|
||||
}
|
||||
|
||||
std::unique_ptr<RawResponse> Send(
|
||||
Request& request,
|
||||
NextHttpPolicy nextHttpPolicy,
|
||||
Context const& ctx) const override
|
||||
{
|
||||
for (auto const& hdrPair : m_options.HeaderValues)
|
||||
{
|
||||
request.SetHeader(hdrPair.first, hdrPair.second);
|
||||
}
|
||||
|
||||
{
|
||||
auto& url = request.GetUrl();
|
||||
for (auto const& qryPair : m_options.QueryValues)
|
||||
{
|
||||
url.AppendQueryParameter(qryPair.first, qryPair.second);
|
||||
}
|
||||
}
|
||||
|
||||
return nextHttpPolicy.Send(request, ctx);
|
||||
}
|
||||
};
|
||||
} // namespace _internal
|
||||
}}}} // namespace Azure::Core::Http::Policies
|
||||
|
||||
@ -124,34 +124,6 @@ TEST(Policy, throwWhenNoTransportPolicyMessage)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Policy, ValuePolicy)
|
||||
{
|
||||
using namespace Azure::Core;
|
||||
using namespace Azure::Core::Http;
|
||||
using namespace Azure::Core::Http::Policies;
|
||||
using namespace Azure::Core::Http::_internal;
|
||||
|
||||
Azure::Core::Http::Policies::_internal::ValueOptions options
|
||||
= {{{"hdrkey1", "HdrVal1"}, {"hdrkey2", "HdrVal2"}},
|
||||
{{"QryKey1", "QryVal1"}, {"QryKey2", "QryVal2"}}};
|
||||
|
||||
std::vector<std::unique_ptr<HttpPolicy>> policies;
|
||||
policies.emplace_back(
|
||||
std::make_unique<Azure::Core::Http::Policies::_internal::ValuePolicy>(options));
|
||||
policies.emplace_back(std::make_unique<NoOpPolicy>());
|
||||
HttpPipeline pipeline(policies);
|
||||
|
||||
Request request(HttpMethod::Get, Url("https:://www.example.com"));
|
||||
|
||||
pipeline.Send(request, Context::GetApplicationContext());
|
||||
|
||||
auto headers = request.GetHeaders();
|
||||
auto queryParams = request.GetUrl().GetQueryParameters();
|
||||
|
||||
ASSERT_EQ(headers, decltype(headers)({{"hdrkey1", "HdrVal1"}, {"hdrkey2", "HdrVal2"}}));
|
||||
ASSERT_EQ(queryParams, decltype(queryParams)({{"QryKey1", "QryVal1"}, {"QryKey2", "QryVal2"}}));
|
||||
}
|
||||
|
||||
TEST(Policy, RetryPolicyCounter)
|
||||
{
|
||||
using namespace Azure::Core;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user