Interface HttpPolicy

All Superinterfaces:
BasePolicy
All Known Subinterfaces:
HttpSecurityPolicy, Policy, SecurityPolicy

public interface HttpPolicy extends BasePolicy
A HttpPolicy allows to define the actions to apply during the different request execution phases of an HTTP request. A policy can override the default behavior (which is, doing nothing at all) to execute during request or response phase or on each message when the policy is able to work at message level. The implemented methods will be called depending on the execution phase:
  • Method Details

    • onRequest

      default io.reactivex.rxjava3.core.Completable onRequest(HttpPlainExecutionContext ctx)
      Define the actions to perform during the ExecutionPhase.REQUEST phase. The onRequest(HttpSimpleExecutionContext) method will be called during the policy chain construction. Once built, the subscription occurs and the execution is triggered. It is important that nothing must be executed before the subscription occurs as it could lead to important side effects.

      GOOD, the header is added during the execution, at subscription time.
           Completable onRequest(final HttpSimpleExecutionContext ctx) {
               return Completable.fromRunnable(() -> request.headers().set("X-DummyHeader", "dummy"));
           }
       
      BAD, the header is added during the build of the policy chain.
           Completable onRequest(final HttpSimpleExecutionContext ctx) {
               request.headers().set("X-DummyHeader", "dummy");
               return Completable.complete();
           }
       
      Parameters:
      ctx - the current request execution context allowing to access the request, response and attributes.
      Returns:
      a Completable that must complete when all the actions have been performed.
    • onResponse

      default io.reactivex.rxjava3.core.Completable onResponse(HttpPlainExecutionContext ctx)
      Define the actions to perform during the ExecutionPhase.RESPONSE phase. The onResponse(HttpSimpleExecutionContext) method will be called during the policy chain construction. Once built, the subscription occurs and the execution is triggered. It is important that nothing must be executed before the subscription occurs as it could lead to important side effects.

      GOOD, the header is added during the execution, at subscription time.
           Completable onResponse(final HttpSimpleExecutionContext ctx) {
               return Completable.fromRunnable(() -> response.headers().set("X-DummyHeader", "dummy"));
           }
       
      BAD, the header is added during the build of the policy chain.
           Completable onResponse(final HttpSimpleExecutionContext ctx) {
               response.headers().set("X-DummyHeader", "dummy");
               return Completable.complete();
           }
       
      Parameters:
      ctx - the current request execution context allowing to access the request, response and attributes.
      Returns:
      a Completable that must complete when all the actions have been performed.
    • onMessageRequest

      default io.reactivex.rxjava3.core.Completable onMessageRequest(HttpMessageExecutionContext ctx)
      Define the actions to perform during the ExecutionPhase.MESSAGE_REQUEST phase. The onMessageRequest(HttpMessageExecutionContext) method will be called during the policy chain construction. Once built, the subscription occurs and the execution is triggered. It is important that nothing must be executed before the subscription occurs as it could lead to important side effects.

      GOOD, the header is added during the execution, at subscription time.
           Completable onMessageRequest(final HttpMessageExecutionContext ctx) {
               return Completable.fromRunnable(() -> request.headers().set("X-DummyHeader", "dummy"));
           }
       
      BAD, the header is added during the build of the policy chain.
           Completable onMessageRequest(final HttpMessageExecutionContext ctx) {
               request.headers().set("X-DummyHeader", "dummy");
               return Completable.complete();
           }
       
      Parameters:
      ctx - the current request execution context allowing to access the request, response and attributes.
      Returns:
      a Completable that must complete when all the actions have been performed.
    • onMessageResponse

      default io.reactivex.rxjava3.core.Completable onMessageResponse(HttpMessageExecutionContext ctx)
      Define the actions to perform during the ExecutionPhase.MESSAGE_RESPONSE phase. The onMessageResponse(HttpMessageExecutionContext) method will be called during the policy chain construction. Once built, the subscription occurs and the execution is triggered. It is important that nothing must be executed before the subscription occurs as it could lead to important side effects.

      GOOD, the header is added during the execution, at subscription time.
           Completable onMessageResponse(final HttpMessageExecutionContext ctx) {
               return Completable.fromRunnable(() -> response.headers().set("X-DummyHeader", "dummy"));
           }
       
      BAD, the header is added during the build of the policy chain.
           Completable onMessageResponse(final HttpMessageExecutionContext ctx) {
               response.headers().set("X-DummyHeader", "dummy");
               return Completable.complete();
           }
       
      Parameters:
      ctx - the current request execution context allowing to access the request, response and attributes.
      Returns:
      a Completable that must complete when all the actions have been performed.