UserAgentPolicy Class

User-Agent Policy. Allows custom values to be added to the User-Agent header.

Constructor

UserAgentPolicy(base_user_agent: str | None = None, **kwargs: Any)

Parameters

Name Description
base_user_agent
str

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
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 python-[sdk_moniker] Python/[python_version] ([platform_version])

Methods

add_user_agent

Add value to current user agent with a space.

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.

add_user_agent(value: str) -> None

Parameters

Name Description
value
Required
str

value to add to user agent.

on_request

Modifies the User-Agent header before the request is sent.

on_request(request: PipelineRequest[HTTPRequestType]) -> None

Parameters

Name Description
request
Required
<xref:<xref:corehttp.runtime.pipeline#corehttp.runtime.pipeline.PipelineRequest>>

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
<xref:<xref:corehttp.runtime.pipeline#corehttp.runtime.pipeline.PipelineRequest>>

Request to be modified after returning from the policy.

response
Required
<xref:<xref:corehttp.runtime.pipeline#corehttp.runtime.pipeline.PipelineResponse>>

Pipeline response object

Attributes

user_agent

The current user agent value.

Returns

Type Description
str

The current user agent value.