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

Disconnect does not allow for 2-byte status code #14

Open
Altreus opened this issue Jul 9, 2018 · 1 comment
Open

Disconnect does not allow for 2-byte status code #14

Altreus opened this issue Jul 9, 2018 · 1 comment

Comments

@Altreus
Copy link
Contributor

Altreus commented Jul 9, 2018

I came a cropper of a bug that I debugged like this

--- a/lib/Cro/WebSocket/BodyParsers.pm6
+++ b/lib/Cro/WebSocket/BodyParsers.pm6
@@ -30,6 +30,7 @@ class Cro::WebSocket::BodyParser::JSON does Cro::BodyParser {
 
     method parse($message) {
         $message.body-blob.then: -> $blob-promise {
+            CATCH { say "Not good stuff: " ~ $blob-promise.result.gist }
             from-json $blob-promise.result.decode('utf-8')
         }
     }

The RFC says the first two bytes are an unsigned integer and the rest is whatever.

If there is a body, the first two bytes of the body MUST be a 2-byte unsigned integer (in network byte order) representing a status code with value /code/ defined in Section 7.4. Following the 2-byte integer, the body MAY contain UTF-8-encoded data with value /reason/, the interpretation of which is not defined by this specification.

A websocket I tested with sends non-JSON as reason, but it chokes on decode('utf-8') anyway.

I think close frames should be handled specially but I'm still too novice at this to risk a submission.

@Altai-man
Copy link
Member

Test related to #15
as $server.close does not cause internal $!receiver to be closed as well.

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