azure-data-tables
Loading...
Searching...
No Matches
service_version_policy.hpp
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
6#include <azure/core/http/policies/policy.hpp>
7
8#include <memory>
9#include <string>
10
11namespace Azure { namespace Data { namespace Tables { namespace _detail { namespace Policies {
12
13 class ServiceVersionPolicy final : public Azure::Core::Http::Policies::HttpPolicy {
14 constexpr static const char* HttpHeaderXMsVersion = "x-ms-version";
15
16 public:
17 explicit ServiceVersionPolicy(std::string apiVersion) : m_apiVersion{std::move(apiVersion)} {}
18
19 std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy> Clone() const override
20 {
21 return std::make_unique<ServiceVersionPolicy>(*this);
22 }
23
24 std::unique_ptr<Azure::Core::Http::RawResponse> Send(
25 Azure::Core::Http::Request& request,
26 Azure::Core::Http::Policies::NextHttpPolicy nextPolicy,
27 const Azure::Core::Context& context) const override
28 {
29 if (!m_apiVersion.empty())
30 {
31 request.SetHeader(HttpHeaderXMsVersion, m_apiVersion);
32 }
33 return nextPolicy.Send(request, context);
34 }
35
36 private:
37 std::string m_apiVersion;
38 };
39
40}}}}} // namespace Azure::Data::Tables::_detail::Policies