Skip to content

Commit

Permalink
keep-alive by default, unless it is an Upgrade request
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Nov 18, 2016
1 parent b468e59 commit eab1ffb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 4 additions & 0 deletions kong/core/handler.lua
Expand Up @@ -60,6 +60,10 @@ return {
ngx.log(ngx.ERR, "failed the initial dns/balancer resolve: ", err)
return responses.send_HTTP_INTERNAL_SERVER_ERROR()
end

-- Websocket
local is_upgrade = ngx.var.http_connection and ngx.var.http_connection:lower() == "upgrade"
ngx.var.upstream_connection = is_upgrade and "upgrade" or "keep-alive"
end,
-- Only executed if the `resolver` module found an API and allows nginx to proxy it.
after = function()
Expand Down
8 changes: 2 additions & 6 deletions kong/templates/nginx_kong.lua
Expand Up @@ -63,11 +63,6 @@ upstream kong_upstream {
keepalive ${{UPSTREAM_KEEPALIVE}};
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
server_name kong;
listen ${{PROXY_LISTEN}};
Expand All @@ -89,6 +84,7 @@ server {
location / {
set $upstream_host nil;
set $upstream_url nil;
set $upstream_connection nil;
access_by_lua_block {
kong.access()
Expand All @@ -100,7 +96,7 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $upstream_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Connection $upstream_connection;
proxy_pass_header Server;
proxy_pass $upstream_url;
Expand Down

0 comments on commit eab1ffb

Please sign in to comment.