vertx-web icon indicating copy to clipboard operation
vertx-web copied to clipboard

BodyHandler should not be added before the ProxyHandler

Open tsegismont opened this issue 1 year ago • 5 comments

See #2614

Added documentation and make ProxyHandler fail fast if the BodyHandler has been seen.

tsegismont avatar May 24 '24 15:05 tsegismont

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 avatar May 29 '24 16:05 tsegismont

@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 😅

pmlopes avatar May 30 '24 16:05 pmlopes

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.

pmlopes avatar May 30 '24 16:05 pmlopes

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.

Protocol upgrade is fine with me, the proxy can do this anyway (websocket proxy).

tsegismont avatar May 31 '24 16:05 tsegismont

@pmlopes PTAL

tsegismont avatar May 31 '24 16:05 tsegismont