UserAgentPolicy Class
- java.
lang. Object - com.
azure. core. http. policy. UserAgentPolicy
- com.
Implements
public class UserAgentPolicy
implements HttpPipelinePolicy
The UserAgentPolicy
class is an implementation of the HttpPipelinePolicy interface. This policy is used to add a "User-Agent" header to each HttpRequest
.
This class is useful when you need to add a specific "User-Agent" header for all requests in a pipeline. It ensures that the "User-Agent" header is set correctly for each request. The "User-Agent" header is used to provide the server with information about the software used by the client.
Code sample:
In this example, a UserAgentPolicy
is created with a "User-Agent" header value of "MyApp/1.0". Once added to the pipeline, requests will have their "User-Agent" header set to "MyApp/1.0" by the UserAgentPolicy
.
UserAgentPolicy userAgentPolicy = new UserAgentPolicy("MyApp/1.0");
Field Summary
Modifier and Type | Field and Description |
---|---|
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. |
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. |
Constructor Summary
Constructor | Description |
---|---|
UserAgentPolicy() |
Creates a UserAgentPolicy with a default user agent string. |
UserAgentPolicy(String userAgent) |
Creates a User |
UserAgentPolicy(String sdkName, String sdkVersion, Configuration configuration, ServiceVersion version) |
Deprecated
Use UserAgentPolicy(String applicationId, String sdkName, String sdkVersion, Configuration configuration) instead.
Creates a User |
UserAgentPolicy(String applicationId, String sdkName, String sdkVersion, Configuration configuration) |
Creates a User |
Method Summary
Modifier and Type | Method and Description |
---|---|
Mono<Http |
process(HttpPipelineCallContext context, HttpPipelineNextPolicy next)
Updates the "User-Agent" header with the value supplied in the policy. |
Http |
processSync(HttpPipelineCallContext context, HttpPipelineNextSyncPolicy next)
Updates the "User-Agent" header with the value supplied in the policy synchronously. |
Methods inherited from java.lang.Object
Field Details
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.
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.
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:
UserAgentPolicy
@Deprecated
public UserAgentPolicy(String sdkName, String sdkVersion, Configuration configuration, ServiceVersion version)
Deprecated
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:
null
is passed the getGlobalConfiguration() will be checked.
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:
null
is passed the getGlobalConfiguration() will be checked.
Method Details
process
public Mono
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.
Parameters:
Returns:
processSync
public HttpResponse processSync(HttpPipelineCallContext context, HttpPipelineNextSyncPolicy next)
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.
Parameters:
Returns:
Applies to
Azure SDK for Java