vertx-web
vertx-web copied to clipboard
BodyHandler should not be added before the ProxyHandler
See #2614
Added documentation and make ProxyHandler fail fast if the BodyHandler has been seen.
Thanks @pmlopes for the feedback! I have a couple of comments:
1/ I think ProxyHandler should extend ProtocolUpgradeHandler rather than PlatformHandler because the user might want to add a security handler before.
2/ Perhaps we should keep both mechanisms because a handler having a priority lower than BODY is not protected in the case of the following setup:
router.post().handler(BodyHandler.create());
router.route("/product").handler(ProxyHandler.create(productServiceProxy));
Or am I missing something?
@tsegismont yeap, that's correct, platform wouldn't allow anything before (other than another platform) protocol upgrade is a better suited interface. The unspoken contract is that if the handler performs any async call and doesn't terminate the request, it should pause/resume the request to ensure that once a body handler is on the route the body isn't lost like here:
https://github.com/vert-x3/vertx-web/blob/bcf9dea0540121405fff08f6f0c8b881ede634d1/vertx-web/src/main/java/io/vertx/ext/web/handler/impl/AuthenticationHandlerImpl.java#L58-L61
and
https://github.com/vert-x3/vertx-web/blob/bcf9dea0540121405fff08f6f0c8b881ede634d1/vertx-web/src/main/java/io/vertx/ext/web/handler/impl/AuthenticationHandlerImpl.java#L96-L99
I guess we should have these “bespoken” rules in the interface javadoc too 😅
You can also add another interface to cleary mark proxy related stuff if protocol upgrade seems odd. There is no cost as the check only happens once in the lifecycle of the router, in the weight() function.
You can also add another interface to cleary mark proxy related stuff if
protocol upgradeseems odd. There is no cost as the check only happens once in the lifecycle of the router, in the weight() function.
Protocol upgrade is fine with me, the proxy can do this anyway (websocket proxy).
@pmlopes PTAL