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.

Inheritance
azure.core.pipeline.policies._base.SansIOHTTPPolicy
HeadersPolicy

Constructor

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

Parameters

base_headers
dict
default value: None

Headers to send with the request.

Examples

Configuring a headers policy.


   from azure.core.pipeline.policies import HeadersPolicy

   headers_policy = HeadersPolicy()
   headers_policy.add_header('CustomValue', 'Foo')

   # Or headers can be added per operation. These headers will supplement existing headers
   # or those defined in the config headers policy. They will also overwrite existing
   # identical headers.
   policies.append(headers_policy)
   client = PipelineClient(base_url=url, policies=policies)
   request = client.get(url)
   pipeline_response = client._pipeline.run(request, headers={'CustomValue': 'Bar'})

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.

add_header

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

add_header(key, value)

Parameters

key
str
Required

The header.

value
str
Required

The header's value.

on_request

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

on_request(request: azure.core.pipeline.PipelineRequest) -> None

Parameters

request
PipelineRequest
Required

The PipelineRequest object

Attributes

headers

The current headers collection.