lua-nginx-module icon indicating copy to clipboard operation
lua-nginx-module copied to clipboard

Lua code in header_filter phase still runs after ngx.exit(401) is executed in access phase

Open ChnMig opened this issue 1 year ago • 3 comments

I saw in the documentation that using ngx.exit(<200) would make the request return directly to the client without executing the lua code at various stages later, and my colleague told me that was correct, my colleague had previously used an older version of openrest (seems to be 1.19.X) But I tested linux version 1.21.4.3 and windows version 1.25.3.1 and found that even if I executed ngx.exit(401) during the access phase, it still triggered lua script during the header_filter phase. Why? Did I use it wrong?

my nginx config

events {
    accept_mutex   off;
    worker_connections   20480;
}
http {
	server {
        error_log logs/error.log error;
		listen 80; 
		location / {
			proxy_set_header Host $host;
			access_by_lua_file test/access.lua;
			header_filter_by_lua_file test/header.lua;
		}
	}
} 

test/access.lua

ngx.log(ngx.ERR, "access.lua")
return ngx.exit(401) 

test/header.lua

ngx.log(ngx.ERR, "header.lua")

result (logs/error.log)

2024/01/22 15:47:31 [error] 157014#0: *1 [lua] access.lua:1: access.lua, client: 172.28.64.1, server: , request: "GET / HTTP/1.1", host: "172.28.73.58:80"
2024/01/22 15:47:31 [error] 157014#0: *1 [lua] header.lua:1: header.lua, client: 172.28.64.1, server: , request: "GET / HTTP/1.1", host: "172.28.73.58:80"

ChnMig avatar Jan 22 '24 08:01 ChnMig