There is a bug in the getResult method of the ExtraInfoResponse class.
If the encoding of the upstream response is not UTF-8, The result string is broken.
In my opinion, instead of casting to char, casting to byte is the correct way.
Original Code:
public String getResult() {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < this.resp.resultLength(); i++) {
builder.append((char) this.resp.result(i));
}
return builder.toString();
}
Suggestion:
public byte[] getResult() {
byte[] byteArray = new byte[this.resp.resultLength()];
for (int i = 0; i < this.resp.resultLength(); i++) {
byteArray[i] = (byte) this.resp.result(i);
}
return byteArray;
}
Environment
your apisix-java-plugin-runner version
0.4.0
Minimal test code / Steps to reproduce the issue
set Upstream which produces response other than UTF-8 encoding
set ext-plugin-post-resp plugin setting in ApisixRoute
log the result of PostRequest getBody() in postFilter method
What's the actual result? (including assertion message & call stack if applicable)
Issue description
There is a bug in the
getResult
method of theExtraInfoResponse
class. If the encoding of the upstream response is notUTF-8
, The result string is broken. In my opinion, instead of casting tochar
, casting tobyte
is the correct way.Original Code:
Suggestion:
Environment
Minimal test code / Steps to reproduce the issue
UTF-8
encodingext-plugin-post-resp
plugin setting in ApisixRoutepostFilter
methodWhat's the actual result? (including assertion message & call stack if applicable)
broken string
What's the expected result?
normal string