17 #include "azure/core/internal/input_sanitizer.hpp"
41 namespace Azure {
namespace Core {
namespace Http {
namespace Policies {
44 std::shared_ptr<HttpTransport> GetTransportAdapter();
90 std::chrono::milliseconds
RetryDelay = std::chrono::seconds(4);
151 std::shared_ptr<HttpTransport>
Transport = _detail::GetTransportAdapter();
178 virtual std::unique_ptr<RawResponse>
Send(
181 Context const& context)
const = 0;
193 virtual std::unique_ptr<HttpPolicy>
Clone()
const = 0;
235 const size_t m_index;
236 const std::vector<std::unique_ptr<HttpPolicy>>& m_policies;
247 explicit NextHttpPolicy(
size_t index,
const std::vector<std::unique_ptr<HttpPolicy>>& policies)
248 : m_index(index), m_policies(policies)
264 namespace _internal {
270 class TransportPolicy final :
public HttpPolicy {
272 TransportOptions m_options;
280 explicit TransportPolicy(TransportOptions options = TransportOptions())
281 : m_options(std::move(options))
285 std::unique_ptr<HttpPolicy> Clone()
const override
287 return std::make_unique<TransportPolicy>(*
this);
290 std::unique_ptr<RawResponse> Send(
292 NextHttpPolicy nextPolicy,
293 Context
const& context)
const override;
300 #if !defined(TESTING_BUILD)
303 :
public HttpPolicy {
305 RetryOptions m_retryOptions;
313 explicit RetryPolicy(RetryOptions options) : m_retryOptions(std::move(options)) {}
315 std::unique_ptr<HttpPolicy>
Clone()
const override
317 return std::make_unique<RetryPolicy>(*
this);
320 std::unique_ptr<RawResponse>
Send(
322 NextHttpPolicy nextPolicy,
323 Context
const& context)
const final;
336 static int32_t GetRetryCount(Context
const& context);
339 virtual bool ShouldRetryOnTransportFailure(
340 RetryOptions
const& retryOptions,
342 std::chrono::milliseconds& retryAfter,
343 double jitterFactor = -1)
const;
345 virtual bool ShouldRetryOnResponse(
346 RawResponse
const& response,
347 RetryOptions
const& retryOptions,
349 std::chrono::milliseconds& retryAfter,
350 double jitterFactor = -1)
const;
359 class RequestIdPolicy final :
public HttpPolicy {
361 constexpr
static const char* RequestIdHeader =
"x-ms-client-request-id";
368 explicit RequestIdPolicy() {}
370 std::unique_ptr<HttpPolicy>
Clone()
const override
372 return std::make_unique<RequestIdPolicy>(*
this);
375 std::unique_ptr<RawResponse>
Send(
377 NextHttpPolicy nextPolicy,
378 Context
const& context)
const override
382 request.SetHeader(RequestIdHeader, uuid);
383 return nextPolicy.Send(request, context);
395 class RequestActivityPolicy final :
public HttpPolicy {
397 Azure::Core::_internal::InputSanitizer m_inputSanitizer;
409 explicit RequestActivityPolicy(Azure::Core::_internal::InputSanitizer
const& inputSanitizer)
410 : m_inputSanitizer(inputSanitizer)
414 std::unique_ptr<HttpPolicy>
Clone()
const override
416 return std::make_unique<RequestActivityPolicy>(*
this);
419 std::unique_ptr<RawResponse>
Send(
421 NextHttpPolicy nextPolicy,
422 Context
const& context)
const override;
432 class TelemetryPolicy final :
public HttpPolicy {
434 std::string
const m_telemetryId;
436 static std::string BuildTelemetryId(
437 std::string
const& componentName,
438 std::string
const& componentVersion,
439 std::string
const& applicationId);
449 explicit TelemetryPolicy(
450 std::string
const& componentName,
451 std::string
const& componentVersion,
452 TelemetryOptions options = TelemetryOptions())
453 : m_telemetryId(BuildTelemetryId(componentName, componentVersion, options.ApplicationId))
457 std::unique_ptr<HttpPolicy>
Clone()
const override
459 return std::make_unique<TelemetryPolicy>(*
this);
462 std::unique_ptr<RawResponse>
Send(
464 NextHttpPolicy nextPolicy,
465 Context
const& context)
const override;
472 class BearerTokenAuthenticationPolicy final :
public HttpPolicy {
474 std::shared_ptr<Credentials::TokenCredential const>
const m_credential;
475 Credentials::TokenRequestContext m_tokenRequestContext;
477 mutable Credentials::AccessToken m_accessToken;
478 mutable std::mutex m_accessTokenMutex;
480 BearerTokenAuthenticationPolicy(BearerTokenAuthenticationPolicy
const&) =
delete;
481 void operator=(BearerTokenAuthenticationPolicy
const&) =
delete;
490 explicit BearerTokenAuthenticationPolicy(
491 std::shared_ptr<Credentials::TokenCredential const> credential,
492 Credentials::TokenRequestContext tokenRequestContext)
493 : m_credential(std::move(credential)),
494 m_tokenRequestContext(std::move(tokenRequestContext))
498 std::unique_ptr<HttpPolicy>
Clone()
const override
500 return std::make_unique<BearerTokenAuthenticationPolicy>(
501 m_credential, m_tokenRequestContext);
504 std::unique_ptr<RawResponse>
Send(
506 NextHttpPolicy nextPolicy,
507 Context
const& context)
const override;
516 class LogPolicy final :
public HttpPolicy {
517 LogOptions m_options;
518 Azure::Core::_internal::InputSanitizer m_inputSanitizer;
525 explicit LogPolicy(LogOptions options)
526 : m_options(std::move(options)),
527 m_inputSanitizer(m_options.AllowedHttpQueryParameters, m_options.AllowedHttpHeaders)
531 std::unique_ptr<HttpPolicy>
Clone()
const override
533 return std::make_unique<LogPolicy>(*
this);
536 std::unique_ptr<RawResponse>
Send(
538 NextHttpPolicy nextPolicy,
539 Context
const& context)
const override;