beginnerWJC commented on issue #191:
URL:
https://github.com/apache/apisix-java-plugin-runner/issues/191#issuecomment-1231059247
我还发现了个问题,我想在插件里面将返回值改成200规避这个问题,然后发现无法修改响应码
插件代码:
```
public void postFilter(PostRequest request, PostResponse response,
PluginFilterChain chain) {
logger.info("TestPostFilter插件开始执行!");
Map<String, String> headersMap = request.getUpstreamHeaders();
logger.info("上游返回的headers:{}",JSON.toJSONString(headersMap));
int statusCode = request.getUpstreamStatusCode();
logger.info("上游返回的状态码为:{}",statusCode);
if(statusCode == 204) {
logger.info("修改上游的状态码为200");
response.setStatusCode(200);
}
response.setHeader("apisix", "TestPostFilter");
chain.postFilter(request, response);
}
```
日志打印
```
2022/08/30 01:36:25 [warn] 58#58: *194 [lua] init.lua:913: 08/30
01:36:25.794 [epollEventLoopGroup-2-2] INFO
[o.a.a.p.runner.filter.TestPostFilter] -TestPostFilter插件开始执行!
, context: ngx.timer
2022/08/30 01:36:25 [warn] 58#58: *194 [lua] init.lua:913: 08/30
01:36:25.794 [epollEventLoopGroup-2-2] INFO
[o.a.a.p.runner.filter.TestPostFilter] -上游返回的headers:{"Date":"Tue, 30 Aug 2022
01:36:25 GMT"}
, context: ngx.timer
2022/08/30 01:36:25 [warn] 58#58: *194 [lua] init.lua:913: 08/30
01:36:25.795 [epollEventLoopGroup-2-2] INFO
[o.a.a.p.runner.filter.TestPostFilter] -上游返回的状态码为:204
, context: ngx.timer
2022/08/30 01:36:25 [warn] 58#58: *194 [lua] init.lua:913: 08/30
01:36:25.795 [epollEventLoopGroup-2-2] INFO
[o.a.a.p.runner.filter.TestPostFilter] -修改上游的状态码为200
, context: ngx.timer
172.17.67.1 - - [30/Aug/2022:01:36:25 +0000] 192.168.40.174:30880 "GET
/robot-monitor/v1/robotMonitor/test204 HTTP/1.1" 204 0 0.205 "-"
"PostmanRuntime/7.28.4" 192.168.2.120:8900 204 0.007
"http://192.168.40.174:30880"
```
postman:

还是204,没有改写成功
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]