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

Make websocket close include the status code #854

Merged
merged 4 commits into from
Jul 29, 2024

Conversation

davidot
Copy link
Contributor

@davidot davidot commented Jul 22, 2024

In the websocket protocol the first two bytes of the payload in a close packet indicate the status code.

⚠️ This code is not backwards compatible, as I could not find how that is handled in this project. In the most extreme case we can use a std::enable_if on the onclose handler which then puts the status code in front of the message again to ensure any user code behaves the exact same.

Fixes: #545
And also the third commit fixes #549 (at the very least the simple case)

@gittiver
Copy link
Member

HI davidot, could you update to the newest main branch? It's just for macOS build, which does not work anymore on macos11?

include/crow/websocket.h Outdated Show resolved Hide resolved
include/crow/websocket.h Outdated Show resolved Hide resolved
include/crow/websocket.h Show resolved Hide resolved
tests/unittest.cpp Outdated Show resolved Hide resolved
davidot added 3 commits July 28, 2024 20:04
The first two bytes of a WS close packet (opcode 0x8) represent
the status code, where 1000 is normal clean exit.
Otherwise this would invalidate connection leading to e.g. get_remote_ip
to already being cleaned before the onclose handler was called.
@davidot davidot force-pushed the add-ws-exit-status branch from f8456e8 to 9f484b9 Compare July 28, 2024 19:49
@davidot
Copy link
Contributor Author

davidot commented Jul 28, 2024

Rebased on master, added enum (non-class one, can change that) and fixed 0 codes.

CI failure is a already present unit test, although it is not failing on master? It is passing for me locally

@gittiver
Copy link
Member

Restarted the ci jobs, seems GitHub had an hiccup, all run successful (except windows which takes longer....)

Copy link
Member

@gittiver gittiver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just notized that documentation needs to be adapted.
Just changed it already.

@gittiver gittiver merged commit 31ca145 into CrowCpp:master Jul 29, 2024
11 checks passed
@davidot davidot deleted the add-ws-exit-status branch July 29, 2024 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants