zhendongcmss opened a new issue, #9585:
URL: https://github.com/apache/apisix/issues/9585
### Current Behavior
- I want close the connection on header_filter_by_lua phase, I add the code
on `apisix/plugins/response-rewrite.lua` to test it.
```
function _M.header_filter(conf, ctx)
if true then
ngx.header.connection = "close"
ngx.status = 444
ngx.exit(444)
return
end
...
```
- Test it, the connection was closed.
```
curl 127.0.0.1:9080/test/ -i
curl: (52) Empty reply from server
```
- But I got error
error.log
```
2023/06/01 09:46:47 [error] 22431#22431: *596 connect() failed (111:
Connection refused) while connecting to upstream, client: 127.0.0.1, server: _,
request: "GET /test/ HTTP/1.1", upstream: "http://127.0.0.1:8881/test/", host:
"127.0.0.1:9080"
2023/06/01 09:46:47 [error] 22431#22431: *596 attempt to set
ngx.header.HEADER after sending out response headers while sending to client,
client: 127.0.0.1, server: _, request: "GET /test/ HTTP/1.1", upstream:
"http://127.0.0.1:8881/test/", host: "127.0.0.1:9080"
2023/06/01 09:46:47 [error] 22431#22431: *596 failed to run
body_filter_by_lua*:
...ncer-upstream-groups/apisix/plugins/response-rewrite.lua:128: API disabled
in the context of body_filter_by_lua*
stack traceback:
[C]: in function 'error'
/usr/local/openresty/lualib/resty/core/exit.lua:60: in function 'exit'
...ncer-upstream-groups/apisix/plugins/response-rewrite.lua:128: in
function 'phase_func'
...working/onest-balancer-upstream-groups/apisix/plugin.lua:708: in
function 'run_plugin'
...working/onest-balancer-upstream-groups/apisix/plugin.lua:741: in
function 'run_global_rules'
...4_working/onest-balancer-upstream-groups/apisix/init.lua:342: in
function 'common_phase'
...4_working/onest-balancer-upstream-groups/apisix/init.lua:641: in
function 'http_body_filter_phase'
body_filter_by_lua:2: in main chunk while sending to client, client:
127.0.0.1, server: _, request: "GET /test/ HTTP/1.1", upstream:
"http://127.0.0.1:8881/test/", host: "127.0.0.1:9080"
```
- The lua-nginx-module say ngx.exit() can be used on header_filter_by_lua.
https://github.com/openresty/lua-nginx-module#ngxexit
syntax: ngx.exit(status)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*,
header_filter_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*,
ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*
- I try on 2.10.1 and master branch both have this issue.
### Expected Behavior
_No response_
### Error Logs
_No response_
### Steps to Reproduce
refer Current Behavior
### Environment
- APISIX version (run `apisix version`): 2.10.1 and mster branch
- Operating system (run `uname -a`): centos 7.9
- OpenResty / Nginx version (run `openresty -V` or `nginx -V`): nginx
version: openresty/1.19.3.2
- etcd version, if relevant (run `curl
http://127.0.0.1:9090/v1/server_info`):
- APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run `luarocks --version`):
--
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]