apisix-java-plugin-runner icon indicating copy to clipboard operation
apisix-java-plugin-runner copied to clipboard

bug: POST request with body contain chinese characters exist encoding problem

Open lbrant opened this issue 3 years ago • 6 comments

Issue description

Environment

apisix-java-plugin-runner version:0.2.0 apsix version:2.13.1

Minimal test code / Steps to reproduce the issue

  1. Test post request contain chinese characters in OKHttp: {"source":"高德地图","content":"https://surl.amap.com/1PoSAsa1l4Ud","deviceId":"123456"}
  2. inner OKHttp,body will be translated to utf-8 format bytes: Charset charset = Util.UTF_8; byte[] bytes = content.getBytes(charset);
  3. Custom filter in apisix-java-plugin-runner, get request body: {"source":"高德地图","content":"https://surl.amap.com/1PoSAsa1l4Ud","deviceId":"123456"}

lbrant avatar Jun 27 '22 04:06 lbrant

apisix-java-plugin-runner also use UTF_8 , see: https://github.com/apache/apisix-java-plugin-runner/pull/53/files

tzssangglass avatar Jun 29 '22 04:06 tzssangglass

@tzssangglass

I mean body in request, fixed by modifing ExtraInfoResponse.getResult:

from:

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();
    }

to

public String getResult() {
        byte[] bytes = new byte[this.resp.resultLength()];
        for (int i = 0; i < this.resp.resultLength(); i++) {
            bytes[i] = (byte) this.resp.result(i);
        }
        return new String(bytes, StandardCharsets.UTF_8);
    }

lbrant avatar Jul 27 '22 09:07 lbrant

would you like to submit a PR to fix it?

tzssangglass avatar Jul 27 '22 11:07 tzssangglass

@tzssangglass

I mean body in request, fixed by modifing ExtraInfoResponse.getResult:

from:

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();
    }

to

public String getResult() {
        byte[] bytes = new byte[this.resp.resultLength()];
        for (int i = 0; i < this.resp.resultLength(); i++) {
            bytes[i] = (byte) this.resp.result(i);
        }
        return new String(bytes, StandardCharsets.UTF_8);
    }

确实有个问题

dargoner avatar Oct 08 '22 13:10 dargoner

0.4.0 Cannot be modified manually

fitz-97 avatar Dec 09 '22 07:12 fitz-97

We can make it configurable by reading configuration from the configuration file.

tzssangglass avatar Dec 12 '22 03:12 tzssangglass