Interface HttpPolicy
- All Superinterfaces:
BasePolicy
- All Known Subinterfaces:
HttpSecurityPolicy,Policy,SecurityPolicy
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 Summary
Modifier and TypeMethodDescriptiondefault io.reactivex.rxjava3.core.CompletableDefine the actions to perform during theExecutionPhase.MESSAGE_REQUESTphase.default io.reactivex.rxjava3.core.CompletableDefine the actions to perform during theExecutionPhase.MESSAGE_RESPONSEphase.default io.reactivex.rxjava3.core.CompletableDefine the actions to perform during theExecutionPhase.REQUESTphase.default io.reactivex.rxjava3.core.CompletableDefine the actions to perform during theExecutionPhase.RESPONSEphase.Methods inherited from interface io.gravitee.gateway.reactive.api.policy.base.BasePolicy
id
-
Method Details
-
onRequest
Define the actions to perform during theExecutionPhase.REQUESTphase. TheonRequest(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
Completablethat must complete when all the actions have been performed.
-
onResponse
Define the actions to perform during theExecutionPhase.RESPONSEphase. TheonResponse(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
Completablethat must complete when all the actions have been performed.
-
onMessageRequest
Define the actions to perform during theExecutionPhase.MESSAGE_REQUESTphase. TheonMessageRequest(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
Completablethat must complete when all the actions have been performed.
-
onMessageResponse
Define the actions to perform during theExecutionPhase.MESSAGE_RESPONSEphase. TheonMessageResponse(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
Completablethat must complete when all the actions have been performed.
-