Have a look at the code in io.undertow.server.handlers.RequestBufferingHandler
This basically fully reads the request (assuming it fits in the buffers), then uses
Connectors.ungetRequestBytes(exchange, bufferedData); to restore the data. You could do
something similar.
Stuart
----- Original Message -----
From: "Jaeckle Thomas (INST/ECS1)"
<Thomas.Jaeckle(a)bosch-si.com>
To: undertow-dev(a)lists.jboss.org
Sent: Wednesday, 20 January, 2016 8:48:49 PM
Subject: [undertow-dev] Reverse-Proxy: Consuming InputStream before delegating to proxy
target
Hi.
I have following scenario in which I currently face a problem with Undertow:
I use Undertow as a Reverse-Proxy (via SimpleProxyClientProvider).
I want to enable a Signature-based authentication where the client can sign
the HTTP request with its private key and the Reverse-Proxy (implemented
with Undertow) can check with the client’s public key if it was signed
correctly.
I do not only want to include HTTP headers (Host, Date, ..) and Method/Path,
but also the request body.
For that I need to consume the HttpServerExchange’s InputStream:
if ( isHttpMethodWithBody (method))
{
exchange.startBlocking();
final String body = new Scanner(exchange.getInputStream(), "UTF-8"
).useDelimiter( " \\A " ).next();
..
Unfortunately in this scenario, the Exchange’s “getRequestChannel()” returns
null as “another party already acquired the channel”.
I found “ Connectors. resetRequestChannel (exchange)”;
But just calling this results after the InputStream was consumed results in a
“IOException : UT001000: Connection closed”.
Is there any way to “consume” the request’s payload, but afterwards simply
forward to the proxy target?
Any help is really appreciated, Thanks!
--
Thomas Jäckle
_______________________________________________
undertow-dev mailing list
undertow-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/undertow-dev