Giter Site home page Giter Site logo

Comments (3)

ninjken avatar ninjken commented on August 28, 2024 1

I think what the documentation says with regard to your question is

ngx.exit
syntax: ngx.exit(status)
...
When status >= 200 (i.e., ngx.HTTP_OK and above), it will interrupt the execution of the current request and return status code to Nginx.

Literally interpreted, if you call ngx.exit(401) in access phase, nothing else should happen except a 401 HTTP response. But that's not what really happens, but that only request handling phases gets interrupted, and response handling(like header filter) still works. Below is my nginx.conf snippet

location /test {
            access_by_lua_file test/access.lua;
            content_by_lua_file test/content.lua;
            header_filter_by_lua_file test/header.lua;
            log_by_lua_file test/log.lua;
}

Test it and you will see that content_by_lua_file(request handling) is not executed, but both header filter and log phases are still working!

from lua-nginx-module.

ChnMig avatar ChnMig commented on August 28, 2024

I think what the documentation says with regard to your question is

ngx.exit
syntax: ngx.exit(status)
...
When status >= 200 (i.e., ngx.HTTP_OK and above), it will interrupt the execution of the current request and return status code to Nginx.

Literally interpreted, if you call in access phase, nothing else should happen except a 401 HTTP response. But that's not what really happens, but that only request handling phases gets interrupted, and response handling(like header filter) still works. Below is my nginx.conf snippetngx.exit(401)

location /test {
            access_by_lua_file test/access.lua;
            content_by_lua_file test/content.lua;
            header_filter_by_lua_file test/header.lua;
            log_by_lua_file test/log.lua;
}

Test it and you will see that content_by_lua_file(request handling) is not executed, but both header filter and log phases are still working!

If you're right, does that mean the document is wrong? My colleague told me that the old version of lua-nginx-module would return directly, but I don't have the old binary installation package to test:)

from lua-nginx-module.

zhuizhuhaomeng avatar zhuizhuhaomeng commented on August 28, 2024

ngx.exit(>=200) will exit the current phase and enter into the reply state.
The header_filter_by and log_by_lua are stilled be called because they are after the reply state.

from lua-nginx-module.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.