lipp / lua-websockets

Websockets for Lua.
http://lipp.github.com/lua-websockets/
MIT License
396 stars 113 forks source link

Request for functionality: get response with selected subprotocol #59

Closed KSDaemon closed 9 years ago

KSDaemon commented 9 years ago

Hi! Another one problem: if websocket client send multiple ws subprotocols, then server can choose one, and answer with corresponding header. On client side we should have a possibility to know that answer. Cause application logic may rely on that.

lipp commented 9 years ago

agree. we can add a second return value to connect

local ok,protocol = ws:connect('ws://foo.bar', {'proto1','proto2'})
if ok then
  print('server has chosen', protocol)
end
moteus commented 9 years ago

May be client/server also can get all headers from handshake?

lipp commented 9 years ago

ok, so you suggest:

local ok,headers = ws:connect(...)

or

local ok,protocol,headers = ws:connect(...)

i am ok with both options

moteus commented 9 years ago

I suggest ok,protocol,headers. Also may be allows client/server add some headers manually. But I do not know for what it may be needed.

lipp commented 9 years ago

ok, great.

regarding specifying header when connecting: i dont like to add functionality without somebody nedding it, though. every feature has to be tested and maintained, espacially if they are seldom or rather never used.

KSDaemon commented 9 years ago

Hi guys! I vote for local ok,protocol,headers = ws:connect(...) That would be enough.

KSDaemon commented 9 years ago

Hi, guys! On this weekend i decided to implement this feature. But i was a bit confused: in client_ev we can not simply return headers, 'cause things are async. So i extended response form on_open function — now it returns websocket object, server selected protocol and all response headers. For sync client — all return points in connect function are extended appropriately.

lipp commented 9 years ago

there is a new PR #73