Repository navigation
Conversation
|
will these changes be compatible with past versions of Kong? |
989d0a7 to
4bc3951
Compare
| local get_request | ||
| do | ||
| local ok, exdata = pcall(require, "thread.exdata") | ||
| if ok and exdata then | ||
| function get_request() | ||
| local r = exdata() | ||
| if r ~= nil then | ||
| return r | ||
| end | ||
| end | ||
|
|
||
| else | ||
| local getfenv = getfenv | ||
|
|
||
| function get_request() | ||
| return getfenv(0).__ngx_req | ||
| end | ||
| end | ||
| end | ||
|
|
There was a problem hiding this comment.
Why not just:
local get_request = require "resty.core.base".get_request
There was a problem hiding this comment.
+1, we don't need to support the 1.13.6 method anymore. 1.15.8 always comes with the get_request method.
| local get_request | ||
| do | ||
| local ok, exdata = pcall(require, "thread.exdata") | ||
| if ok and exdata then | ||
| function get_request() | ||
| local r = exdata() | ||
| if r ~= nil then | ||
| return r | ||
| end | ||
| end | ||
|
|
||
| else | ||
| local getfenv = getfenv | ||
|
|
||
| function get_request() | ||
| return getfenv(0).__ngx_req | ||
| end | ||
| end | ||
| end | ||
|
|
There was a problem hiding this comment.
+1, we don't need to support the 1.13.6 method anymore. 1.15.8 always comes with the get_request method.
|
|
||
|
|
||
| function _M.update_host_header() | ||
| if ngx.config.subsystem == "http" then |
There was a problem hiding this comment.
It's better to make this function disappear in stream module instead of a no-op to make sure the caller errors out. Basically move the if one line higher.
| }; | ||
|
|
||
|
|
||
| // private data structures from ngx_http_proxy_module |
There was a problem hiding this comment.
Not a blocker for Cisco PoC, but we should patch ngx_http_proxy_module instead of copying all the data structure from it. This could break easily with an Nginx upgrade.
| ngx_int_t | ||
| ngx_http_lua_kong_ffi_recreate_request(ngx_http_request_t *r) | ||
| { | ||
| ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "entering here"); |
| return NGX_ERROR; | ||
| } | ||
|
|
||
| cl = ngx_alloc_chain_link(r->pool); |
There was a problem hiding this comment.
Maybe we do not have to reallocate a new chain link it seems? Simply overriding the old chain link's buf pointer should be enough.
|
|
||
| *e.pos++ = ':'; *e.pos++ = ' '; | ||
|
|
||
| if (ngx_strstr(e.pos - ngx_strlen("Host: "), "Host: ") != NULL && |
There was a problem hiding this comment.
ngx_strlen("Host: ") should be changed to sizeof("Host: ") -1 to avoid runtime penalties.
Also, should we check for lowercased version as well? Maybe use ngx_strcasestrn instead.
| // run the script | ||
| while (*(uintptr_t *) e.ip) { | ||
| code = *(ngx_http_script_code_pt *) e.ip; | ||
| code((ngx_http_script_engine_t *) &e); |
There was a problem hiding this comment.
Question: do we really need this logic? If proxy_set_header Host $upstream_host; is set inside the nginx.conf, can we simply set ngx.var.upstream_host = "new.host" inside balancer phase for the script engine to take care of the rest?
If it is caused by weird caching script engine does, we can always clear the cache before running the length and content codes below. That way we can guarantee the length calculated is always the same as the string written and avoid the buffer mangling below.
|
My recommendations: Overall the change is going the right direction. However, the duplication of code from
This way we should be able to get rid of majority of the copied code inside this PR, which makes the PR much more reviewable and maintainable, but most importantly, remain safe across Nginx updates. |
4bc3951 to
23d2541
Compare
|
Superseded by openresty/lua-resty-core#302. |
No description provided.