Documentation: proxied request must be readable when handed over to the proxy
Hi there,
I am building a reverse proxy using vertx-http-proxy (4.5.14) - Java 17 - Linux . In some cases the origin is selected after querying a DB that has some kind of routing information using a key provided in the request.
For building the proxied request I am using
static ProxyRequest reverseProxy(HttpServerRequest proxiedRequest)
In some cases this method throws java.lang.IllegalStateException: Request has already been read at io.vertx.core.http.impl.Http2ServerRequest.checkEnded(Http2ServerRequest.java:205) ~[vertx-core-4.5.14.jar:4.5.14] at io.vertx.core.http.impl.Http2ServerRequest.pause(Http2ServerRequest.java:257) ~[vertx-core-4.5.14.jar:4.5.14] at io.vertx.httpproxy.ProxyRequest.reverseProxy(ProxyRequest.java:41) ~[vertx-http-proxy-4.5.14.jar:4.5.14] at com.chevaris.plt.proxy.router.Proxy.sendProxyRequest(Proxy.java:260) ~[classes/:?] at com.chevaris.plt.proxy.router.Proxy.lambda$13(Proxy.java:243) ~[classes/:?] at com.chevaris.plt.proxy.router.VertxBulkhead.executeFuture(VertxBulkhead.java:30) ~[classes/:?] at com.chevaris.plt.proxy.router.Proxy.lambda$11(Proxy.java:233) ~[classes/:?] at io.vertx.core.impl.future.Composition.onSuccess(Composition.java:38) ~[vertx-core-4.5.14.jar:4.5.14] at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:66) ~[vertx-core-4.5.14.jar:4.5.14] at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:259) ~[vertx-core-4.5.14.jar:4.5.14] at io.vertx.core.impl.future.Composition$1.onSuccess(Composition.java:62) ~[vertx-core-4.5.14.jar:4.5.14] at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:66) ~[vertx-core-4.5.14.jar:4.5.14] at io.vertx.core.impl.future.SucceededFuture.addListener(SucceededFuture.java:88) ~[vertx-core-4.5.14.jar:4.5.14] at io.vertx.core.impl.future.Composition.onSuccess(Composition.java:43) ~[vertx-core-4.5.14.jar:4.5.14] at io.vertx.core.impl.future.FutureBase.lambda$emitSuccess$0(FutureBase.java:60) ~[vertx-core-4.5.14.jar:4.5.14] at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173) ~[netty-common-4.1.118.Final.jar:4.1.118.Final] at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166) ~[netty-common-4.1.118.Final.jar:4.1.118.Final] at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) ~[netty-common-4.1.118.Final.jar:4.1.118.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569) ~[netty-transport-4.1.118.Final.jar:4.1.118.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:998) ~[netty-common-4.1.118.Final.jar:4.1.118.Final] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.118.Final.jar:4.1.118.Final] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.118.Final.jar:4.1.118.Final] at java.lang.Thread.run(Thread.java:840) ~[?:?]
Checking the code I have seen that ProxyRequest and ProxiedRequest relies on that fact that original HttpServerRequest to build the ProxiedRequest instance is NOT ended (that could NOT be always the case, depending on timing/business logic). The issue call be avoided creating the proxiedrequest at the beginning of the flow when the original request is NOT ended (at least should be documented if that is expected in my view), BUT I think the code should be more flexible checking if the request is ended or NOT in order to do the right thing in both cases.
Regards,
Chevaris
Thanks for your report @chevaris
Indeed, it is expected the request has not already been read. Otherwise, the proxy cannot read and forward it to the origin server.
Would you volunteer for a doc PR?
I would it.
Probably it should affect HTTP proxy docs (I guess 4.x and 5.0) and Javadoc?
I would appreciate any hint with a similar example that just changes Vertx documentation
I would it.
Great!
Probably it should affect HTTP proxy docs (I guess 4.x and 5.0) and Javadoc?
Yes, both branches and Javadoc would be best
I would appreciate any hint with a similar example that just changes Vertx documentation
The documentation is maintained as an Asciidoc file in this repo, search for the index.adoc after cloning the project. I think a CAUTION admonition would do the job.