UserAgentPolicy Class
User-Agent Policy. Allows custom values to be added to the User-Agent header.
- Inheritance
-
azure.core.pipeline.policies._base.SansIOHTTPPolicyUserAgentPolicy
Constructor
UserAgentPolicy(base_user_agent: str | None = None, **kwargs: Any)
Parameters
Name | Description |
---|---|
base_user_agent
|
Sets the base user agent value. Default value: None
|
Keyword-Only Parameters
Name | Description |
---|---|
user_agent_overwrite
|
Overwrites User-Agent when True. Defaults to False. |
user_agent_use_env
|
Gets user-agent from environment. Defaults to True. |
user_agent
|
If specified, this will be added in front of the user agent string. |
sdk_moniker
|
If specified, the user agent string will be azsdk-python-[sdk_moniker] Python/[python_version] ([platform_version]) |
Examples
Configuring a user agent policy.
from azure.core.pipeline.policies import UserAgentPolicy
user_agent_policy = UserAgentPolicy()
# The user-agent policy allows you to append a custom value to the header.
user_agent_policy.add_user_agent("CustomValue")
# You can also pass in a custom value per operation to append to the end of the user-agent.
# This can be used together with the policy configuration to append multiple values.
policies = [
redirect_policy,
user_agent_policy,
]
client: PipelineClient[HttpRequest, HttpResponse] = PipelineClient(base_url=url, policies=policies)
request = HttpRequest("GET", url)
pipeline_response = client._pipeline.run(request, user_agent="AnotherValue")
Methods
add_user_agent |
Add value to current user agent with a space. :param str value: value to add to user agent. |
on_exception |
Is executed if an exception is raised while executing the next policy. This method is executed inside the exception handler. |
on_request |
Modifies the User-Agent header before the request is sent. |
on_response |
Is executed after the request comes back from the policy. |
add_user_agent
Add value to current user agent with a space. :param str value: value to add to user agent.
add_user_agent(value: str) -> None
Parameters
Name | Description |
---|---|
value
Required
|
|
on_exception
Is executed if an exception is raised while executing the next policy.
This method is executed inside the exception handler.
on_exception(request: PipelineRequest[HTTPRequestType]) -> None
Parameters
Name | Description |
---|---|
request
Required
|
The Pipeline request object |
on_request
Modifies the User-Agent header before the request is sent.
on_request(request: PipelineRequest[HttpRequest | HttpRequest]) -> None
Parameters
Name | Description |
---|---|
request
Required
|
The PipelineRequest object |
on_response
Is executed after the request comes back from the policy.
on_response(request: PipelineRequest[HTTPRequestType], response: PipelineResponse[HTTPRequestType, HTTPResponseType]) -> None | Awaitable[None]
Parameters
Name | Description |
---|---|
request
Required
|
Request to be modified after returning from the policy. |
response
Required
|
Pipeline response object |
Attributes
user_agent
Azure SDK for Python