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: Optional[str] = None, **kwargs: Any)
Parameters
- user_agent_overwrite
- bool
Overwrites User-Agent when True. Defaults to False.
- user_agent_use_env
- bool
Gets user-agent from environment. Defaults to True.
- user_agent
- str
If specified, this will be added in front of the user agent string.
- sdk_moniker
- str
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(base_url=url, policies=policies)
request = client.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_request |
Modifies the User-Agent header before the request is sent. |
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
- value
on_request
Modifies the User-Agent header before the request is sent.
on_request(request: azure.core.pipeline.PipelineRequest) -> None
Parameters
Attributes
user_agent
The current user agent value.
Feedback
Submit and view feedback for