-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feature: add precontent_by_lua directives #2472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add precontent_by_lua directives #2472
Conversation
53814d4 to
b43f761
Compare
|
Just tried and works perfectly. really helpful, thanks bro |
src/ngx_http_lua_common.h
Outdated
| #define NGX_HTTP_LUA_CONTEXT_EXIT_WORKER 0x00002000 | ||
| #define NGX_HTTP_LUA_CONTEXT_SSL_CLIENT_HELLO 0x00004000 | ||
| #define NGX_HTTP_LUA_CONTEXT_SERVER_REWRITE 0x00008000 | ||
| #define NGX_HTTP_LUA_CONTEXT_PRECONTENT 0x00020000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move the code after NGX_HTTP_LUA_CONTEXT_PROXY_SSL_VERIFY
|
|
||
| /* | ||
| * Copyright (C) Xiaozhe Wang (chaoslawful) | ||
| * Copyright (C) Yichun Zhang (agentzh) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to your email
src/ngx_http_lua_precontentby.c
Outdated
| #if 0 | ||
| if (cur_ph == last_ph) { | ||
| dd("XXX our handler is already the last precontent phase handler"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't keep the dead code copy from other file
b43f761 to
b2faf26
Compare
I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.
Since balancer_by_lua_block does not support consocket, getting upstream peers from the outside is usually performed in the access_by_lua_*. (refer to https://github.com/openresty/lua-nginx-module?tab=readme-ov-file#balancer_by_lua_block)
However, since the access phase is mainly responsible for access control, many subrequests usually skip the access phase, resulting in subrequests being unable to get upstream peers in the access phase. The current solution is to identify sub-requests and then move the relevant processing logic forward to rewrite_by_lua_*. But it is ultimately an unreasonable solution, as it inappropriately utilizes the rewrite or access phase to provide functionality that does not belong to them.
In nginx, there is actually a precontent phase after the post_access phase. Initially, nginx named this phase
NGX_HTTP_TRY_FILES_PHASE, and it was a dedicated phase for the try_files module (other module handlers could not be registered). As nginx's functionality expanded, it was renamedNGX_HTTP_PRECONTENT_PHASE, which also allowed the registration of new module handlers.By injecting Lua code into the precontent phase, we can implement proxy/upstream-related preparation functions, including upstream header rewriting, proxy authentication, proxy URI rewriting, and upstream information retrieval (such as obtaining the upstream peer list via DNS). Furthermore, the precontent phase will not be bypassed in sub-requests (one of the biggest problems with registering non-access control related functions in the access phase).
This PR added 3 directives:
The PR for lua-resty-core: openresty/lua-resty-core#519
close #2253