Comments (10)
@rshriram I mean something like
header_filter_by_lua_block {
local my_status = ngx.ctx.my_status
if my_status and ngx.status == 500 then
ngx.status = my_status
end
}
Assuming you have set ngx.ctx.my_status
to 503 in your balancer_by_lua*
handlers.
Generated response headers (and also bodies) can be overridden in the output filters, that's what output filters are all about :)
from lua-resty-core.
@rshriram This is the behavior of the nginx upstream facility and we cannot override that in a 3rd-party module.
from lua-resty-core.
@rshriram Having said that, you can override it in header_filter_by_lua*
, BTW.
from lua-resty-core.
@agentzh Thanks for the clarification. To summarize, returning anything other than ngx.error, ngx.ok is not possible in a balancer_by_lua context (I went through the code).
the header_filter_by_lua* -- can it work in balancer_by_lua ? I thought the headers are already generated by the time the request reaches balancer by lua stage. And they can't be overridden. If this works, I would love to use it, as I need to set the host header dynamically based on the choice of upstream instance.
from lua-resty-core.
@rshriram You can always use ngx.ctx
to communicate your own data between different phase handlers anyway.
from lua-resty-core.
Would you suggest ngx.var over ngx.ctx, as I thought the latter was costlier.
from lua-resty-core.
@rshriram ngx.var
is much more expensive and much more limited than ngx.ctx
.
from lua-resty-core.
@rshriram ngx.ctx
is not that costly if you do not invoke it in a hot Lua loop (and you shouldn't do that for any real reasons). You can always measure the overhead yourself BTW. Just don't be over panic.
from lua-resty-core.
đ˛ ! I thought it was the other way around.. And ended up using ngx.var as much as possible, while avoiding ngx.ctx .. Based on this https://www.cryptobells.com/openresty-performance-ngx-ctx-vs-ngx-shared-dict/ .. and now I see your response in google groups (https://groups.google.com/forum/#!msg/openresty-en/Yjaiut8Dv0k/Gc1eZWmLEQAJ)
On Sun, May 1, 2016 at 7:12 PM, Rob Kelledy wrote:
> "The ngx.ctx lookup requires relatively expensive metamethod calls and it is
> much slower than explicitly passing per-request data along by your own
> function arguments. So do not abuse this API for saving your own function
> arguments because it usually has quite some performance impact."
>
Don't worry too much about this paragraph. I added this note just for
people who want to achieve near-C performance with their Lua code :)
Sigh!
from lua-resty-core.
@rshriram Better profile with flame graph tools before trying any optimizations. Otherwise you may very well slow things even further :)
No kidding. I've seen such things a lot in real production systems.
from lua-resty-core.
Related Issues (20)
- Error : failed to run balancer_by_lua*: /usr/local/lib/lua/resty/core/base.lua:24: ngx_http_lua_module 0.10.19 or 0.10.20 required HOT 2
- can ngx.resty.core support proxy ceritificate setting directives
- ngx.var.ssl_ciphers in ssl_certificate_by_lua HOT 1
- Failed on IBM Z/S390x HOT 1
- how to set error log level ? HOT 4
- 2022/06/14 05:43:28 [error] 159#0: *45 lua entry thread aborted: runtime error: /opt/nginx/lib/lua/resty/core/misc.lua:178: /usr/local/lib/libluajit-5.1.so.2: undefined symbol: ngx_http_lua_ffi_req_is_internal stack traceback: coroutine 0: [C]: in function '__index' /opt/nginx/lib/lua/resty/core/misc.lua:178: in function 'is_internal' /opt/nginx/scripts/manage_access_session.lua:70: in main chunk, client: 10.221.16.1 HOT 11
- no ssl session caching happen, always new session ID!
- 0.1.24 tag missing features from lua-nginx-module 0.10.22
- I want to get all the extension information of client hello, not just server name , what can I do? HOT 6
- b64.encode_base64url problem HOT 3
- undocumented that errlog.set_filter_level can not be set lower than error_log level HOT 1
- ngx.sleep() does not work in ssl_client_hello_by_lua* HOT 13
- undefined symbol: ngx_http_lua_ffi_var_get HOT 3
- ngx.balancer ĺŚä˝čŽžç˝ŽéčŻçśćç HOT 3
- why the lua version number is commented out in Makefile HOT 4
- nginx: [alert] failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from https://openresty.org/en/download.html (reason: module 'resty.core' not found: HOT 5
- ngx.shared.DICT:ttl() returns 0 for the exipred key
- Requesting information about security fixes. HOT 1
- runtime error: /usr/local/openresty/lualib/ngx/semaphore.lua:129: attempt to perform arithmetic on a nil value HOT 1
- get_client_hello_ext() | lua-resty-core/lib/ngx/ssl | Issue with custom TLS Extension Type 17516
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ď¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lua-resty-core.