Package com.azure.core.http.policy
Class UserAgentPolicy
java.lang.Object
com.azure.core.http.policy.UserAgentPolicy
- All Implemented Interfaces:
HttpPipelinePolicy
Pipeline policy that adds "User-Agent" header to a request.
The format for the "User-Agent" string is outlined in
Azure Core: Telemetry policy.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKey forContextto add a value which will be appended to the User-Agent supplied in this policy in an ad-hoc manner.static final StringKey forContextto add a value which will override the User-Agent supplied in this policy in an ad-hoc manner. -
Constructor Summary
ConstructorsConstructorDescriptionCreates aUserAgentPolicywith a default user agent string.UserAgentPolicy(String userAgent) Creates a UserAgentPolicy withuserAgentas the header value.UserAgentPolicy(String sdkName, String sdkVersion, Configuration configuration, ServiceVersion version) Deprecated.UserAgentPolicy(String applicationId, String sdkName, String sdkVersion, Configuration configuration) Creates a UserAgentPolicy with thesdkNameandsdkVersionin the User-Agent header value. -
Method Summary
Modifier and TypeMethodDescriptionprocess(HttpPipelineCallContext context, HttpPipelineNextPolicy next) Updates the "User-Agent" header with the value supplied in the policy.processSync(HttpPipelineCallContext context, HttpPipelineNextSyncPolicy next) Updates the "User-Agent" header with the value supplied in the policy synchronously.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.azure.core.http.policy.HttpPipelinePolicy
getPipelinePosition
-
Field Details
-
OVERRIDE_USER_AGENT_CONTEXT_KEY
Key forContextto add a value which will override the User-Agent supplied in this policy in an ad-hoc manner.- See Also:
-
APPEND_USER_AGENT_CONTEXT_KEY
Key forContextto add a value which will be appended to the User-Agent supplied in this policy in an ad-hoc manner.- See Also:
-
-
Constructor Details
-
UserAgentPolicy
public UserAgentPolicy()Creates aUserAgentPolicywith a default user agent string. -
UserAgentPolicy
Creates a UserAgentPolicy withuserAgentas the header value. IfuserAgentisnull, then the default user agent value is used.- Parameters:
userAgent- The user agent string to add to request headers.
-
UserAgentPolicy
public UserAgentPolicy(String applicationId, String sdkName, String sdkVersion, Configuration configuration) Creates a UserAgentPolicy with thesdkNameandsdkVersionin the User-Agent header value.If the passed configuration contains true for AZURE_TELEMETRY_DISABLED the platform information won't be included in the user agent.
- Parameters:
applicationId- User specified application Id.sdkName- Name of the client library.sdkVersion- Version of the client library.configuration- Configuration store that will be checked forConfiguration.PROPERTY_AZURE_TELEMETRY_DISABLED. Ifnullis passed theglobal configurationwill be checked.
-
UserAgentPolicy
@Deprecated public UserAgentPolicy(String sdkName, String sdkVersion, Configuration configuration, ServiceVersion version) Deprecated.Creates a UserAgentPolicy with thesdkNameandsdkVersionin the User-Agent header value.If the passed configuration contains true for AZURE_TELEMETRY_DISABLED the platform information won't be included in the user agent.
- Parameters:
sdkName- Name of the client library.sdkVersion- Version of the client library.version-ServiceVersionof the service to be used when making requests.configuration- Configuration store that will be checked forConfiguration.PROPERTY_AZURE_TELEMETRY_DISABLED. Ifnullis passed theglobal configurationwill be checked.
-
-
Method Details
-
process
Updates the "User-Agent" header with the value supplied in the policy.The
contextwill be checked forOverride-User-AgentandAppend-User-Agent.Override-User-Agentwill take precedence over the value supplied in the policy,Append-User-Agentwill be appended to the value supplied in the policy.- Specified by:
processin interfaceHttpPipelinePolicy- Parameters:
context- request contextnext- The next policy to invoke.- Returns:
- A publisher that initiates the request upon subscription and emits a response on completion.
-
processSync
Updates the "User-Agent" header with the value supplied in the policy synchronously.The
contextwill be checked forOverride-User-AgentandAppend-User-Agent.Override-User-Agentwill take precedence over the value supplied in the policy,Append-User-Agentwill be appended to the value supplied in the policy.- Specified by:
processSyncin interfaceHttpPipelinePolicy- Parameters:
context- request contextnext- The next policy to invoke.- Returns:
- A response.
-
UserAgentPolicy(String, String, String, Configuration)instead.