如何访问处理程序中的主体并保持其可由vertx-http-proxy使用?

问题描述 投票:0回答:1

我正在尝试在 quarkus 中实现反向代理。 它使用 vert.x-http-proxy 并需要检查主体。 根据this vert.x-http-proxy问题我知道vert.x-http-proxy不支持使用BodyHandler,但事实上每次我在拦截器中消耗主体时,代理都会卡住或抛出已读异常。 任何帮助表示赞赏。

    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))
quarkus vert.x
1个回答
0
投票

使用拦截器找到了这个解决方案:

 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()
    }
© www.soinside.com 2019 - 2024. All rights reserved.