通过lua-resty-http发起的请求到同一个openresty服务上 能否获取到对应的请求头部?

56 views
Skip to first unread message

3824...@qq.com

unread,
Jan 13, 2024, 11:50:43 AMJan 13
to openresty
下面是一个配置:

http {


    server {


        listen 80;


        location / {

            content_by_lua_block {

                local httpc = http.new()

                httpc:request_uri("localhost:8080/test.html", {

                            method = "GET",

                            headers = {

                                ["myheader"] = "myheadervalue",

                            }

                        }

            }

        }


    }



    server {

        listen 8080;

        location / {

            content_by_lua_block {


                local myheader = ngx.var.http_myheader    -- can't get it ..

            }

        }

    }

}


然后从curl 发起对80的请求,我发现在8080server块中获取不到从lua-resty-http客户端自定义的头部,我不知道这是合理的行为还是我的使用方式有问题。


业务场景: 从80接收到客户请求后需要进行拆解并通过cosocket发起请求到同一个openresty的不同server上完成相关任务,但是在8080上需要通过加入的头部进行业务处理。







3824...@qq.com

unread,
Jan 14, 2024, 3:05:32 AMJan 14
to openresty
sorry, i made a mistake.   the config above will work fine.   and it will generate correct header as what I expect, which will be myheadervalue in this case.
回复全部
回复作者
转发
Reply all
Reply to author
Forward
0 new messages
Search
Clear search
Close search
Google apps
Main menu