This changed in Kong 0.10 with the introduction of the load balancer. Setting ngx.var.upstream_host in the access phase of a plugin should work, since it is considered right before the load balancing phase, see:
If this does not work for you, could you be more specific, and give us:
The version of Kong on which you are seeing this behaviour
A more detailed description of what your plugin does, and where (or ideally, if you can, the relevant snippet of code)
An example request, along with the Service/Route configuration - this would help us understanding any other issue that may occur, such as your plugin not executing for example…
BTW, in Kong 0.14.0 (of which we just released the first RC), we introduced a Plugin Development Kit, which offers formalized, documented, and forward-compatible Lua functions to do this kind of things (setting/retrieving headers, etc…). You can read more about it in the 0.14.0 Changelog, and expect detailed documentation very soon.
Plugin will read request boy POST-ed to that API, and if the condition meet it will change upstream to https://internal-host-b:8080. What it does basically (on access block)
ngx.req.read_body()
if cond(ngx.req.get_body_data()) then
ngx.log(ngx.INFO, "true")
ngx.var.upstream_host = "internal-host-b:8080"
end
On test it always goes to internal-host-a. no problem in the cond() since the log prints.