I'm trying to implement a reverse proxy in quarkus. It uses vert.x-http-proxy and needs to examine the body. According to this vert.x-http-proxy issue I know that vert.x-http-proxy does not support using BodyHandler but in fact every time I consume the body in my Interceptor, the proxy stuck or throw an already read exception. Any help appreciated.
fun onStart(@Observes router: Router, vertx: Vertx) {
val proxyClient: HttpClient = vertx.createHttpClient(HttpClientOptions().setTrustAll(false))
val proxy: HttpProxy = HttpProxy.reverseProxy(proxyClient)
proxy.origin(8888, "localhost").addInterceptor(myInterceptor)
router
.route()
.path("/authorized/*")
.handler(ProxyHandler.create(proxy))
Found this solution using Interceptor:
override fun handleProxyRequest(context: ProxyContext): Future<ProxyResponse> {
// Rewrite uri to remove useless part
context.request().uri = context.request().uri.substringAfter("/authorize")
val originalRequest = context.request().proxiedRequest()
originalRequest.bodyHandler { requestBody ->
//Do something with the body
...
}
// Continue the interception chain
return context.sendRequest()
}