17 #include "azure/core/internal/http/http_sanitizer.hpp"
41 namespace Azure {
namespace Core {
namespace Http {
namespace Policies {
43 struct TransportOptions;
45 std::shared_ptr<HttpTransport> GetTransportAdapter(TransportOptions
const& transportOptions);
47 AZ_CORE_DLLEXPORT extern std::set<std::string>
const g_defaultAllowedHttpQueryParameters;
92 std::chrono::milliseconds
RetryDelay = std::chrono::milliseconds(800);
234 virtual std::unique_ptr<RawResponse>
Send(
237 Context const& context)
const = 0;
249 virtual std::unique_ptr<HttpPolicy>
Clone()
const = 0;
291 const size_t m_index;
292 const std::vector<std::unique_ptr<HttpPolicy>>& m_policies;
303 explicit NextHttpPolicy(
size_t index,
const std::vector<std::unique_ptr<HttpPolicy>>& policies)
304 : m_index(index), m_policies(policies)
320 namespace _internal {
326 class TransportPolicy final :
public HttpPolicy {
328 TransportOptions m_options;
336 explicit TransportPolicy(TransportOptions
const& options = TransportOptions());
338 std::unique_ptr<HttpPolicy> Clone()
const override
340 return std::make_unique<TransportPolicy>(*
this);
343 std::unique_ptr<RawResponse> Send(
345 NextHttpPolicy nextPolicy,
346 Context const& context)
const override;
353 #if !defined(TESTING_BUILD)
356 :
public HttpPolicy {
358 RetryOptions m_retryOptions;
366 explicit RetryPolicy(RetryOptions options) : m_retryOptions(std::move(options)) {}
368 std::unique_ptr<HttpPolicy> Clone()
const override
370 return std::make_unique<RetryPolicy>(*
this);
373 std::unique_ptr<RawResponse>
Send(
375 NextHttpPolicy nextPolicy,
376 Context
const& context)
const final;
389 static int32_t GetRetryCount(Context
const& context);
392 virtual bool ShouldRetryOnTransportFailure(
393 RetryOptions
const& retryOptions,
395 std::chrono::milliseconds& retryAfter,
396 double jitterFactor = -1)
const;
398 virtual bool ShouldRetryOnResponse(
399 RawResponse
const& response,
400 RetryOptions
const& retryOptions,
402 std::chrono::milliseconds& retryAfter,
403 double jitterFactor = -1)
const;
412 class RequestIdPolicy final :
public HttpPolicy {
414 constexpr
static const char* RequestIdHeader =
"x-ms-client-request-id";
421 explicit RequestIdPolicy() {}
423 std::unique_ptr<HttpPolicy>
Clone()
const override
425 return std::make_unique<RequestIdPolicy>(*
this);
428 std::unique_ptr<RawResponse>
Send(
430 NextHttpPolicy nextPolicy,
431 Context
const& context)
const override
433 if (!request.GetHeader(RequestIdHeader).HasValue())
436 request.SetHeader(RequestIdHeader, uuid);
439 return nextPolicy.Send(request, context);
451 class RequestActivityPolicy final :
public HttpPolicy {
453 Azure::Core::Http::_internal::HttpSanitizer m_httpSanitizer;
465 explicit RequestActivityPolicy(
466 Azure::Core::Http::_internal::HttpSanitizer
const& httpSanitizer)
467 : m_httpSanitizer(httpSanitizer)
471 std::unique_ptr<HttpPolicy>
Clone()
const override
473 return std::make_unique<RequestActivityPolicy>(*
this);
476 std::unique_ptr<RawResponse>
Send(
478 NextHttpPolicy nextPolicy,
479 Context
const& context)
const override;
495 class TelemetryPolicy final :
public HttpPolicy {
497 std::string
const m_telemetryId;
507 explicit TelemetryPolicy(
508 std::string
const& packageName,
509 std::string
const& packageVersion,
510 TelemetryOptions options = TelemetryOptions())
511 : m_telemetryId(
Azure::Core::Http::_detail::UserAgentGenerator::GenerateUserAgent(
514 options.ApplicationId))
518 std::unique_ptr<HttpPolicy>
Clone()
const override
520 return std::make_unique<TelemetryPolicy>(*
this);
523 std::unique_ptr<RawResponse>
Send(
525 NextHttpPolicy nextPolicy,
526 Context
const& context)
const override;
533 class BearerTokenAuthenticationPolicy final :
public HttpPolicy {
535 std::shared_ptr<Credentials::TokenCredential const>
const m_credential;
536 Credentials::TokenRequestContext m_tokenRequestContext;
538 mutable Credentials::AccessToken m_accessToken;
539 mutable std::mutex m_accessTokenMutex;
541 BearerTokenAuthenticationPolicy(BearerTokenAuthenticationPolicy
const&) =
delete;
542 void operator=(BearerTokenAuthenticationPolicy
const&) =
delete;
551 explicit BearerTokenAuthenticationPolicy(
552 std::shared_ptr<Credentials::TokenCredential const> credential,
553 Credentials::TokenRequestContext tokenRequestContext)
554 : m_credential(std::move(credential)),
555 m_tokenRequestContext(std::move(tokenRequestContext))
559 std::unique_ptr<HttpPolicy>
Clone()
const override
561 return std::make_unique<BearerTokenAuthenticationPolicy>(
562 m_credential, m_tokenRequestContext);
565 std::unique_ptr<RawResponse>
Send(
567 NextHttpPolicy nextPolicy,
568 Context
const& context)
const override;
577 class LogPolicy final :
public HttpPolicy {
578 LogOptions m_options;
579 Azure::Core::Http::_internal::HttpSanitizer m_httpSanitizer;
586 explicit LogPolicy(LogOptions options)
587 : m_options(std::move(options)),
588 m_httpSanitizer(m_options.AllowedHttpQueryParameters, m_options.AllowedHttpHeaders)
592 std::unique_ptr<HttpPolicy>
Clone()
const override
594 return std::make_unique<LogPolicy>(*
this);
597 std::unique_ptr<RawResponse>
Send(
599 NextHttpPolicy nextPolicy,
600 Context
const& context)
const override;
A map<string, string> with case-insensitive key comparison.
A context is a node within a tree that represents deadlines and key/value pairs.
Definition: context.hpp:45
HTTP policy base class.
Definition: policy.hpp:218
HttpPolicy & operator=(const HttpPolicy &other)=default
Assigns this HttpPolicy to copy the other.
virtual ~HttpPolicy()
Destructs HttpPolicy.
Definition: policy.hpp:243
HttpPolicy()=default
Constructs a default instance of HttpPolicy.
virtual std::unique_ptr< RawResponse > Send(Request &request, NextHttpPolicy nextPolicy, Context const &context) const =0
Applies this HTTP policy.
virtual std::unique_ptr< HttpPolicy > Clone() const =0
Creates a clone of this HttpPolicy.
HttpPolicy(HttpPolicy &&other)=default
Contructs HttpPolicy by moving other HttpPolicy.
HttpPolicy(const HttpPolicy &other)=default
Constructs a copy of other HttpPolicy.
The next HTTP policy in the stack sequence of policies.
Definition: policy.hpp:290
NextHttpPolicy(size_t index, const std::vector< std::unique_ptr< HttpPolicy >> &policies)
Constructs an abstraction representing a next line in the stack sequence of policies,...
Definition: policy.hpp:303
std::unique_ptr< RawResponse > Send(Request &request, Context const &context)
Applies this HTTP policy.
Definition: policy.cpp:13
A request message from a client to a server.
Definition: http.hpp:176
std::string ToString()
Gets Uuid as a string.
Definition: uuid.cpp:20
static Uuid CreateUuid()
Creates a new random UUID.
Definition: uuid.cpp:50
Context for canceling long running operations.
Credentials used for authentication with many (not all) Azure SDK client libraries.
#define AZ_CORE_DLLEXPORT
Applies DLL export attribute, when applicable.
Definition: dll_import_export.hpp:93
HTTP request and response functionality.
@ BadGateway
HTTP 502 Bad Gateway.
@ ServiceUnavailable
HTTP 503 Unavailable.
@ RequestTimeout
HTTP 408 Request Timeout.
@ GatewayTimeout
HTTP 504 Gateway Timeout.
@ InternalServerError
HTTP 500 Internal Server Error.
std::set< std::string, _internal::StringExtensions::CaseInsensitiveComparator > CaseInsensitiveSet
A type alias of std::set<std::string> with case-insensitive element comparison.
Definition: case_insensitive_containers.hpp:31
Azure SDK abstractions.
Definition: azure_assert.hpp:55
std::shared_ptr< Azure::Core::Http::HttpTransport > AzureSdkGetCustomHttpTransport()
Log options that parameterize the information being logged.
Definition: policy.hpp:120
std::set< std::string > AllowedHttpQueryParameters
HTTP query parameter names that are allowed to be logged.
Definition: policy.hpp:125
CaseInsensitiveSet AllowedHttpHeaders
HTTP header names that are allowed to be logged.
Definition: policy.hpp:131
The set of options that can be specified to influence how retry attempts are made,...
Definition: policy.hpp:80
std::chrono::milliseconds RetryDelay
The minimum permissible delay between retry attempts.
Definition: policy.hpp:92
int32_t MaxRetries
The maximum number of retry attempts before giving up.
Definition: policy.hpp:85
std::chrono::milliseconds MaxRetryDelay
The maximum permissible delay between retry attempts.
Definition: policy.hpp:99
std::set< HttpStatusCode > StatusCodes
The HTTP status codes that indicate when an operation should be retried.
Definition: policy.hpp:105
Telemetry options, used to configure telemetry parameters.
Definition: policy.hpp:56
std::string ApplicationId
The Application ID is the last part of the user agent for telemetry.
Definition: policy.hpp:64
std::shared_ptr< Azure::Core::Tracing::TracerProvider > TracingProvider
Specifies the default distributed tracing provider to use for this client. By default,...
Definition: policy.hpp:70
HTTP transport options parameterize the HTTP transport adapter being used.
Definition: policy.hpp:138
std::shared_ptr< HttpTransport > Transport
Azure::Core::Http::HttpTransport that the transport policy will use to send and receive requests and ...
Definition: policy.hpp:207
Azure::Nullable< std::string > ProxyPassword
The password to use when authenticating with the proxy server.
Definition: policy.hpp:164
bool EnableCertificateRevocationListCheck
Enable TLS Certificate validation against a certificate revocation list.
Definition: policy.hpp:174
std::string ExpectedTlsRootCertificate
Base64 encoded DER representation of an X.509 certificate expected in the certificate chain used in T...
Definition: policy.hpp:187
Azure::Nullable< std::string > HttpProxy
The URL for the proxy server to use for this connection.
Definition: policy.hpp:148
Azure::Nullable< std::string > ProxyUserName
The username to use when authenticating with the proxy server.
Definition: policy.hpp:156
Utilities to be used by HTTP transport implementations.
HTTP pipeline is a stack of HTTP policies.
Universally unique identifier.