How to set connection header close when call upstream url

when call upstream url ,I wanta set header to close,
use request-transformer plugin to add connection:close,
I tcpdump the package found the connection is always keep-alive,
I read the source and found the follow source(kong\nginx-kong.conf,kong\templates\nginx_kong.lua)
proxy_set_header Host $upstream_host;
proxy_set_header Upgrade $upstream_upgrade;
proxy_set_header Connection $upstream_connection;
could I set connection header to close when call upstream url or how to do
thanks

@jian Good point. As of today, you’d need a (tiny) custom plugin doing the following:

-- handler.lua
function CustomPlugin:access()
    ngx.var.upstream_connection = "close"
end

Such a plugin could be applied on a Service or globally, and set the upstream Connection: close header when enabled.

I encourage you to browse the Plugin Development Guide for more info on custom plugin (e.g. how to write the handler.lua file and how to install it).

Another improvement would be to make this configurable on a per Service or per Upstream basis, right into the core. We will keep this in mind or welcome any pull request for it.

Hope that helps,

thank you
BTW is there any other way to set it,eg ,ENV var,config file etc.

If you want to set it globally you might be able to set it in nginx_kong.conf. I’ve never tried this so I’m not sure if it will have unintended side effects.

As @peter-evans suggested, by creating your own Nginx configuration template which hard-codes the upstream Connection header (although I do not recommend you do this for maintainability reasons).

Otherwise, no (or else I would have talked about it, wouldn’t I :slightly_smiling_face:) hence why I said:

Another improvement would be to make this configurable on a per Service or per Upstream basis, right into the core. We will keep this in mind or welcome any pull request for it.