Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vnayar opened this issue Apr 20, 2023 · 1 comment
Open

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

vnayar opened this issue Apr 20, 2023 · 1 comment

Comments

@vnayar
Copy link

vnayar commented Apr 20, 2023

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.

@s-ludwig
Copy link
Member

The problem here is actually the query property itself that is not const. It used to be a normal field in the early days, but now parses the query string lazily for performance reasons and thus cannot be const. It seems like we need to change it from const(HTTPServerRequest) request() const to inout(HTTPServerRequest) request() inout and just document that the returned request may not be modified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants