Closed nnzbz closed 4 months ago
Can you please add more info to help us reproduce?
A complete reproducer is even better
client request:
response:
server http config:
proxy config(forward kibana):
modify code:
So, if I understand correctly:
Correct?
Yes, that's right
I was able to reproduce.
The problem is that the Kibana response body is encoded with gzip (as indicated by the content-encoding
header).
So when you get the buffered content (with BufferingWriteStream
) you cannot transform to String
, because you're actually looking at binary content.
Instead, you must create the response like this:
Buffer content = bufferingWriteStream.content();
proxyResponse.setBody(Body.body(content));
return context.sendResponse();
If you want to inspect the string content, you can do it like this:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(content.getBytes()))) {
byte[] buffer = new byte[1024];
int len;
while ((len = gis.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
String html = baos.toString(StandardCharsets.UTF_8);
Questions
Error for modify body before gzip response,browser developer tools network show "(failed)net::ERR_CONTENT_DECODING_FAILED"
Version
4.5.8
Context
My code referenced https://vertx.io/docs/vertx-http-proxy/java/#_interception_control, but when proxy response gzip occur "ERR_CONTENT_DECODING_FAILED" error in brower.
Do you have a reproducer?
No
Steps to reproduce
No
Extra
No