在undertow BUG TRACKER上反饋的一個問題:在httpHander中不能修改response Body的問題。
一種思路(比較難):
Re: [undertow-dev] get response content in HttpHandler
Bill O'Neil <[email protected]>
You need to implement org.xnio.conduits.StreamSinkConduit and add io.undertow.server.HttpServerExchange#addResponseWrapper
There is no simple in memory representation of the response, because it may be to large for the server to buffer (or more likely the server does not want to buffer it for performance reasons). Implementing this will allow you to modify the response as it is being written.
另一種思路
[undertow-dev] Steve Hu <[email protected]>提交了issuse: UNDERTOW-854
此ISSUSE內容如下:
We are trying to use RequestDumpingHandler to log all about request and response for testing and auditing purpose. However, the output doesn't include request body and response body. I think I know how to get request body by consuming the input stream and attached the parsed body to the exchange for subsequent handlers. Response body is the hard part and I found several posts mentioned that in the mailing list but the solution is hard to understand without knowing the details on how the server works. Can this be added to the handler? Thanks.
總的來說,由於性能等原因,目前要想在httpHander中修改response Body不易容。大家儘可能避開這個小坑。以後發佈的版本中,官方會提供適當的api的。