lua-resty-core icon indicating copy to clipboard operation
lua-resty-core copied to clipboard

I use recreate_request in balancer_by_lua_block phase, but it never work.

Open dearjane opened this issue 3 years ago • 1 comments

I want to change request header in balancer_by_lua_block phase, because i need to pass host header to next upstream node. I use recreate_request function to change request header information but it doesn't work.

my test example show as follow:

`upstream apisix_backend {

    server 0.0.0.1;
    balancer_by_lua_block {
        local balancer = require "ngx.balancer"
        balancer.recreate_request()
        ngx.var.domain_host="www.baidu.com"
    }

    keepalive 320;
}

`

` location / { set $upstream_host ''; proxy_set_header Host $upstream_host;

        content_by_lua_block {
               ngx.say("1");
       }

} `

dearjane avatar Sep 14 '20 07:09 dearjane

set header or var before recreate_request, like this:

    server 0.0.0.1;
    balancer_by_lua_block {
        local balancer = require "ngx.balancer"
        ngx.var.domain_host="www.baidu.com"
        ngx.req.set_header("kk", "dasda")
        balancer.recreate_request()
    }

    keepalive 320;

soulbird avatar Dec 17 '20 09:12 soulbird