Skip to content
Advertisement

How to get response body in Zuul post filter?

How it is possible to read a response body while using Zuul as a proxy in post filter?

I am trying to call the code like this:

JavaScript

Advertisement

Answer

I’ve managed to overcome this. The solution consists of 4 steps:

  1. Read ctx.getResponseDataStream() into a ByteArrayOutputStream
  2. Copy OutputStream to 2 InputStreams.
  3. Use one of it for your custom purposes.
  4. Use the second to reassign to context: context.setResponseBody(inputStream)
    • reading stream from point 1 would cause that the stream cannot be read again, so this way you’re passing a new fresh stream that wasn’t read yet
Advertisement