HeadersPolicy Class

A simple policy that sends the given headers with the request.

This will overwrite any headers already defined in the request. Headers can be configured up front, where any custom headers will be applied to all outgoing operations, and additional headers can also be added dynamically per operation.

Constructor

HeadersPolicy(base_headers: Dict[str, str] | None = None, **kwargs: Any)

Parameters

Name Description
base_headers

Headers to send with the request.

Default value: None

Methods

add_header

Add a header to the configuration to be applied to all requests.

on_request

Updates with the given headers before sending the request to the next policy.

on_response

Is executed after the request comes back from the policy.

add_header

Add a header to the configuration to be applied to all requests.

add_header(key: str, value: str) -> None

Parameters

Name Description
key
Required
str

The header.

value
Required
str

The header's value.

on_request

Updates with the given headers before sending the request to the next policy.

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

headers

The current headers collection.

Returns

Type Description

The current headers collection.