gaoxingliang opened a new issue, #12205:
URL: https://github.com/apache/apisix/issues/12205
### Current Behavior
I have a post response plugin and find when the upstream return a non-200
code, the apisix fail to respond.
I did following investigations:
**(1) in my plugin code looks like:**
```
@Component
public class EncryptResponseFilter implements PluginFilter {
private final Logger logger =
LoggerFactory.getLogger(EncryptResponseFilter.class);
@Override
public String name() {
return "EncryptResponseFilter";
}
@Override
public void postFilter(PostRequest request, PostResponse response,
PluginFilterChain chain) {
logger.warn("EncryptResponseFilter return non 200 code:{},
headers:{}", request.getUpstreamStatusCode(), headers);
response.setStatusCode(Optional.ofNullable(request.getUpstreamStatusCode()).orElse(500));
try {
// if code is not 200, just return the raw response
String rawResponseBody =
request.getBody(Charset.forName("UTF-8"));
logger.warn("EncryptResponseFilter return non 200 code:{},
headers:{}, raw response body:{}", request.getUpstreamStatusCode(), headers,
rawResponseBody);
response.setBody(rawResponseBody);
response.setHeader("Content-Length", null);
} catch (Exception e){
logger.warn("EncryptResponseFilter return non 200 code fail
to set response body", e);
}
}
chain.postFilter(request, response);
}
@Override
public Boolean requiredRespBody() {
return true;
}
@Override
public Boolean requiredBody() {
return true;
}
}
```
and my plugin logged the upstream code and response:
```
[]05-13 02:37:37.950.+0000[] [WARN
][epollEventLoopGroup-2-5][o.a.a.p.r.f.EncryptResponseFilter.postFilter:73]EncryptResponseFilter
return non 200 code?400, headers:{date=[Tue, 13 May 2025 02:37:37 GMT],
internal-userid=[6], transfer-encoding=[chunked], connection=[close],
content-type=[application/json], internal-nickname=xxx,
internal-username=[xxx]}, raw response body:{"message":"xxx productId"}
```
(2) in the apisix log: (the log flushes too much. the time is different
while the content and format is same.)
```
2025/05/13 02:25:05 [warn] 60#60: *14279300 a client request body is
buffered to a temporary file /usr/local/apisix/client_body_temp/0000042246,
client: 117.172.., server: _, request: "POST
/v1/enterprises/customized/modules/whites HTTP/1.0", host: "yyyy.cn:8888"
2025/05/13 02:25:05 [warn] 60#60: *14279300 [lua] plugin.lua:1107:
common_phase(): ext-plugin-post-resp exits with http status code 400, client:
117.172.., server: _, request: "POST /v1/enterprises/customized/modules/whites
HTTP/1.0", host: "yyyy.cn:8888"
```
**(3) in the wireshark capture, I found a tls v1.2 alert close notify. no
response set in the plugin received.** I have a same env in development (APISIX
version 3.6.0), the plugin is same, the error body is received. the difference
is :**the develop env is HTTP while prod is HTTPS**
(4) route conf
for develop env:
```
{
"uri": "/v1/enterprises/customized/modules/whites",
"name": "API-白名单查询",
"methods": [
"POST"
],
"host": "xxxx.cn",
"plugins": {
"ext-plugin-post-req": {
"_meta": {
"disable": false
},
"conf": [
{
"name": "DecryptRequestFilter",
"value": "{}"
}
]
},
"ext-plugin-post-resp": {
"_meta": {
"disable": false
},
"conf": [
{
"name": "EncryptResponseFilter",
"value": "{}"
}
]
},
"wolf-rbac": {
"_meta": {
"disable": false
}
}
},
"upstream": {
"nodes": [
{
"host": "xxx.test",
"port": 7083,
"weight": 1
}
],
"timeout": {
"connect": 6,
"send": 6,
"read": 45
},
"type": "roundrobin",
"scheme": "http",
"pass_host": "pass",
"keepalive_pool": {
"idle_timeout": 60,
"requests": 1000,
"size": 320
}
},
"status": 1
}
```
for prod env:
```
{
"uri": "/v1/enterprises/customized/modules/whites",
"name": "API-白名单查询",
"methods": [
"POST"
],
"host": "yyyyy.cn",
"plugins": {
"ext-plugin-post-req": {
"_meta": {
"disable": false
},
"conf": [
{
"name": "DecryptRequestFilter",
"value": "{}"
}
]
},
"ext-plugin-post-resp": {
"_meta": {
"disable": false
},
"conf": [
{
"name": "EncryptResponseFilter",
"value": "{}"
}
]
},
"wolf-rbac": {
"_meta": {
"disable": false
}
}
},
"upstream": {
"nodes": [
{
"host": "yyyy.prod",
"port": 7083,
"weight": 1
}
],
"timeout": {
"connect": 6,
"send": 6,
"read": 45
},
"type": "roundrobin",
"scheme": "http",
"pass_host": "pass",
"keepalive_pool": {
"idle_timeout": 60,
"requests": 1000,
"size": 320
}
},
"status": 1
}
```
### Expected Behavior
1, the error content body should be received.
### Error Logs
_No response_
### Steps to Reproduce
I'm not sure this can be reproduced or not.
### Environment
- APISIX version (run `apisix version`): 3.6.0
- Operating system (run `uname -a`): official docker images
--
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]