Class AddHeadersPolicy

java.lang.Object
com.azure.core.http.policy.AddHeadersPolicy
All Implemented Interfaces:
HttpPipelinePolicy

public class AddHeadersPolicy extends Object implements HttpPipelinePolicy

The AddHeadersPolicy class is an implementation of the HttpPipelinePolicy interface. This policy is used to add a set of headers to all outgoing HTTP requests.

This class is useful when there are certain headers that should be included in all requests. For example, you might want to include a "User-Agent" header in all requests to identify your application, or a "Content-Type" header to specify the format of the request body.

Code sample:

In this example, the AddHeadersPolicy is created from the specified headers. The policy can be added to the pipeline and the requests sent will include the headers specified in the AddHeadersPolicy.

 HttpHeaders headers = new HttpHeaders();
 headers.put("User-Agent", "MyApp/1.0");
 headers.put("Content-Type", "application/json");

 new AddHeadersPolicy(headers);
 
See Also:
  • Constructor Details

    • AddHeadersPolicy

      public AddHeadersPolicy(HttpHeaders headers)
      Creates a AddHeadersPolicy.
      Parameters:
      headers - The headers to add to outgoing requests.
  • Method Details