Kong: [request] Websocket support

Created on 10 May 2015  Â·  31Comments  Â·  Source: Kong/kong

Understanding the feasibility of Websocket support into Kong and the details for an implementation, with documented limitations and use-cases.

tasfeature

Most helpful comment

Can you stop writing +1 so we don't get useless notifications all the time and can focus more on valuable content like how we can go by solving this instead.

Github have introduced reactions, use that instead.
skarmavbild 2016-06-06 kl 23 19 25

If you are doing it only cuz you want to get notified when someone writes something then use the subscribe button!
skarmavbild 2016-06-06 kl 23 24 51

It will be more of a pain to summarize the issue when it gets long and 95% of the content is +1 and only 5% is useful information

PS: If you didn't notice it's possible to sort on reaction in the search
is:issue is:open sort:reactions-+1-desc
so doing reaction instead of +1's may well be a better way to signal that it's a highly requested feature

All 31 comments

@rosskukulinski requested this on twitter last week too so +1 from me

+1

+1 here

Ditto!

+1 for Real-time App Support.

+1

+1

+1

+1

+1

+1

+1

+1

+1

Can you stop writing +1 so we don't get useless notifications all the time and can focus more on valuable content like how we can go by solving this instead.

Github have introduced reactions, use that instead.
skarmavbild 2016-06-06 kl 23 19 25

If you are doing it only cuz you want to get notified when someone writes something then use the subscribe button!
skarmavbild 2016-06-06 kl 23 24 51

It will be more of a pain to summarize the issue when it gets long and 95% of the content is +1 and only 5% is useful information

PS: If you didn't notice it's possible to sort on reaction in the search
is:issue is:open sort:reactions-+1-desc
so doing reaction instead of +1's may well be a better way to signal that it's a highly requested feature

I would prefer everyone involved get a "+1" notification every month as a reminder that a heavily requested enhancement has not had any discussion in over a year.

In the meantime, this seems like a good idea: https://github.com/isaacs/github/issues/640

+1

Wondering the status of this, and if any ETA is available.

Looking for Rate Limiting the websocket messages - hope some info / docs are available on it.

Just trying to focus my scope for this feature, what I need is websocket proxy, as http://nginx.org/en/docs/http/websocket.html and not a websocket server as in https://github.com/openresty/lua-resty-websocket - For the former, I guess it would be as easy as passing is_websocket=true, with default value being false, and everything still works as it is, but if anyone wants to enable websocket headers, just flag it and that particular location would be a websocket proxy, either by proxying those requests to rabbitmq stomper module or node.js' ws, or any pub/sub websocket enabled server.

If I wanted to just enable passthrough of websockets to the upstream server, where would I go about making that change in Kong's sourcecode? As an MVP I'm not bothered about rate limiting websocket messages etc

@danjenkins I was able to get this working globally by adding the following to my kong.yml:

in the http directive:

# Websocket
map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
}

in the server directive:

proxy_http_version 1.1;

# Proxy Websocket Upgrade request
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;

Thats Exactly what I was looking for @pklingem ! Thanks so much; I'll go test this out

@danjenkins did you manage to try the websockets with kong ?

@sallespro yes, with the above config from @pklingem it all worked great

@pklingem, @sallespro I'm using version Kong 0.9, I've edited the nginx-kong.conf Added the http

since the nginx.conf uses http { import "kong-nginx.conf" } thought this would work however I keep getting 400 bad request When trying to connect to rabbit-mq stomp via websockets.. However long-polling does work.

map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }

server { 
     ...
    location / {
        ...
        proxy_pass $upstream_url;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
      }
}

Edit

  • tyk.io websockets enabled works fine, connecting rabbit-mq
  • direct connection to rabbit-mq works also

I believe it's my configuration in kong. Not the method of connection. I keep seeing kong.yml 0.9 uses kong.conf, that in turn points to the nginx-kong.conf.. possibility I placed the info in the wrong places?

hi Derek, double check Rabbit.
I have been able to make socket connections work fine with websockets, primus lib, and other socket dependent apps with this config.

Em 18/10/2016, à(s) 14:30, Derek Smith [email protected] escreveu:

@pklingem, @sallespro I'm using version Kong 0.9, I've edited the nginx-kong.conf Added the http

since the nginx.config uses http { import "kong-nginx.cong" } thought this would work however I keep getting 400 bad request When trying to connect to rabbit-mq stomp

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

server {
...
location / {
...
proxy_pass $upstream_url;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

Got it working... No Kong.conf changes needed..

Using kong start --nginx-conf=/path/to/custom-nginx.template
Full Nginx-Template

just for reference a link to similar items on Gitter; https://gitter.im/Mashape/kong?at=581a7e44e097df7575627a89

I just tried custom-nginx way, and failed.

Kong 0.9.5, installed using Docker.

Success in direct connection, and server side get the request like this(use tcpdump and wireshark):

GET / HTTP/1.1
Host: 192.168.255.129:61337
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: http://192.168.255.128
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36
DNT: 1
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,ja;q=0.6,en;q=0.4
Cookie: __cfduid=d5f8e57ac0ab5d6ae5bfb95c2d4309bd11469499311
Sec-WebSocket-Key: Dp9bf139sqaZDDd3LNalKw==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: CmigKkxi8+GafPZe4FAjID2KMf4=
Origin: http://192.168.255.128

......./....S.R...2H..A,...{"type":"color","data":"blue"}

Failed in using kong connection:

GET / HTTP/1.0
X-Real-IP: 192.168.255.100
X-Forwarded-For: 192.168.255.100
X-Forwarded-Proto: http
Host: 192.168.255.103
Connection: close
Pragma: no-cache
Cache-Control: no-cache
Origin: http://192.168.255.128
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36
DNT: 1
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,ja;q=0.6,en;q=0.4
Sec-WebSocket-Key: P3YIzgiwlUjPUCuiyGr2bA==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
X-Forwarded-Host: 192.168.255.103

HTTP turned to be 1.0? The Connection: Upgrade and Upgrade: websocket are missing.

OK, I think it maybe my fault. Missing Connection: Upgrade and Upgrade: websocket may relate to my conf.
I run the docker by CMD ["kong", "start", "--nginx-conf=/usr/local/kong/custom-nginx.conf"] and in container I get it like this:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      2154  0.0  0.0  13372  2064 ?        S    09:12   0:00 -bash
root      2168  0.0  0.0   5884   660 ?        S+   09:12   0:00  \_ tailf error.log
root      1340  0.0  0.0  13376  2080 ?        S    08:41   0:00 -bash
root      2421  0.0  0.0  49020  1800 ?        R+   09:19   0:00  \_ ps auxf
root         1  0.0  0.0    192     4 ?        Ss   07:57   0:00 /usr/local/bin/dumb-init /bin/bash /docker-entrypoint.sh kong start --nginx-conf=/usr/local/kong/custom-nginx.conf
root         6  0.0  0.1  40972  7064 ?        Ss   07:57   0:00 perl /usr/local/openresty/bin/resty /usr/local/bin/kong start --nginx-conf=/usr/local/kong/custom-nginx.conf
root         7  0.0  0.1  50520  6168 ?        S    07:57   0:00  \_ /usr/local/openresty/bin/../nginx/sbin/nginx -p /tmp/x6lQQya4nl/ -c conf/nginx.conf
root        62  0.0  0.0  11636  1364 ?        S    07:57   0:00      \_ sh -c /usr/local/openresty/nginx/sbin/nginx -p /usr/local/kong -c nginx.conf >"/tmp/lua_cCXswe" 2>"/tmp/lua_bZzMY2"
root        63  0.0  0.2 198504  8148 ?        S    07:57   0:00          \_ nginx: master process /usr/local/openresty/nginx/sbin/nginx -p /usr/local/kong -c nginx.conf
nobody    2325  0.0  0.3 208480 13784 ?        S    09:16   0:00              \_ nginx: worker process
nobody    2326  0.0  0.3 205556 12428 ?        S    09:16   0:00              \_ nginx: worker process
root        28  0.0  0.0  15552   848 ?        S    07:57   0:00 /usr/sbin/dnsmasq -p 8053 --pid-file=/usr/local/kong/pids/dnsmasq.pid -N -o --listen-address=127.0.0.1
root        36  0.1  0.2  18156  7420 ?        Sl   07:57   0:04 serf agent -profile wan -rpc-addr 127.0.0.1:7373 -event-handler member-join,member-leave,member-failed,member-update,member-reap,user:kong=/usr/local/kong/serf/serf_event.sh -bind 0.0.0.0:7946 -node 2c4a629037e8_0.0.0.0:7946_6184d5766bbe425c93c2c75c7f777117 -log-level err

There IS a start --nginx-conf but it doesn't work, or it IS working but something is wrong.

https://github.com/Mashape/kong/pull/1827 has been merged, this can be closed.

Was this page helpful?
0 / 5 - 0 ratings