Class PortPolicy

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

public class PortPolicy extends Object implements HttpPipelinePolicy
The PortPolicy class is an implementation of the HttpPipelinePolicy interface. This policy is used to add a specific port to each HttpRequest.

This class is useful when you need to set a specific port for all requests in a pipeline. It ensures that the port is set correctly for each request.

Code sample:

In this example, a PortPolicy is created with a port of 8080 and an overwrite flag set to true. The policy can then be added to the pipeline. Once added to the pipeline, all requests will have their port set to 8080 by the PortPolicy.

 PortPolicy portPolicy = new PortPolicy(8080, true);
 
See Also:
  • Constructor Details

    • PortPolicy

      public PortPolicy(int port, boolean overwrite)
      Creates a new PortPolicy object.
      Parameters:
      port - The port to set.
      overwrite - Whether to overwrite a HttpRequest's port if it already has one.
  • Method Details