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

Closing WebSocket throws error if code is not in range 3000 - 4999 #1203

Closed
catapop84 opened this issue May 16, 2024 · 5 comments · Fixed by #1211
Closed

Closing WebSocket throws error if code is not in range 3000 - 4999 #1203

catapop84 opened this issue May 16, 2024 · 5 comments · Fixed by #1211
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@catapop84
Copy link

In pkgs/web_socket/lib/src/utils.dart you check if the close code is within the range of 3000 - 4999

Is there a reason for this? basically closing the websocket with code 1000 ( normal closure) will throw an error

in pkgs/web_socket/lib/src/io_web_socket.dart

  @override
  Future<void> close([int? code, String? reason]) async {
  //...

    // is there a reason why only code between 3000-4999 is accepted?
    checkCloseCode(code);
    checkCloseReason(reason);

  // ...
  }
@catapop84 catapop84 added package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels May 16, 2024
@brianquinlan
Copy link
Collaborator

Allowing 1000 seems like a good idea.

brianquinlan added a commit to brianquinlan/http that referenced this issue May 23, 2024
brianquinlan added a commit that referenced this issue May 24, 2024
@catapop84
Copy link
Author

Hello @brianquinlan , thanks for reply and quick fix. However after I checked the submitted code I have to reopen the issue.
I think you misunderstood , I just give an example that code 1000 (normal close) throws error, but you should allow other codes without throwing an error.
The official documentation: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code allows any code within range 1000-4999

Hope this helps

@brianquinlan
Copy link
Collaborator

brianquinlan commented May 24, 2024

But it does not allow that for user set codes. From https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close#code :

If specified, the value of this code parameter overrides the automatic setting of the close code for the connection, and instead sets a custom code. The value must be an integer: either 1000, or else a custom code of your choosing in the range 3000-4999. If you specify a code value, you should also specify a reason value.

This behavior is standardized in the whatng Web Socket Spec

@bhumkong
Copy link

bhumkong commented May 29, 2024

Please see the docs here: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
It says 1000 - normal closure, 1001 - going away, 1002 - Protocol error, and so on.
Let's allow the whole 1000 - 4999 range please.

@bhumkong
Copy link

Or, I thought it was about server-sent codes, and we're actually talking about client-sent codes. I guess it's correct then. Sorry for bothering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants