Class UserAgentPolicy

java.lang.Object
com.azure.core.http.policy.UserAgentPolicy
All Implemented Interfaces:
HttpPipelinePolicy

public class UserAgentPolicy extends Object implements 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 Details

    • OVERRIDE_USER_AGENT_CONTEXT_KEY

      public static final String OVERRIDE_USER_AGENT_CONTEXT_KEY
      Key for Context to 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

      public static final String APPEND_USER_AGENT_CONTEXT_KEY
      Key for Context to 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 a UserAgentPolicy with a default user agent string.
    • UserAgentPolicy

      public UserAgentPolicy(String userAgent)
      Creates a UserAgentPolicy with userAgent as the header value. If userAgent is null, 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 the sdkName and sdkVersion in 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 for Configuration.PROPERTY_AZURE_TELEMETRY_DISABLED. If null is passed the global configuration will be checked.
    • UserAgentPolicy

      @Deprecated public UserAgentPolicy(String sdkName, String sdkVersion, Configuration configuration, ServiceVersion version)
      Creates a UserAgentPolicy with the sdkName and sdkVersion in 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 - ServiceVersion of the service to be used when making requests.
      configuration - Configuration store that will be checked for Configuration.PROPERTY_AZURE_TELEMETRY_DISABLED. If null is passed the global configuration will be checked.
  • Method Details

    • process

      Updates the "User-Agent" header with the value supplied in the policy.

      The context will be checked for Override-User-Agent and Append-User-Agent. Override-User-Agent will take precedence over the value supplied in the policy, Append-User-Agent will be appended to the value supplied in the policy.

      Specified by:
      process in interface HttpPipelinePolicy
      Parameters:
      context - request context
      next - 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 context will be checked for Override-User-Agent and Append-User-Agent. Override-User-Agent will take precedence over the value supplied in the policy, Append-User-Agent will be appended to the value supplied in the policy.

      Specified by:
      processSync in interface HttpPipelinePolicy
      Parameters:
      context - request context
      next - The next policy to invoke.
      Returns:
      A response.