Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: ExtraInfoResponse class getResult method bug #244

Merged
merged 8 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void doPostFilter(ChannelHandlerContext ctx) {
}

private void handleExtraInfo(ChannelHandlerContext ctx, ExtraInfoResponse request) {
String result = request.getResult();
byte[] result = request.getResult();
String varsKey = queue.poll();
if (Objects.isNull(varsKey)) {
logger.error("queue is empty");
Expand All @@ -233,7 +233,7 @@ private void handleExtraInfo(ChannelHandlerContext ctx, ExtraInfoResponse reques
}
}
else {
nginxVars.put(varsKey, result);
nginxVars.put(varsKey, new String(result));
}

if (queue.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public static ExtraInfoResponse from(ByteBuffer buffer) {
return new ExtraInfoResponse(req);
}

public String getResult() {
StringBuilder builder = new StringBuilder();
public byte[] getResult() {
byte[] byteArray = new byte[this.resp.resultLength()];
for (int i = 0; i < this.resp.resultLength(); i++) {
builder.append((char) this.resp.result(i));
byteArray[i] = (byte) this.resp.result(i);
}
return builder.toString();
return byteArray;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.util.StringUtils;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand All @@ -50,7 +51,7 @@ public class HttpRequest implements A6Request {

private Map<String, String> vars;

private String body;
private byte[] body;

public HttpRequest(Req req) {
this.req = req;
Expand Down Expand Up @@ -300,10 +301,18 @@ public void setVars(Map<String, String> vars) {
}

public String getBody() {
return body;
return new String(body);
}

public String getBody(Charset charset) {
return new String(body, charset);
}

public void setBody(String body) {
this.body = body.getBytes();
}

public void setBody(byte[] body) {
this.body = body;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.util.CollectionUtils;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand All @@ -38,7 +39,7 @@ public class PostRequest implements A6Request {

private Integer status;

private String body;
private byte[] body;

private Map<String, String> vars;

Expand Down Expand Up @@ -94,11 +95,19 @@ public Integer getUpstreamStatusCode() {
}

public void setBody(String body) {
this.body = body.getBytes();
}

public void setBody(byte[] body) {
this.body = body;
}

public String getBody() {
return body;
return new String(body);
}

public String getBody(Charset charset) {
return new String(body, charset);
}

public String getVars(String key) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.apisix.plugin.runner;

import org.junit.jupiter.api.DisplayName;
Expand Down