Package com.azure.core.http.policy
Class AddHeadersPolicy
java.lang.Object
com.azure.core.http.policy.AddHeadersPolicy
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprocess(HttpPipelineCallContext context, HttpPipelineNextPolicy next) Processes provided request context and invokes the next policy.processSync(HttpPipelineCallContext context, HttpPipelineNextSyncPolicy next) Processes provided request context and invokes the next policy synchronously.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.azure.core.http.policy.HttpPipelinePolicy
getPipelinePosition
-
Constructor Details
-
AddHeadersPolicy
Creates a AddHeadersPolicy.- Parameters:
headers- The headers to add to outgoing requests.
-
-
Method Details
-
process
Description copied from interface:HttpPipelinePolicyProcesses provided request context and invokes the next policy.- Specified by:
processin interfaceHttpPipelinePolicy- Parameters:
context- The request context.next- The next policy to invoke.- Returns:
- A publisher that initiates the request upon subscription and emits a response on completion.
-
processSync
Description copied from interface:HttpPipelinePolicyProcesses provided request context and invokes the next policy synchronously.- Specified by:
processSyncin interfaceHttpPipelinePolicy- Parameters:
context- The request context.next- The next policy to invoke.- Returns:
- A publisher that initiates the request upon subscription and emits a response on completion.
-