azure-core
Loading...
Searching...
No Matches
pipeline.hpp
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
10#pragma once
11
17#include "azure/core/internal/http/http_sanitizer.hpp"
18
19#include <memory>
20#include <vector>
21
22namespace Azure { namespace Core { namespace Http { namespace _internal {
23
33 class HttpPipeline final {
34 protected:
35 std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> m_policies;
36
37 public:
46 explicit HttpPipeline(
47 const std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>>& policies)
48 {
49 if (policies.size() == 0)
50 {
51 throw std::invalid_argument("policies cannot be empty");
52 }
53
54 m_policies.reserve(policies.size());
55 for (auto& policy : policies)
56 {
57 m_policies.emplace_back(policy->Clone());
58 }
59 }
60
78 explicit HttpPipeline(
79 Azure::Core::_internal::ClientOptions const& clientOptions,
80 std::string const& telemetryPackageName,
81 std::string const& telemetryPackageVersion,
82 std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>>&& perRetryPolicies,
83 std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>>&& perCallPolicies)
84 {
85 Azure::Core::Http::_internal::HttpSanitizer httpSanitizer(
86 clientOptions.Log.AllowedHttpQueryParameters, clientOptions.Log.AllowedHttpHeaders);
87
88 auto const& perCallClientPolicies = clientOptions.PerOperationPolicies;
89 auto const& perRetryClientPolicies = clientOptions.PerRetryPolicies;
90 // Adding 5/6 for:
91 // - TelemetryPolicy (if required)
92 // - RequestIdPolicy
93 // - RetryPolicy
94 // - LogPolicy
95 // - RequestActivityPolicy
96 // - TransportPolicy
97 auto pipelineSize = perCallClientPolicies.size() + perRetryClientPolicies.size()
98 + perRetryPolicies.size() + perCallPolicies.size() + 6;
99
100 m_policies.reserve(pipelineSize);
101
102 // service-specific per call policies
103 for (auto& policy : perCallPolicies)
104 {
105 m_policies.emplace_back(policy->Clone());
106 }
107
108 // Request Id
109 m_policies.emplace_back(
110 std::make_unique<Azure::Core::Http::Policies::_internal::RequestIdPolicy>());
111
112 // Telemetry (user-agent header)
113 m_policies.emplace_back(
114 std::make_unique<Azure::Core::Http::Policies::_internal::TelemetryPolicy>(
115 telemetryPackageName, telemetryPackageVersion, clientOptions.Telemetry));
116
117 // client-options per call policies.
118 for (auto& policy : perCallClientPolicies)
119 {
120 m_policies.emplace_back(policy->Clone());
121 }
122
123 // Retry policy
124 m_policies.emplace_back(std::make_unique<Azure::Core::Http::Policies::_internal::RetryPolicy>(
125 clientOptions.Retry));
126
127 // service-specific per retry policies.
128 for (auto& policy : perRetryPolicies)
129 {
130 m_policies.emplace_back(policy->Clone());
131 }
132 // client options per retry policies.
133 for (auto& policy : perRetryClientPolicies)
134 {
135 m_policies.emplace_back(policy->Clone());
136 }
137
138 // Add a request activity policy which will generate distributed traces for the pipeline.
139 m_policies.emplace_back(
140 std::make_unique<Azure::Core::Http::Policies::_internal::RequestActivityPolicy>(
141 httpSanitizer));
142
143 // logging - won't update request
144 m_policies.emplace_back(
145 std::make_unique<Azure::Core::Http::Policies::_internal::LogPolicy>(clientOptions.Log));
146
147 // transport
148 m_policies.emplace_back(
149 std::make_unique<Azure::Core::Http::Policies::_internal::TransportPolicy>(
150 clientOptions.Transport));
151 }
152
168 [[deprecated]] explicit HttpPipeline(
169 Azure::Core::_internal::ClientOptions const& clientOptions,
170 std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>>&& perRetryPolicies,
171 std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>>&& perCallPolicies)
172 : HttpPipeline(
173 clientOptions,
174 "security.attestation",
175 "1.0.0",
176 std::move(perRetryPolicies),
177 std::move(perCallPolicies))
178 {
179 }
180
189 explicit HttpPipeline(
190 std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>>&& policies)
191 : m_policies(std::move(policies))
192 {
193 if (m_policies.size() == 0)
194 {
195 throw std::invalid_argument("policies cannot be empty");
196 }
197 }
198
207 HttpPipeline(const HttpPipeline& other)
208 {
209 m_policies.reserve(other.m_policies.size());
210 for (auto& policy : other.m_policies)
211 {
212 m_policies.emplace_back(policy->Clone());
213 }
214 }
215
224 std::unique_ptr<Azure::Core::Http::RawResponse> Send(
226 Context const& context) const
227 {
228 // Accessing position zero is fine because pipeline must be constructed with at least one
229 // policy.
230 return m_policies[0]->Send(
231 request, Azure::Core::Http::Policies::NextHttpPolicy(0, m_policies), context);
232 }
233 };
234}}}} // namespace Azure::Core::Http::_internal
The next HTTP policy in the stack sequence of policies.
Definition policy.hpp:331
A request message from a client to a server.
Definition http.hpp:182
Base type for all client option types, exposes various common client options like Retry and Transport...
Context for canceling long running operations.
HTTP request and response functionality.
Compute the hash value for the input binary data, using SHA256, SHA384 and SHA512.
Definition azure_assert.hpp:57
HTTP transport policies, and their options.
Utilities to be used by HTTP transport implementations.