apache / apisix-java-plugin-runner

APISIX Plugin Runner in Java
https://apisix.apache.org/
Apache License 2.0
128 stars 95 forks source link

bug:在PluginFilter类中通过requiredRespBody()方法设置为true后,在插件中调用PostRequest.getUpstreamStatusCode()方法会偶现(概率很高)获取到不正确的响应码 #235

Open beginnerWJC opened 1 year ago

beginnerWJC commented 1 year ago

Issue description

在PluginFilter类中通过requiredRespBody()方法设置为true后,在插件中调用PostRequest.getUpstreamStatusCode()方法会偶现(概率很高)获取到不正确的响应码

Environment

Minimal test code / Steps to reproduce the issue

1.通过apisix-dashboard创建路由使用ext-plugin-post-resp插件 image 2.写一个简单的java测试插件,并且设置requiredRespBody()和requiredBody()都为true image 3.查看日志发现一会是正常的406,一会是57 image

What's the actual result? (including assertion message & call stack if applicable)

What's the expected result?

beginnerWJC commented 1 year ago

这个和下面这个问题应该是一类问题 https://github.com/apache/apisix-java-plugin-runner/issues/234

frankqoqo8 commented 12 months ago

修正一下PostRequest的构造函数就行可以了: public PostRequest(Req req) { this.req = req; this.status = req.status(); headers = new HashMap<>(); for (int i = 0; i < req.headersLength(); i++) { TextEntry header = req.headers(i); headers.put(header.name(), header.value()); } }

beginnerWJC commented 11 months ago

@frankqoqo8 好的,感谢,我找时间验证一下

gaoxingliang commented 9 months ago

It worked ! a non-official workaround https://github.com/gaoxingliang/apisix-java-plugin-runner/commit/6d1ccd30ab44f6faf5825d7891433be9f97b2ee7