[refactor/resolver] lighter kong.lua #708
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's been a while I was thinking
kong.lua
needed a refactor to be better organized. To be properly decoupled it needed a module to load the plugins for a given request, a module to be run manually at given points during a request, andkong.lua
orchestrating both.Changes:
resolver
is not plugin-like anymore.kong.core
: per-context handlers that need to be run before or after given Nginx contexts. It carries information about a request from one context to the next ones usingngx,ctx
. Timers, plugins to execute, etc...kong.core.resolver
is now ran as part of thebefore_access
handler ofkong.core
.$backend_host
and$backend_url
to$upstream_host
and$upstream_url
.ngx.ctx.upstream_url
variable to modify it.kong.core
will copy the value to$upstream_url
just before the request is proxied,ngx.ctx.stop_phases
variable.kong.lua
much lighter.ngx.status == ngx.OK
, but this was not suited for plugin which still want to be executed when previous contexts failed.Next (TODO):
dao
andconfiguration
from the globals. Instead, we want them to be allocated inkong.lua
and passed along plugins throughngx.ctx
(the job ofkong.core
).