oatpp / oatpp-websocket

oatpp-websocket submodule.

Home Page:https://oatpp.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Q] how to handle websockets arguments / headers

madkote opened this issue · comments

commented

Please consider following use case.
Clients connects with arguments or headers to websockets

async with websockets.connect("ws://localhost:8000/ws?hello=wolrd&vendor=xyz", extra_headers=dict(foo="bar")) as ws:
    await ws.send("init")
    ...

I would expect, on server side arguments and headers could be accessible before connection is accepted. To my best understanding, that should happen at

void WSInstanceListener::onAfterCreate(const oatpp::websocket::WebSocket& socket, const std::shared_ptr<const ParameterMap>& params) {
  SOCKETS ++;
  OATPP_LOGD(TAG, "New Incoming Connection. Connection count=%d", SOCKETS.load());
  std::cout << "elements=" << params << std::endl;
  ...
  // depending on arguments and headers set various listeners to the connection
  if (elements["hello"] == "world") {
    socket.setListener(std::make_shared<WSHelloWorldListener>());
  }
  else {
    socket.setListener(std::make_shared<WSEchoListener>());
  }

Questions:

  • how to access arguments and/or headers passed in url?
  • is it possible to set different WSInstanceListener to different endpoints?
    • as I can see there is only one Listener Instance in example. But if service should support some variation on main functionality, I would like to implement it in various listeners.

Thanks!!!

commented

is it possible to set different WSInstanceListener to different endpoints? - resolved.

How to access arguments and/or headers passed in url for websocket connection?

commented

many Thanks!!! i definitely overlooked it