vibe-d / vibe.d

Official vibe.d development

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Unable to call WebSocket.request._query.get() due to const

vnayar opened this issue · comments

When attaching a handler to a WebSocket like so:

  @Autowire
  URLRouter router;

  @PostConstruct
  void postConstruct() {
    logInfo("Registering RtcNotifier as HTTP GET " ~ PATH);
    router.get(PATH, handleWebSockets((WebSocket sock) => handleConnection(sock)));
  }

The handler itself is unable to access the query-string parameters using the get method.

  void handleConnection(scope WebSocket socket) {
    string peerId = socket.request()._query.get("peerId", "");

    string peerId = socket.request().query.get("peerId", "");

This code results in the error:

Error: none of the overloads of `get` are callable using a `const` object
Error: mutable method `vibe.http.server.HTTPServerRequest.query` is not callable using a `const` object

The reason for this is that the WebSocket.request() method returns a const value, which unfortunately does not work for DictionaryList.get. A const version of DictionaryList.get should be added, which is needed due to returning a const HTTPServerRequest.